nemo_automodel.components.models.minimax_m2.model

View as Markdown

Module Contents

Classes

NameDescription
BlockMiniMax-M2 transformer block with attention + MoE.
MiniMaxM2ForCausalLM-
MiniMaxM2Model-

Data

ModelClass

API

class nemo_automodel.components.models.minimax_m2.model.Block(
layer_idx: int,
config: typing.Any,
moe_config: nemo_automodel.components.moe.layers.MoEConfig,
backend: nemo_automodel.components.models.common.BackendConfig
)

Bases: Module

MiniMax-M2 transformer block with attention + MoE.

input_layernorm
mlp
= MoE(moe_config, backend)
post_attention_layernorm
self_attn
= MiniMaxM2Attention(config, backend)
nemo_automodel.components.models.minimax_m2.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 = {}
) -> torch.Tensor
nemo_automodel.components.models.minimax_m2.model.Block.init_weights(
buffer_device: torch.device
)
class nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM(
config: typing.Any,
moe_config: nemo_automodel.components.moe.layers.MoEConfig | None = None,
backend: nemo_automodel.components.models.common.BackendConfig | None = None,
kwargs = {}
)

Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin

backend
= backend or BackendConfig()
lm_head
model
state_dict_adapter
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.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_ids
torch.Tensor

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

position_ids
torch.Tensor | NoneDefaults to None

Optional position indices.

attention_mask
torch.Tensor | NoneDefaults to None

Optional attention mask.

padding_mask
torch.Tensor | NoneDefaults to None

Optional padding mask.

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

If 0, compute logits for all positions (training default); otherwise only compute logits for the last logits_to_keep token positions.

output_hidden_states
Optional[bool]Defaults to None

Whether to return the final hidden states on the output.

**attn_kwargs
AnyDefaults to {}

Additional arguments forwarded to the base model (e.g. qkv_format).

Returns: CausalLMOutputWithPast

class:~transformers.modeling_outputs.CausalLMOutputWithPast with logits

nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.from_config(
config: typing.Any,
moe_config: nemo_automodel.components.moe.layers.MoEConfig | None = None,
backend: nemo_automodel.components.models.common.BackendConfig | None = None,
kwargs = {}
)
classmethod
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.from_pretrained(
pretrained_model_name_or_path: str,
model_args = (),
kwargs = {}
)
classmethod
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.get_input_embeddings()
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.get_output_embeddings()
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.initialize_weights(
buffer_device: torch.device | None = None,
dtype: torch.dtype = torch.bfloat16
) -> None
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.set_input_embeddings(
value
)
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2ForCausalLM.set_output_embeddings(
new_embeddings
)
class nemo_automodel.components.models.minimax_m2.model.MiniMaxM2Model(
config: typing.Any,
backend: nemo_automodel.components.models.common.BackendConfig,
moe_config: nemo_automodel.components.moe.layers.MoEConfig | None = None,
moe_overrides: dict | None = None
)

Bases: Module

embed_tokens
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.minimax_m2.model.MiniMaxM2Model.forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor
nemo_automodel.components.models.minimax_m2.model.MiniMaxM2Model.init_weights(
buffer_device: torch.device | None = None
) -> None
nemo_automodel.components.models.minimax_m2.model.ModelClass = MiniMaxM2ForCausalLM