> This page is for version 0.7.0 · 26.10.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/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/automodel/llms.txt.

# nemo_automodel.components.models.common.sinkhorn

Sinkhorn normalization of hyper-connection (mHC) mixing logits.

The torch implementation is the numerical reference. The optional CUDA path
uses DeepSeek TileKernels `tile_kernels.modeling.mhc.ops.sinkhorn_normalize`
and its low-level kernels; no TileKernels source is vendored. Upstream source:
[https://github.com/deepseek-ai/TileKernels/blob/36d9e45d38e204ebb87e6f6e833821eee0482fe5/tile_kernels/modeling/mhc/ops/sinkhorn.py](https://github.com/deepseek-ai/TileKernels/blob/36d9e45d38e204ebb87e6f6e833821eee0482fe5/tile_kernels/modeling/mhc/ops/sinkhorn.py)
Upstream license: MIT, copyright 2026 DeepSeek.

## Module Contents

### Classes

| Name                                                                                             | Description                                                                  |
| ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- |
| [`_TileKernelsSinkhorn`](#nemo_automodel-components-models-common-sinkhorn-_TileKernelsSinkhorn) | TileKernels Sinkhorn wrapper that accepts non-contiguous backward gradients. |

### Functions

| Name                                                                                                                         | Description                                                                                      |
| ---------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [`is_tile_kernels_sinkhorn_available`](#nemo_automodel-components-models-common-sinkhorn-is_tile_kernels_sinkhorn_available) | Return whether the TileKernels Sinkhorn wrapper and its forward/backward kernels are importable. |
| [`sinkhorn_normalize_tile_kernels`](#nemo_automodel-components-models-common-sinkhorn-sinkhorn_normalize_tile_kernels)       | Run the TileKernels Sinkhorn; never falls back to the torch path.                                |
| [`sinkhorn_normalize_torch`](#nemo_automodel-components-models-common-sinkhorn-sinkhorn_normalize_torch)                     | Normalize mixing logits into an approximately doubly stochastic matrix.                          |

### API

```python
class nemo_automodel.components.models.common.sinkhorn._TileKernelsSinkhorn()
```

**Bases:** `Function`

TileKernels Sinkhorn wrapper that accepts non-contiguous backward gradients.

The upstream high-level wrapper launches the backward kernel with
`grad_output` as-is. Hyper-connection combinations are consumed through
transposed matmul sites, so autograd can provide a transposed gradient
layout. The low-level TileKernels backward kernel requires contiguous
row-major inputs.

```python
nemo_automodel.components.models.common.sinkhorn._TileKernelsSinkhorn.backward(
    ctx: torch.autograd.function.FunctionCtx,
    grad_output: torch.Tensor
) -> tuple[torch.Tensor, None, None]
```

staticmethod

Run the TileKernels backward kernel on a contiguous copy of the gradient.

**Parameters:**

**`ctx`** `torch.autograd.function.FunctionCtx`

Autograd context.

---

**`grad_output`** `torch.Tensor`

Gradient of shape \[..., streams, streams], any strides.

---

**Returns:** `tuple[torch.Tensor, None, None]`

Input gradient with the forward input's shape, then `None` for `repeat` and `eps`.

```python
nemo_automodel.components.models.common.sinkhorn._TileKernelsSinkhorn.forward(
    ctx: torch.autograd.function.FunctionCtx,
    x: torch.Tensor,
    repeat: int,
    eps: float
) -> torch.Tensor
```

staticmethod

Run the TileKernels forward kernel.

**Parameters:**

**`ctx`** `torch.autograd.function.FunctionCtx`

Autograd context.

---

**`x`** `torch.Tensor`

CUDA logits of shape \[..., streams, streams], with arbitrary leading dimensions.

---

**`repeat`** `int`

Number of normalization rounds.

---

**`eps`** `float`

Additive stabilizer.

---

**Returns:** `torch.Tensor`

Tensor with the shape of `x`, independent of its storage.

```python
nemo_automodel.components.models.common.sinkhorn.is_tile_kernels_sinkhorn_available() -> bool
```

Return whether the TileKernels Sinkhorn wrapper and its forward/backward kernels are importable.

```python
nemo_automodel.components.models.common.sinkhorn.sinkhorn_normalize_tile_kernels(
    x: torch.Tensor,
    repeat: int,
    eps: float
) -> torch.Tensor
```

Run the TileKernels Sinkhorn; never falls back to the torch path.

**Parameters:**

**`x`** `torch.Tensor`

CUDA logits of shape \[..., streams, streams], with arbitrary leading dimensions.

---

**`repeat`** `int`

Number of normalization rounds.

---

**`eps`** `float`

Additive stabilizer.

---

**Returns:** `torch.Tensor`

Tensor with the shape of `x`.

**Raises:**

* `RuntimeError`: If TileKernels is not importable or `x` is not a CUDA tensor.

```python
nemo_automodel.components.models.common.sinkhorn.sinkhorn_normalize_torch(
    x: torch.Tensor,
    repeat: int,
    eps: float
) -> torch.Tensor
```

Normalize mixing logits into an approximately doubly stochastic matrix.

**Parameters:**

**`x`** `torch.Tensor`

Logits of shape \[..., streams, streams], with arbitrary leading dimensions.

---

**`repeat`** `int`

Number of row/column normalization rounds; the first round starts from a softmax.

---

**`eps`** `float`

Additive stabilizer applied to every normalization denominator.

---

**Returns:** `torch.Tensor`

Tensor with the shape and dtype of `x`.