Skip to navigation

nemo_automodel.components.models.step3p5.model

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
BlockStep3p5 transformer block with attention, MLP/MoE, and shared experts.
Step3p5ForCausalLMStep3p5 model for causal language modeling.
Step3p5ModelStep3p5 transformer model.

Functions

NameDescription
_keep_step_router_bias_fp32Keep Step router correction bias in fp32 after module-wide dtype casts.
parse_moe_layers_enumParse moe_layers_enum to get set of MoE layer indices.

Data

ModelClass

API

class nemo_automodel.components.models.step3p5.model.Block(
layer_idx: int,
config: typing.Any,
)

Bases: Module

Step3p5 transformer block with attention, MLP/MoE, and shared experts.

attention_type
input_layernorm
is_moe_layer
= layer_idx in moe_layers
moe
= MoE(layer_moe_config, backend)
post_attention_layernorm
self_attn
= Step3p5Attention(config, layer_idx, backend)
share_expert
nemo_automodel.components.models.step3p5.model.Block.forward(
x: torch.Tensor,
freqs_cis: torch.Tensor,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
position_ids: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor
nemo_automodel.components.models.step3p5.model.Block.init_weights(
buffer_device: torch.device
) -> None
class nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM(
config: typing.Any,
logits_dtype: torch.dtype | None = None,
moe_overrides: dict | None = None
)

Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin

Step3p5 model for causal language modeling.

_keep_in_fp32_modules
= ['rotary_emb']
_uses_native_fa4
bool = True
backend
= backend or BackendConfig()
lm_head
model
state_dict_adapter
tie_word_embeddings_support
TieSupport = TieSupport.UNTIED_ONLY
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.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 Step3p5Model 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 padding mask of shape [batch, sequence], 1 at valid tokens and 0 at padding, for unpacked input; 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; when None, the MoE layers derive it from attention_mask.

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.step3p5.model.Step3p5ForCausalLM.from_config(
config: typing.Any,
kwargs = {}
)
classmethod
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.from_pretrained(
pretrained_model_name_or_path: str,
model_args = (),
kwargs = {}
)
classmethod
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.get_input_embeddings()
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.get_output_embeddings()
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.initialize_weights(
buffer_device: torch.device | None = None,
dtype: torch.dtype = torch.bfloat16
) -> None
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.set_input_embeddings(
value
)
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.set_output_embeddings(
new_embeddings
)
class nemo_automodel.components.models.step3p5.model.Step3p5Model(
config: typing.Any,
moe_overrides: dict | None = None
)

Bases: Module

Step3p5 transformer model.

embed_tokens
has_sliding_layers
= 'sliding_attention' in layer_types
head_dim
layers
= torch.nn.ModuleDict()
max_seq_len
= config.max_position_embeddings
moe_config
= moe_config or MoEConfig(**moe_defaults)
norm
rotary_emb
nemo_automodel.components.models.step3p5.model.Step3p5Model._apply(
fn
)
nemo_automodel.components.models.step3p5.model.Step3p5Model.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 = {}
) -> torch.Tensor

Run the decoder layers on padded or packed (THD) input.

Packed input arrives batched and is squeezed to [tokens, …] for the layers, which TE’s packed kernels take; the hidden states come back batched. Callers that already squeezed packed input for their own preprocessing pass [tokens] layouts, which the squeeze leaves unchanged.

Parameters:

input_ids
torch.Tensor | NoneDefaults to None

Token IDs of shape [batch, sequence], or packed token IDs of shape [1, tokens]. Later pipeline stages pass hidden states of shape [batch, sequence, hidden] or [1, tokens, hidden].

inputs_embeds
torch.Tensor | NoneDefaults to None

Optional embeddings of shape [batch, sequence, hidden] used instead of input_ids, or packed [tokens, hidden] from a caller that already squeezed packed input.

position_ids
torch.Tensor | NoneDefaults to None

Optional positions of shape [batch, sequence]; packed input requires them, as [1, tokens].

attention_mask
torch.Tensor | NoneDefaults to None

Optional padding mask of shape [batch, sequence], 1 at valid tokens and 0 at padding, for unpacked input; packed input ignores it.

padding_mask
torch.Tensor | NoneDefaults to None

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

**attn_kwargs
AnyDefaults to {}

Backend metadata. 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: torch.Tensor

Hidden states of shape [batch, sequence, hidden], or [1, tokens, hidden] for packed input.

nemo_automodel.components.models.step3p5.model.Step3p5Model.init_weights(
buffer_device: torch.device | None = None
) -> None
nemo_automodel.components.models.step3p5.model._keep_step_router_bias_fp32(
module: torch.nn.Module
) -> None

Keep Step router correction bias in fp32 after module-wide dtype casts.

nemo_automodel.components.models.step3p5.model.parse_moe_layers_enum(
moe_layers_enum: str | int | tuple | list | None,
num_hidden_layers: int
) -> set[int]

Parse moe_layers_enum to get set of MoE layer indices.

Parameters:

moe_layers_enum
str | int | tuple | list | None

Tuple/list of layer indices, integer, comma-separated string, or None. HF Step-3.5-Flash uses tuple format like (3, 4, 5, …, 44).

num_hidden_layers
int

Total number of hidden layers.

Returns: set[int]

Set of layer indices that should be MoE layers.

nemo_automodel.components.models.step3p5.model.ModelClass = Step3p5ForCausalLM