> 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.models.deepseek_v3.model

## Module Contents

### Classes

| Name                                                                                                 | Description |
| ---------------------------------------------------------------------------------------------------- | ----------- |
| [`Block`](#nemo_automodel-components-models-deepseek_v3-model-Block)                                 | -           |
| [`DeepseekV3ForCausalLM`](#nemo_automodel-components-models-deepseek_v3-model-DeepseekV3ForCausalLM) | -           |
| [`DeepseekV3Model`](#nemo_automodel-components-models-deepseek_v3-model-DeepseekV3Model)             | -           |

### Data

[`ModelClass`](#nemo_automodel-components-models-deepseek_v3-model-ModelClass)

### API

```python
class nemo_automodel.components.models.deepseek_v3.model.Block(
    layer_idx: int,
    config: transformers.models.deepseek_v3.configuration_deepseek_v3.DeepseekV3Config,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

```python
nemo_automodel.components.models.deepseek_v3.model.Block._mlp(
    x: torch.Tensor,
    padding_mask: torch.Tensor
) -> torch.Tensor
```

```python
nemo_automodel.components.models.deepseek_v3.model.Block.forward(
    x: torch.Tensor,
    freqs_cis: torch.Tensor,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> tuple[torch.Tensor, torch.Tensor | None]
```

Forward pass for the Transformer block.

**Parameters:**

Input tensor.

Precomputed complex exponential values for rotary embeddings.

Boolean tensor indicating padding positions.

**Returns:** `torch.Tensor`

torch.Tensor: Output tensor after block computation.

```python
nemo_automodel.components.models.deepseek_v3.model.Block.init_weights(
    buffer_device: torch.device
)
```

```python
class nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM(
    config: transformers.models.deepseek_v3.configuration_deepseek_v3.DeepseekV3Config,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

**Bases:** [HFCheckpointingMixin](/nemo-automodel/nemo_automodel/components/models/common/hf_checkpointing_mixin#nemo_automodel-components-models-common-hf_checkpointing_mixin-HFCheckpointingMixin), `Module`, [MoEFSDPSyncMixin](/nemo-automodel/nemo_automodel/components/moe/fsdp_mixin#nemo_automodel-components-moe-fsdp_mixin-MoEFSDPSyncMixin)

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.forward(
    input_ids: torch.Tensor,
    position_ids: torch.Tensor | None = None,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    logits_to_keep: typing.Union[int, torch.Tensor] = 0,
    output_hidden_states: typing.Optional[bool] = None,
    attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast
```

Forward pass returning :class:`~transformers.modeling_outputs.CausalLMOutputWithPast`.

**Parameters:**

Input token IDs. BSHD: `[B, S]`; THD: `[1, T]` (squeezed internally).

Optional position indices.

Optional attention mask.

Optional padding mask.

If `0` (default), compute logits for all positions; otherwise
only compute logits for the last `logits_to_keep` positions (avoids
materialising the full logit matrix during generation / fused CE training).

Whether to carry the final hidden states on the output.

Additional arguments forwarded to the base model
(e.g. qkv\_format, cu\_seqlens, CP kwargs).

**Returns:** `CausalLMOutputWithPast`

class:`~transformers.modeling_outputs.CausalLMOutputWithPast` with `logits` and,

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.from_config(
    config: transformers.models.deepseek_v3.configuration_deepseek_v3.DeepseekV3Config,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.from_pretrained(
    pretrained_model_name_or_path: str,
    model_args = (),
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.get_input_embeddings()
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.get_output_embeddings()
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.initialize_weights(
    buffer_device: torch.device | None = None,
    dtype: torch.dtype = torch.bfloat16
) -> None
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.set_input_embeddings(
    value
)
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.set_output_embeddings(
    new_embeddings
)
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3ForCausalLM.update_moe_gate_bias() -> None
```

```python
class nemo_automodel.components.models.deepseek_v3.model.DeepseekV3Model(
    config: transformers.models.deepseek_v3.configuration_deepseek_v3.DeepseekV3Config,
    backend: nemo_automodel.components.models.common.BackendConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    moe_overrides: dict | None = None
)
```

**Bases:** `Module`

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3Model.forward(
    input_ids: torch.Tensor | None = None,
    inputs_embeds: torch.Tensor | None = None,
    position_ids: torch.Tensor | None = None,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> tuple[torch.Tensor, torch.Tensor | None]
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3Model.init_weights(
    buffer_device: torch.device | None = None
) -> None
```

```python
nemo_automodel.components.models.deepseek_v3.model.DeepseekV3Model.update_moe_gate_bias() -> None
```

```python
nemo_automodel.components.models.deepseek_v3.model.ModelClass = DeepseekV3ForCausalLM
```