> 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.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.moe.megatron.fused_indices_converter

## Module Contents

### Classes

| Name                                                                                                     | Description                                          |
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [`IndicesToMultihot`](#nemo_automodel-components-moe-megatron-fused_indices_converter-IndicesToMultihot) | Convert moe topk indices to multihot representation. |

### Functions

| Name                                                                                                                         | Description                                                      |
| ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [`_indices_to_multihot_kernel`](#nemo_automodel-components-moe-megatron-fused_indices_converter-_indices_to_multihot_kernel) | Triton kernel for converting indices to multihot representation. |
| [`_multihot_to_indices_kernel`](#nemo_automodel-components-moe-megatron-fused_indices_converter-_multihot_to_indices_kernel) | Triton kernel for converting multihot representation to indices. |
| [`fused_indices_to_multihot`](#nemo_automodel-components-moe-megatron-fused_indices_converter-fused_indices_to_multihot)     | Convert moe topk indices to multihot representation.             |

### Data

[`HAVE_TRITON`](#nemo_automodel-components-moe-megatron-fused_indices_converter-HAVE_TRITON)

[`null_decorator`](#nemo_automodel-components-moe-megatron-fused_indices_converter-null_decorator)

### API

```python
class nemo_automodel.components.moe.megatron.fused_indices_converter.IndicesToMultihot()
```

**Bases:** `Function`

Convert moe topk indices to multihot representation.

This class implements a custom forward and backward propagation
operation for efficiently converting indices to multihot
representation.
It is an experimental feature and may change in future versions.

```python
nemo_automodel.components.moe.megatron.fused_indices_converter.IndicesToMultihot.backward(
    ctx,
    grad_multihot_indices,
    grad_probs_in_multihot
)
```

staticmethod

Backward function for IndicesToMultihot

Convert multihot probs representation to indices.
indices is ignored in the backward function.

**Parameters:**

\[num\_of\_tokens, num\_of\_local\_experts]

\[num\_of\_tokens, num\_of\_local\_experts]

**Returns:**

\[num\_of\_tokens, topk]

```python
nemo_automodel.components.moe.megatron.fused_indices_converter.IndicesToMultihot.forward(
    ctx,
    indices,
    probs_indices,
    num_of_local_experts
)
```

staticmethod

Forward function for IndicesToMultihot

Convert indices to multihot representation.

**Parameters:**

\[num\_of\_tokens, topk]

\[num\_of\_tokens, topk]

int

**Returns:**

\[num\_of\_tokens, num\_of\_local\_experts]

```python
nemo_automodel.components.moe.megatron.fused_indices_converter._indices_to_multihot_kernel(
    indices_ptr,
    probs_in_indices_ptr,
    multihot_indices_ptr,
    probs_in_multihot_ptr,
    position_map_ptr,
    num_of_local_experts: triton.language.constexpr,
    num_of_local_experts_next_power_of_2: triton.language.constexpr,
    topk: triton.language.constexpr,
    topk_next_power_of_2: triton.language.constexpr,
    BLOCK_SIZE: triton.language.constexpr
)
```

Triton kernel for converting indices to multihot representation.

Output:
multihot\_indices: \[num\_of\_tokens, num\_of\_local\_experts]
probs\_in\_multihot: \[num\_of\_tokens, num\_of\_local\_experts]

Assume that topk = 2 , num\_of\_local\_experts = 4, num\_of\_tokens = 2,
then the kernel can process the following conversion:

Output Example:
multihot\_indices = \[
\[1, 1, -1, -1],
\[-1, 1, 1, -1]
]
probs\_in\_multihot = \[
\[0.1, 0.2, 0.0, 0.0],
\[0.0, 0.3, 0.4, 0.0]
]

```python
nemo_automodel.components.moe.megatron.fused_indices_converter._multihot_to_indices_kernel(
    probs_in_multihot_ptr,
    position_map_ptr,
    probs_indices_ptr,
    num_of_local_experts: triton.language.constexpr,
    num_of_local_experts_next_power_of_2: triton.language.constexpr,
    topk: triton.language.constexpr,
    topk_next_power_of_2: triton.language.constexpr,
    BLOCK_SIZE: triton.language.constexpr
)
```

Triton kernel for converting multihot representation to indices.

Output:
probs\_indices: \[num\_of\_tokens, topk]

Assume that topk = 2 , num\_of\_local\_experts = 4, num\_of\_tokens = 2,
then the kernel can process the following conversion:

Output Example:
probs\_indices = \[
\[0.7, 0.8],
\[0.1, 0.9]
]

```python
nemo_automodel.components.moe.megatron.fused_indices_converter.fused_indices_to_multihot(
    indices,
    probs_indices,
    num_of_local_experts
)
```

Convert moe topk indices to multihot representation.

This function is an experimental feature and may change in future versions.

```python
nemo_automodel.components.moe.megatron.fused_indices_converter.HAVE_TRITON = True
```

```python
nemo_automodel.components.moe.megatron.fused_indices_converter.null_decorator = partial(lambda x: x)
```