> This page is for version Nightly.
> For other versions, use one of these documentation indexes:
> - 0.1.0 (default): https://docs.nvidia.com/nemo/lens/0.1.0/llms.txt
> - Nightly: https://docs.nvidia.com/nemo/lens/nightly/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/lens/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/lens/_mcp/server.

# lens.contrib.nccl

NCCL context propagation helpers.

Provides utilities for serializing/deserializing OTel trace context
alongside activation tensor transfers in pipeline parallel training.

## Module Contents

### Functions

| Name                                                              | Description                                                               |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------- |
| [`deserialize_context`](#lens-contrib-nccl-deserialize_context)   | Deserialize trace context from bytes received via NCCL.                   |
| [`extract_nccl_context`](#lens-contrib-nccl-extract_nccl_context) | Extract OTel context from NCCL-received bytes.                            |
| [`serialize_context`](#lens-contrib-nccl-serialize_context)       | Serialize current trace context to bytes for piggy-backing on NCCL sends. |

### API

```python
lens.contrib.nccl.deserialize_context(
    data: bytes
) -> dict | None
```

Deserialize trace context from bytes received via NCCL.

**Parameters:**

**`data`**

JSON-encoded W3C trace context bytes.

---

**Returns:** `dict | None`

A carrier dict, or None if deserialization fails.

```python
lens.contrib.nccl.extract_nccl_context(
    data: bytes
)
```

Extract OTel context from NCCL-received bytes.

Convenience function combining deserialize + extract.

**Parameters:**

**`data`**

JSON-encoded W3C trace context bytes.

---

**Returns:**

An OTel Context (empty if deserialization fails).

```python
lens.contrib.nccl.serialize_context() -> bytes
```

Serialize current trace context to bytes for piggy-backing on NCCL sends.

**Returns:** `bytes`

JSON-encoded W3C trace context as bytes.