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.nemotron_h
The Nemotron-H architecture.
A hybrid decoder interleaving Mamba-2 mixers, NoPE GQA attention, and relu2 MLP blocks. The Nemotron 3 MoE variants add mixture-of-experts blocks.
NemotronH
class max.pipelines.architectures.nemotron_h.NemotronH(config)
Bases: Module
Full Nemotron-H decoder: embed -> hybrid blocks -> norm -> lm_head.
Registered for the DECODER role. Its Mamba layers keep each request’s
conv and SSM state in the KV cache’s state leaves, which the graph updates
in place.
-
Parameters:
-
config (NemotronHConfig)
graph_name
graph_name = 'nemotron_h'
The name the graph compiled under before registration, which keys precompiled MEFs.
load_state_dict()
load_state_dict(state_dict, *, override_quantization_encoding=False, weight_alignment=None, strict=True)
Loads the checkpoint, logging the weights it lacks or doesn’t use.
-
Parameters:
-
- state_dict (Mapping[str, DLPackArray | WeightData])
- override_quantization_encoding (bool)
- weight_alignment (int | None)
- strict (bool)
-
Return type:
-
None
override_quantization_encoding
override_quantization_encoding = True
strict_state_dict_loading
strict_state_dict_loading = False
NemotronHConfig
class max.pipelines.architectures.nemotron_h.NemotronHConfig(*, hidden_size, vocab_size, num_hidden_layers, layer_norm_epsilon, max_seq_len, dtype, devices, tie_word_embeddings=False, layer_kinds=<factory>, num_attention_heads, num_key_value_heads, attention_head_dim, attention_bias=False, intermediate_size, mlp_hidden_act='relu2', mlp_bias=False, num_experts=0, num_experts_per_tok=0, moe_intermediate_size=0, moe_shared_expert_intermediate_size=0, routed_scaling_factor=1.0, norm_topk_prob=True, mamba_num_heads, mamba_head_dim, n_groups, ssm_state_size, conv_kernel, chunk_size, use_conv_bias=True, mamba_proj_bias=False, time_step_limit=(0.0, inf), kv_params, fp8_mamba_layers=<factory>, fp8_mlp_layers=<factory>, fp8_moe_layers=<factory>, fp8_attention_layers=<factory>, is_fp8=False, quantization_encoding=None, quant_config=None, return_logits=ReturnLogits.LAST_TOKEN)
Bases: ArchConfigWithStoredKVParams, ArchConfigWithKVCache
Configuration for a Nemotron-H (nemotron_h) hybrid decoder.
Nemotron-H interleaves Mamba-2 mixers, NoPE GQA attention, and relu2
(non-gated) MLP blocks per hybrid_override_pattern. There is no
rotary embedding (attention is NoPE; position information flows through
the SSM). FP8 (modelopt per-tensor static) is applied per-module to the
Mamba in/out projections and the MLP up/down projections, honoring the
checkpoint’s exclude_modules list; attention, conv1d, norms, and
lm_head stay bf16.
-
Parameters:
-
- hidden_size (int)
- vocab_size (int)
- num_hidden_layers (int)
- layer_norm_epsilon (float)
- max_seq_len (int)
- dtype (DType)
- devices (list[DeviceRef])
- tie_word_embeddings (bool)
- layer_kinds (list[str])
- num_attention_heads (int)
- num_key_value_heads (int)
- attention_head_dim (int)
- attention_bias (bool)
- intermediate_size (int)
- mlp_hidden_act (str)
- mlp_bias (bool)
- num_experts (int)
- num_experts_per_tok (int)
- moe_intermediate_size (int)
- moe_shared_expert_intermediate_size (int)
- routed_scaling_factor (float)
- norm_topk_prob (bool)
- mamba_num_heads (int)
- mamba_head_dim (int)
- n_groups (int)
- ssm_state_size (int)
- conv_kernel (int)
- chunk_size (int)
- use_conv_bias (bool)
- mamba_proj_bias (bool)
- time_step_limit (tuple[float, float])
- kv_params (MultiKVCacheParams)
- fp8_mamba_layers (set[int])
- fp8_mlp_layers (set[int])
- fp8_moe_layers (set[int])
- fp8_attention_layers (set[int])
- is_fp8 (bool)
- quantization_encoding (SupportedEncoding | None)
- quant_config (QuantConfig | None)
- return_logits (ReturnLogits)
DEFAULT_ENCODING
DEFAULT_ENCODING: ClassVar[SupportedEncoding] = 'bfloat16'
SUPPORTED_ENCODINGS
SUPPORTED_ENCODINGS: ClassVar[set[SupportedEncoding]] = {'bfloat16', 'float8_e4m3fn'}
attention_bias
attention_bias: bool = False
attention_head_dim
attention_head_dim: int
attention_kv_dim
property attention_kv_dim: int
The key and value width across all key/value heads.
attention_layer_indices
The indices of the layers whose mixer is attention.
attention_q_dim
property attention_q_dim: int
The query width across all attention heads.
attn_kv_params
property attn_kv_params: KVCacheParams
The attention child of kv_params.
calculate_max_seq_len()
classmethod calculate_max_seq_len(huggingface_config, model_config)
The configured maximum length, capped at the model’s default.
-
Parameters:
-
- huggingface_config (AutoConfig)
- model_config (MAXModelConfig)
-
Return type:
chunk_size
chunk_size: int
construct_kv_params()
static construct_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype, *, allow_kv_head_replication=False)
Returns the attention leaf beside the Mamba state.
KV is allocated only for the full-attention layers. The forward pass maps each attention layer to a sequential KV cache index (0, 1, 2, …), independent of the absolute layer index; the Mamba layers do the same in the state leaves.
The reference configuration uses an FP8 KV cache for this checkpoint. Select the same default while preserving explicit cache-format overrides and non-FP8 model behavior.
-
Parameters:
-
- huggingface_config (AutoConfig)
- pipeline_config (PipelineConfig)
- devices (list[DeviceRef])
- kv_cache_config (KVCacheConfig)
- cache_dtype (DType)
- allow_kv_head_replication (bool)
-
Return type:
conv_dim
property conv_dim: int
The width the causal convolution runs at.
conv_kernel
conv_kernel: int
devices
dtype
dtype: DType
finalize()
finalize(huggingface_config, state_dict, outputs)
Completes the config in place from the checkpoint.
Records which layers are FP8 and their scheme, from the checkpoint’s
weight_scale tensors, and the logits the pipeline returns.
-
Parameters:
-
- huggingface_config (AutoConfig)
- state_dict (Mapping[str, WeightData])
- outputs (ModelOutputConfig)
-
Return type:
-
None
fp8_attention_layers
fp8_mamba_layers
fp8_mlp_layers
fp8_moe_layers
from_hf()
classmethod from_hf(pipeline_config, huggingface_config, dtype, kv_params, devices, *, max_seq_len)
Builds the config from the checkpoint’s config.json.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- huggingface_config (AutoConfig)
- dtype (DType)
- kv_params (MultiKVCacheParams)
- devices (list[DeviceRef])
- max_seq_len (int)
-
Return type:
get_num_layers()
static get_num_layers(huggingface_config)
The checkpoint’s hidden layer count.
-
Parameters:
-
huggingface_config (AutoConfig)
-
Return type:
hidden_size
hidden_size: int
initialize()
classmethod initialize(pipeline_config, model_config=None, *, max_seq_len)
ArchConfig protocol entry point.
Derives dtype / devices / KV params from model_config and delegates
to from_hf(). model.py calls from_hf() directly during
graph build (it already has the resolved KV params); this method exists
so the pipeline config-resolution / memory-estimation path can build the
arch config from a PipelineConfig alone.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- model_config (MAXModelConfig | None)
- max_seq_len (int)
-
Return type:
intermediate_size
intermediate_size: int
is_fp8
is_fp8: bool = False
kv_params
kv_params: MultiKVCacheParams
The cache tree: the attention layers’ KV beside the Mamba state.
layer_kinds
layer_norm_epsilon
layer_norm_epsilon: float
mamba_head_dim
mamba_head_dim: int
mamba_in_proj_out
property mamba_in_proj_out: int
The width the mixer’s input projection produces.
mamba_intermediate_size
property mamba_intermediate_size: int
The mixer’s width, from the head count and the head width.
mamba_layer_indices
The indices of the layers whose mixer is Mamba-2.
mamba_num_heads
mamba_num_heads: int
mamba_proj_bias
mamba_proj_bias: bool = False
max_seq_len
max_seq_len: int
mlp_bias
mlp_bias: bool = False
mlp_hidden_act
mlp_hidden_act: str = 'relu2'
moe_intermediate_size
moe_intermediate_size: int = 0
moe_shared_expert_intermediate_size
moe_shared_expert_intermediate_size: int = 0
n_groups
n_groups: int
norm_topk_prob
norm_topk_prob: bool = True
num_attention_heads
num_attention_heads: int
num_experts
num_experts: int = 0
num_experts_per_tok
num_experts_per_tok: int = 0
num_hidden_layers
num_hidden_layers: int
num_key_value_heads
num_key_value_heads: int
populate_fp8_layers()
populate_fp8_layers(state_dict)
Record which mamba/MLP/MoE/attention layers are FP8 from the checkpoint.
A Linear is FP8 iff its weight_scale is present in the checkpoint
(the exact inverse of the modelopt exclude_modules list). Names are
the post-adapter MAX names: blocks.{i}.mixer.{in_proj,out_proj, up_proj,down_proj}.weight_scale.
-
Parameters:
-
state_dict (Mapping[str, WeightData])
-
Return type:
-
None
quant_config
quant_config: QuantConfig | None = None
The per-tensor static FP8 scheme of the FP8 layers, from the
checkpoint (finalize()).
quantization_encoding
quantization_encoding: SupportedEncoding | None = None
return_logits
return_logits: ReturnLogits = 'last_token'
routed_scaling_factor
routed_scaling_factor: float = 1.0
ssm_state_size
ssm_state_size: int
tie_word_embeddings
tie_word_embeddings: bool = False
time_step_limit
use_conv_bias
use_conv_bias: bool = True
vocab_size
vocab_size: int