For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Python module
max.pipelines.architectures.laguna
LagunaConfigβ
class max.pipelines.architectures.laguna.LagunaConfig(*, 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, lora_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, num_local_experts=256, num_experts_per_tok=8, moe_intermediate_size=512, shared_expert_intermediate_size=512, moe_routed_scaling_factor=2.5, moe_router_logit_softcapping=0.0, norm_topk_prob=True, correction_bias_dtype=None, gate_dtype=None, attn_dtype=None, ep_config=None, mlp_layer_types=None, intermediate_size_dense=8192, partial_rotary_factor=0.5, gating=True)
Bases: Llama3Config
Configuration for Laguna decoder-only MoE models.
Extends Llama3Config with Laguna-specific fields:
- Uniform GQA: 64 query / 8 KV heads, full causal attention, a single
RoPE table (
rope_theta+partial_rotary_factor; M.1 is full-rotary, 1.0). - Per-layer MLP type:
mlp_layer_typesisdense(the dense prefix) orsparse(the rest). The decoder block dispatches between the dense MLP and the sparse MoE block. - Sigmoid + correction-bias routing: not softmax. See
LagunaTopKRouterfor the per-token routing math. - Routed scaling factor + shared experts + softplus attention output gate: applied per token / per element as Laguna requires.
-
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)
- lora_config (LoRAConfig | 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)
- num_local_experts (int)
- num_experts_per_tok (int)
- moe_intermediate_size (int)
- shared_expert_intermediate_size (int)
- moe_routed_scaling_factor (float)
- moe_router_logit_softcapping (float)
- norm_topk_prob (bool)
- correction_bias_dtype (DType | None)
- gate_dtype (DType | None)
- attn_dtype (DType | None)
- ep_config (EPConfig | None)
- mlp_layer_types (list[str] | None)
- intermediate_size_dense (int)
- partial_rotary_factor (float)
- gating (bool)
attn_dtypeβ
Data type for attention weights. Detected from state dict during finalize().
calculate_attention_multiplier()β
static calculate_attention_multiplier(huggingface_config)
Computes the attention multiplier from the configβs head_dim.
-
Parameters:
-
huggingface_config (AutoConfig) β The HuggingFace configuration object.
-
Returns:
-
The attention multiplier value.
-
Return type:
construct_kv_params()β
static construct_kv_params(huggingface_config, pipeline_config, devices, kv_cache_config, cache_dtype)
Constructs KV cache parameters using explicit head_dim from config.
-
Parameters:
-
- huggingface_config (AutoConfig) β The HuggingFace configuration object.
- pipeline_config (PipelineConfig) β The MAX Engine pipeline configuration.
- devices (list[DeviceRef]) β Devices to use for the KV cache.
- kv_cache_config (KVCacheConfig) β Configuration for KV cache.
- cache_dtype (DType) β Data type for the cache.
-
Returns:
-
KVCacheParams object with the correct head_dim from config.
-
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 routed-expert gate Linear. Detected from state dict during finalize().
gatingβ
gating: bool = True
When True, attention applies softplus(g_proj(hidden)) * attn_out per-head before o_proj. g_proj.out_features = num_heads (one scalar per head); broadcast over head_dim.
Always True for poolside/Laguna-M.1-NVFP4.
initialize()β
classmethod initialize(pipeline_config, model_config=None)
Initializes a LagunaConfig from pipeline configuration.
-
Parameters:
-
- pipeline_config (PipelineConfig) β The MAX Engine pipeline configuration.
- model_config (MAXModelConfig | None)
-
Returns:
-
An initialized LagunaConfig instance.
-
Return type:
initialize_from_config()β
classmethod initialize_from_config(pipeline_config, huggingface_config, model_config=None)
Initializes a LagunaConfig 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.
-
Returns:
-
An initialized LagunaConfig instance.
-
Return type:
intermediate_size_denseβ
intermediate_size_dense: int = 8192
Intermediate dim of the dense-layer MLPs (the one or more layers
where mlp_layer_types[i] == "dense"). Distinct from
intermediate_size (which Llama3Config uses for the active
branch) and from moe_intermediate_size.
mlp_layer_typesβ
Per-layer MLP type. Each entry is "dense" or "sparse".
Length equals num_hidden_layers. Typically layer 0 is dense
and the rest are sparse MoE.
moe_intermediate_sizeβ
moe_intermediate_size: int = 512
Per-expert intermediate dim (each routed expert is a SwiGLU MLP with this intermediate size).
moe_routed_scaling_factorβ
moe_routed_scaling_factor: float = 2.5
Scalar applied to routed-expert output before adding the shared expert output. Laguna-specific (default 1.0 in donors that have it at all).
moe_router_logit_softcappingβ
moe_router_logit_softcapping: float = 0.0
If > 0, router logits are passed through
softcap * tanh(logits/softcap) before sigmoid. Disabled (0.0)
for poolside/Laguna-M.1-NVFP4.
norm_topk_probβ
norm_topk_prob: bool = True
Whether to L1-normalise the selected top-k routing weights so they sum to 1. True for Laguna (matches HF reference).
num_experts_per_tokβ
num_experts_per_tok: int = 8
Top-k experts selected per token.
num_local_expertsβ
num_local_experts: int = 256
Number of routed experts per sparse layer.
partial_rotary_factorβ
partial_rotary_factor: float = 0.5
Fraction of head_dim used for rotary embeddings, read from the HF
config. poolside/Laguna-M.1-NVFP4 is full-rotary (1.0).
shared_expert_intermediate_sizeβ
shared_expert_intermediate_size: int = 512
Intermediate dim of the always-on shared expert MLP added alongside the routed-expert output (sum, not gated).
LagunaModelβ
class max.pipelines.architectures.laguna.LagunaModel(pipeline_config, session, devices, kv_cache_config, weights, adapter=None, return_logits=ReturnLogits.LAST_TOKEN, return_hidden_states=ReturnHiddenStates.NONE)
Bases: AlwaysSignalBuffersMixin, LlamaModelBase
Laguna 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)
- adapter (WeightsAdapter | None)
- return_logits (ReturnLogits)
- return_hidden_states (ReturnHiddenStates)
attention_biasβ
attention_bias: bool = False
Whether to use attention bias.
estimate_activation_memory()β
classmethod estimate_activation_memory(pipeline_config, huggingface_config)
-
Parameters:
-
- pipeline_config (PipelineConfig)
- huggingface_config (AutoConfig)
-
Return type:
load_model()β
load_model(session)
-
Parameters:
-
session (InferenceSession)
-
Return type:
modelβ
model: Model
Compiled and initialized model ready for inference.
model_config_clsβ
model_config_cls
alias of LagunaConfig
norm_methodβ
norm_method: Literal['rms_norm'] | Literal['layer_norm'] = 'rms_norm'
Normalization layer.
state_dictβ
Weights to load into the model.
LagunaReasoningParserβ
class max.pipelines.architectures.laguna.LagunaReasoningParser(think_start_token_id, think_end_token_id, tool_call_start_token_id=None)
Bases: ReasoningParser
Laguna reasoning parser for spans framed by <think> and </think>.
Reasoning may begin implicitly, without an explicit <think> token
(the chat template appends <think> to the assistant turn), and may end
implicitly when a tool call begins.
-
Parameters:
from_tokenizer()β
async classmethod from_tokenizer(tokenizer)
Constructs 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)
Identifies 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 the tool-call opener β 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.
LagunaToolParserβ
class max.pipelines.architectures.laguna.LagunaToolParser
Bases: object
Parser for Laguna <tool_call> blocks.
Streaming is emitted at per-call granularity: each complete
<tool_call>...</tool_call> block produces one delta carrying the
function name and the full JSON arguments. That is coarser than per-token
but still valid for OpenAI-style clients, which concatenate argument
fragments back into a JSON string.
parse_complete()β
parse_complete(response)
Parses a complete model response into tool calls.
-
Parameters:
-
response (str)
-
Return type:
parse_delta()β
parse_delta(delta)
Processes one decoded-token delta incrementally.
Buffers until a full <tool_call>...</tool_call> block is available,
then emits it as a single tool-call delta. Content before the first
block is forwarded; structural text between/after blocks is suppressed.
-
Parameters:
-
delta (str)
-
Return type:
-
list[ParsedToolCallDelta] | None
reset()β
reset()
Resets internal state for a new streaming session.
-
Return type:
-
None
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!