For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python module
max.pipelines.architectures.minimax_m2
MiniMaxM2Config
class max.pipelines.architectures.minimax_m2.MiniMaxM2Config(*, hidden_size, num_attention_heads, num_key_value_heads, num_hidden_layers, rope_theta, rope_scaling_params, max_seq_len, intermediate_size, interleaved_rope_weights, vocab_size, dtype, model_quantization_encoding, quantization_config, kv_params, return_logits=ReturnLogits.LAST_TOKEN, norm_method='rms_norm', norm_dtype=None, attention_bias=False, rms_norm_eps=None, tie_word_embeddings=False, stacked_mlp=False, stacked_qkv=False, attention_multiplier, embedding_multiplier, residual_multiplier, devices, clip_qkv, quant_config=None, longrope_scaling_params=None, logits_scaling=1.0, return_hidden_states=ReturnHiddenStates.NONE, target_layer_ids=None, use_subgraphs=True, data_parallel_degree=1, sliding_window=None, quantization_encoding=None, num_local_experts=256, num_experts_per_tok=8, norm_topk_prob=True, correction_bias_dtype=None, gate_dtype=None, attn_dtype=None, ep_config=None, partial_rotary_factor=1.0)
Bases: Llama3Config
Configuration for MiniMax-M2 MoE models.
Extends Llama3Config with MoE-specific parameters including sigmoid routing with expert score correction bias.
-
Parameters:
-
- hidden_size (int)
- num_attention_heads (int)
- num_key_value_heads (int)
- num_hidden_layers (int)
- rope_theta (float)
- rope_scaling_params (Llama3RopeScalingParams | None)
- max_seq_len (int)
- intermediate_size (int)
- interleaved_rope_weights (bool)
- vocab_size (int)
- dtype (DType)
- model_quantization_encoding (QuantizationEncoding | None)
- quantization_config (QuantizationConfig | None)
- kv_params (KVCacheParams)
- return_logits (ReturnLogits)
- norm_method (Literal['rms_norm', 'layer_norm'])
- norm_dtype (DType | None)
- attention_bias (bool)
- rms_norm_eps (float | None)
- tie_word_embeddings (bool)
- stacked_mlp (bool)
- stacked_qkv (bool)
- attention_multiplier (float)
- embedding_multiplier (float)
- residual_multiplier (float)
- devices (list[DeviceRef])
- clip_qkv (float | None)
- quant_config (QuantConfig | None)
- longrope_scaling_params (LongRoPEScalingParams | None)
- logits_scaling (float)
- return_hidden_states (ReturnHiddenStates)
- target_layer_ids (list[int] | None)
- use_subgraphs (bool)
- data_parallel_degree (int)
- sliding_window (int | None)
- quantization_encoding (SupportedEncoding | None)
- num_local_experts (int)
- num_experts_per_tok (int)
- norm_topk_prob (bool)
- correction_bias_dtype (DType | None)
- gate_dtype (DType | None)
- attn_dtype (DType | None)
- ep_config (EPConfig | None)
- partial_rotary_factor (float)
DEFAULT_ENCODING
DEFAULT_ENCODING: ClassVar[SupportedEncoding] = 'float8_e4m3fn'
SUPPORTED_ENCODINGS
SUPPORTED_ENCODINGS: ClassVar[set[SupportedEncoding]] = {'float4_e2m1fnx2', 'float8_e4m3fn'}
attn_dtype
Data type for attention weights. Detected from state dict during finalize().
calculate_attention_multiplier()
static calculate_attention_multiplier(huggingface_config)
The attention multiplier for MiniMax-M2 models.
Uses the explicit head_dim from the config.
-
Parameters:
-
huggingface_config (AutoConfig) – The HuggingFace configuration object.
-
Returns:
-
The attention multiplier value.
-
Return type:
correction_bias_dtype
Data type of the e_score_correction_bias weight. Detected from state dict during finalize().
ep_config
ep_config: EPConfig | None = None
Expert parallelism configuration. None means no EP (single-GPU).
gate_dtype
Data type for the gate linear layer. Detected from state dict during finalize().
initialize()
classmethod initialize(pipeline_config, model_config=None, *, max_seq_len)
Initializes a MiniMaxM2Config from pipeline configuration.
-
Parameters:
-
- pipeline_config (PipelineConfig) – The MAX Engine pipeline configuration.
- model_config (MAXModelConfig | None)
- max_seq_len (int)
-
Returns:
-
An initialized MiniMaxM2Config instance.
-
Return type:
initialize_from_config()
classmethod initialize_from_config(pipeline_config, huggingface_config, model_config=None, *, max_seq_len)
Initializes a MiniMaxM2Config from pipeline and HuggingFace configs.
-
Parameters:
-
- pipeline_config (PipelineConfig) – The MAX Engine pipeline configuration.
- huggingface_config (AutoConfig) – The HuggingFace model configuration.
- model_config (MAXModelConfig | None) – The MAX Engine model configuration.
- max_seq_len (int)
-
Returns:
-
An initialized MiniMaxM2Config instance.
-
Return type:
norm_topk_prob
norm_topk_prob: bool = True
Whether to normalize top-k expert probabilities to sum to 1.
num_experts_per_tok
num_experts_per_tok: int = 8
Number of experts selected per token.
num_local_experts
num_local_experts: int = 256
Number of local experts in each MoE layer.
partial_rotary_factor
partial_rotary_factor: float = 1.0
Fraction of head_dim used for rotary embeddings. For MiniMax-M2: rotary_dim/head_dim = 64/128 = 0.5.
MiniMaxM2Inputs
class max.pipelines.architectures.minimax_m2.MiniMaxM2Inputs(tokens, input_row_offsets, signal_buffers, return_n_logits, data_parallel_splits=None, *, kv_cache_inputs=None, lora_buffers=(), vision_embeddings=<factory>, vision_scatter_indices=<factory>, hidden_states=None, ep_inputs=(), host_input_row_offsets=None)
Bases: Llama3Inputs
Inputs for MiniMax-M2 with EP and DP support.
-
Parameters:
-
- tokens (Buffer)
- input_row_offsets (Buffer)
- signal_buffers (list[Buffer])
- return_n_logits (Buffer)
- data_parallel_splits (Buffer | Sequence[Sequence[int]] | None)
- kv_cache_inputs (KVCacheInputsInterface[Buffer, Buffer] | None)
- lora_buffers (tuple[Buffer, ...])
- vision_embeddings (list[Buffer])
- vision_scatter_indices (list[Buffer])
- hidden_states (Buffer | list[Buffer] | None)
- ep_inputs (tuple[Buffer, ...])
- host_input_row_offsets (Buffer | None)
buffers
Returns positional Buffer inputs for model ABI calls.
ep_inputs
host_input_row_offsets
MiniMaxM2Model
class max.pipelines.architectures.minimax_m2.MiniMaxM2Model(pipeline_config, session, devices, kv_cache_config, weights, *, memory_plan, adapter=None, return_logits=ReturnLogits.LAST_TOKEN, return_hidden_states=ReturnHiddenStates.NONE, max_batch_size=1)
Bases: AlwaysSignalBuffersMixin, LlamaModelBase
MiniMax-M2 pipeline model for text generation.
Uses AlwaysSignalBuffersMixin since VocabParallelEmbedding and ColumnParallelLinear always require signal buffers for allreduce.
-
Parameters:
-
- pipeline_config (PipelineConfig) – The configuration for this pipeline.
- session (InferenceSession) – The container for the runtime for this model.
- devices (list[Device])
- kv_cache_config (KVCacheConfig)
- weights (Weights)
- memory_plan (MemoryPlan)
- adapter (WeightsAdapter | None)
- return_logits (ReturnLogits)
- return_hidden_states (ReturnHiddenStates)
- max_batch_size (int)
attention_bias
attention_bias: bool = False
Whether to use attention bias.
batch_processor_cls
batch_processor_cls
alias of MiniMaxM2BatchProcessor
model
model: Model
Compiled and initialized model ready for inference.
model_config_cls
model_config_cls
alias of MiniMaxM2Config
norm_method
norm_method: Literal['rms_norm', 'layer_norm'] = 'rms_norm'
Normalization layer.
state_dict
Weights to load into the model.
MiniMaxM2ReasoningParser
class max.pipelines.architectures.minimax_m2.MiniMaxM2ReasoningParser(think_start_token_id, think_end_token_id, tool_call_start_token_id=None)
Bases: ReasoningParser
MiniMax-M2 reasoning parser for sections framed by <think> and </think>.
Reasoning may end implicitly when a tool call begins
(<minimax:tool_call>).
Reasoning may begin implicitly, without an explicit <think> token
(the chat template appends <think> to the assistant turn).
-
Parameters:
REASONING_END
Text delimiter that closes a reasoning span (e.g. "</think>").
See REASONING_START for the declaration contract.
REASONING_START
Text delimiter that opens a reasoning span (e.g. "<think>").
Subclasses declare their delimiters here and resolve token ids from them, so each model’s delimiters are written down exactly once. Consumers that work in the text domain rather than the token domain read them from here instead of restating them.
Declare both delimiters or neither. None means this parser has no text
form at all, so a text-domain consumer cannot bound a reasoning span and
will leave reasoning in the assistant’s content; declaring only one is a
bug, since a span needs both ends. A parser whose chat template prefills
the opening delimiter still declares it – whether a given turn emits it is
a property of the request, not of the parser.
from_tokenizer()
async classmethod from_tokenizer(tokenizer)
Construct a reasoning parser from a tokenizer.
-
Parameters:
-
tokenizer (PipelineTokenizer[Any, Any, Any])
-
Return type:
reasoning_end_token_id()
async classmethod reasoning_end_token_id(tokenizer)
Returns the </think> token id.
-
Parameters:
-
tokenizer (PipelineTokenizer[Any, Any, Any])
-
Return type:
-
int | None
stream()
stream(delta_token_ids, is_currently_reasoning=True)
Identify a reasoning span within a streaming delta chunk.
When is_currently_reasoning=False and the chunk contains no
<think> opener, returns an empty span so non-reasoning chunks
(turns where the chat template prefilled </think>, or any
chunk after reasoning ended in a prior chunk) aren’t misclassified
as reasoning.
-
Parameters:
-
Return type:
will_reason_after_prompt()
will_reason_after_prompt(prompt_token_ids)
Predicts whether the model will emit reasoning after this prompt.
Only checks for </think> — not <minimax:tool_call> — because
the chat template embeds tool-call format tokens in the system prompt
when tools are provided, which must not disable reasoning for the
generation that follows.
MinimaxM2ToolParser
class max.pipelines.architectures.minimax_m2.MinimaxM2ToolParser
Bases: StructuralTagToolParser
Parses MiniMax M2-style tool calls from model responses.
MiniMax M2 wraps tool calls in <minimax:tool_call> and uses
<invoke name=...> / </invoke> for individual calls. The base
class drives buffer accumulation and section/call iteration; we
customize the body split ("name"> is the header, the rest is
parameter XML) and provide a structured-to-JSON conversion so the
base’s argument diffing can produce monotonically-growing JSON.
CALL_BEGIN
CALL_BEGIN: ClassVar[str] = '<invoke name='
CALL_END
CALL_END: ClassVar[str] = '</invoke>'
SECTION_BEGIN
SECTION_BEGIN: ClassVar[str] = '<minimax:tool_call>'
SECTION_END
SECTION_END: ClassVar[str] = '</minimax:tool_call>'
XGRAMMAR_FORMAT
XGRAMMAR_FORMAT = 'minimax'
generate_tool_call_grammar()
static generate_tool_call_grammar(response_format_schema=None, tools=None, backend='xgrammar', tool_choice=None, **kwargs)
Generates a constrained-decoding grammar for MiniMax M2 tool calls.
Returns a serialized xgrammar StructuralTag that frames the
<minimax:tool_call> / <invoke name="..."> envelope and
constrains each call’s arguments to that tool’s JSON schema (emitted
as <parameter name=...> values). When response_format_schema
is provided, the grammar also accepts a schema-conforming JSON
response as an alternative to a tool call.
-
Parameters:
-
- response_format_schema (dict[str, Any] | None) – Optional JSON schema dict. When provided, the grammar also accepts a JSON response matching the schema.
- tools (list[dict[str, Any]] | None) – OpenAI-style tool dicts.
- backend (str) – Structured-output backend; must be
"xgrammar". - tool_choice (str | dict[str, Any] | None) –
"auto","required", or a named choice. - **kwargs (Any) – Ignored; accepts
tokenizerand other future kwargs.
-
Returns:
-
The StructuralTag serialized as a JSON string.
-
Return type: