IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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)

source

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'

source

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)

source

Loads the checkpoint, logging the weights it lacks or doesn’t use.

Parameters:

Return type:

None

override_quantization_encoding​

override_quantization_encoding = True

source

strict_state_dict_loading​

strict_state_dict_loading = False

source

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)

source

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:

DEFAULT_ENCODING​

DEFAULT_ENCODING: ClassVar[SupportedEncoding] = 'bfloat16'

source

SUPPORTED_ENCODINGS​

SUPPORTED_ENCODINGS: ClassVar[set[SupportedEncoding]] = {'bfloat16', 'float8_e4m3fn'}

source

attention_bias​

attention_bias: bool = False

source

attention_head_dim​

attention_head_dim: int

source

attention_kv_dim​

property attention_kv_dim: int

source

The key and value width across all key/value heads.

attention_layer_indices​

property attention_layer_indices: list[int]

source

The indices of the layers whose mixer is attention.

attention_q_dim​

property attention_q_dim: int

source

The query width across all attention heads.

attn_kv_params​

property attn_kv_params: KVCacheParams

source

The attention child of kv_params.

calculate_max_seq_len()​

classmethod calculate_max_seq_len(huggingface_config, model_config)

source

The configured maximum length, capped at the model’s default.

Parameters:

Return type:

int

chunk_size​

chunk_size: int

source

construct_kv_params()​

static construct_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype, *, allow_kv_head_replication=False)

source

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:

Return type:

MultiKVCacheParams

conv_dim​

property conv_dim: int

source

The width the causal convolution runs at.

conv_kernel​

conv_kernel: int

source

devices​

devices: list[DeviceRef]

source

dtype​

dtype: DType

source

finalize()​

finalize(huggingface_config, state_dict, outputs)

source

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:

Return type:

None

fp8_attention_layers​

fp8_attention_layers: set[int]

source

fp8_mamba_layers​

fp8_mamba_layers: set[int]

source

fp8_mlp_layers​

fp8_mlp_layers: set[int]

source

fp8_moe_layers​

fp8_moe_layers: set[int]

source

from_hf()​

classmethod from_hf(pipeline_config, huggingface_config, dtype, kv_params, devices, *, max_seq_len)

source

Builds the config from the checkpoint’s config.json.

Parameters:

Return type:

NemotronHConfig

get_num_layers()​

static get_num_layers(huggingface_config)

source

The checkpoint’s hidden layer count.

Parameters:

huggingface_config (AutoConfig)

Return type:

int

hidden_size​

hidden_size: int

source

initialize()​

classmethod initialize(pipeline_config, model_config=None, *, max_seq_len)

source

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:

Return type:

NemotronHConfig

intermediate_size​

intermediate_size: int

source

is_fp8​

is_fp8: bool = False

source

kv_params​

kv_params: MultiKVCacheParams

source

The cache tree: the attention layers’ KV beside the Mamba state.

layer_kinds​

layer_kinds: list[str]

source

layer_norm_epsilon​

layer_norm_epsilon: float

source

mamba_head_dim​

mamba_head_dim: int

source

mamba_in_proj_out​

property mamba_in_proj_out: int

source

The width the mixer’s input projection produces.

mamba_intermediate_size​

property mamba_intermediate_size: int

source

The mixer’s width, from the head count and the head width.

mamba_layer_indices​

property mamba_layer_indices: list[int]

source

The indices of the layers whose mixer is Mamba-2.

mamba_num_heads​

mamba_num_heads: int

source

mamba_proj_bias​

mamba_proj_bias: bool = False

source

max_seq_len​

max_seq_len: int

source

mlp_bias​

mlp_bias: bool = False

source

mlp_hidden_act​

mlp_hidden_act: str = 'relu2'

source

moe_intermediate_size​

moe_intermediate_size: int = 0

source

moe_shared_expert_intermediate_size​

moe_shared_expert_intermediate_size: int = 0

source

n_groups​

n_groups: int

source

norm_topk_prob​

norm_topk_prob: bool = True

source

num_attention_heads​

num_attention_heads: int

source

num_experts​

num_experts: int = 0

source

num_experts_per_tok​

num_experts_per_tok: int = 0

source

num_hidden_layers​

num_hidden_layers: int

source

num_key_value_heads​

num_key_value_heads: int

source

populate_fp8_layers()​

populate_fp8_layers(state_dict)

source

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

source

The per-tensor static FP8 scheme of the FP8 layers, from the checkpoint (finalize()).

quantization_encoding​

quantization_encoding: SupportedEncoding | None = None

source

return_logits​

return_logits: ReturnLogits = 'last_token'

source

routed_scaling_factor​

routed_scaling_factor: float = 1.0

source

ssm_state_size​

ssm_state_size: int

source

tie_word_embeddings​

tie_word_embeddings: bool = False

source

time_step_limit​

time_step_limit: tuple[float, float] = (0.0, inf)

source

use_conv_bias​

use_conv_bias: bool = True

source

vocab_size​

vocab_size: int

source