Skip to navigation

nemo_automodel.components.models.deepseek_v32.model

View as MarkdownOpen in Claude

DeepSeek V3.2 Model.

Contains DeepseekV32Block, DeepseekV32Model, and DeepseekV32ForCausalLM. These classes subclass from DeepSeek V3, with the main difference being the use of DeepseekV32MLA (with Indexer) instead of the standard MLA.

Module Contents

Classes

NameDescription
DeepseekV32BlockTransformer block for DeepSeek V3.2.
DeepseekV32ForCausalLMDeepSeek V3.2 for Causal Language Modeling.
DeepseekV32ModelDeepSeek V3.2 Model.

Data

ModelClass

API

class nemo_automodel.components.models.deepseek_v32.model.DeepseekV32Block(
layer_idx: int,
)

Bases: Block

Transformer block for DeepSeek V3.2.

Subclasses V3 Block, using DeepseekV32MLA (with Indexer) instead of the standard MLA.

input_layernorm
is_moe_layer
= layer_idx >= config.first_k_dense_replace
mlp
post_attention_layernorm
self_attn
= DeepseekV32MLA(config, backend)
class nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM(
logits_dtype: torch.dtype | None = None,
moe_overrides: dict | None = None
)

Bases: DeepseekV3ForCausalLM

DeepSeek V3.2 for Causal Language Modeling.

Subclasses V3 ForCausalLM, using DeepseekV32Model and DeepSeekV32StateDictAdapter.

_uses_native_fa4
bool = False
lm_head
model
state_dict_adapter
tie_word_embeddings_support
TieSupport = TieSupport.UNTIED_ONLY
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.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: bool | None = None,
attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast

Run the decoder and project the kept positions to vocabulary logits.

Parameters:

input_ids
torch.Tensor

Token IDs of shape [batch, sequence], or packed (THD) IDs of shape [1, tokens], which the decoder squeezes to [tokens]. Later pipeline stages pass hidden states of shape [batch, sequence, hidden] or [1, tokens, hidden].

position_ids
torch.Tensor | NoneDefaults to None

Optional positions of shape [batch, sequence], or [1, tokens] for packed input, which requires them.

attention_mask
torch.Tensor | NoneDefaults to None

Optional additive mask of shape [batch, 1, sequence, sequence], 0 to attend and -inf to mask, for unpacked input with SDPA. The sparse indexer also adds it to its top-k scores, and padding_mask should accompany it. Packed input ignores it.

padding_mask
torch.Tensor | NoneDefaults to None

Optional bool Tensor of shape [batch, sequence], or [1, tokens] when packed, true at padding.

logits_to_keep
Union[int, torch.Tensor]Defaults to 0

0 keeps every position, a positive int keeps the last N positions, and an integer Tensor of shape [kept] keeps those positions.

output_hidden_states
bool | NoneDefaults to None

Whether the output carries the final hidden states; None reads config.output_hidden_states.

**attn_kwargs
AnyDefaults to {}

Backend metadata for the decoder. Packed input sets qkv_format="thd" and passes int32 cu_seqlens and cu_seqlens_padded of shape [1, documents + 1], padded with -1000, and max_seqlen.

Returns: CausalLMOutputWithPast

CausalLMOutputWithPast whose logits have shape [batch, kept, vocab], or [1, kept, vocab] for packed

nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.from_config(
kwargs = {}
)
classmethod
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.from_pretrained(
pretrained_model_name_or_path: str,
model_args = (),
kwargs = {}
)
classmethod
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.get_input_embeddings()
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.get_output_embeddings()
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.set_input_embeddings(
value
)
nemo_automodel.components.models.deepseek_v32.model.DeepseekV32ForCausalLM.set_output_embeddings(
new_embeddings
)
class nemo_automodel.components.models.deepseek_v32.model.DeepseekV32Model(
moe_overrides: dict | None = None
)

Bases: DeepseekV3Model

DeepSeek V3.2 Model.

Subclasses V3 Model, using DeepseekV32Block instead of Block.

embed_tokens
layers
= torch.nn.ModuleDict()
max_seq_len
= config.max_position_embeddings
moe_config
= moe_config or MoEConfig(**moe_defaults)
norm
nemo_automodel.components.models.deepseek_v32.model.ModelClass = DeepseekV32ForCausalLM