Layer input
×The residual features entering this layer.
- shape
- [B batch, T positions, 7168 d]
Sources
Contextual evidence from Token embedding
The token embedding looks up each ID’s row of the table (F.embedding); with one tensor-parallel shard it is a plain lookup.
vocab_parallel_embedding.py 85–525 ↗ · vllm-project/vllm @ 5df63a7203cd
Excerpt
def embedding(self, layer: torch.nn.Module, input_: torch.Tensor) -> torch.Tensor:
return F.embedding(input_, layer.weight)… lines 87–521 omitted …
def forward(self, input_):
"""Look up IDs, optionally reducing contributions from vocabulary shards."""
if self.tp_size == 1:
return self.quant_method.embedding(self, input_.long())The released configuration in Mistral’s own format: width 7,168, 61 layers, 128 heads (and 128 key–value heads), a dense MLP of 16,384, MLA ranks 1,536 (query) and 512 (key–value) with head widths 128 + 64 (query–key) and 128 (value); 128 routed experts of 4,096, 4 used, one shared expert, one expert group, route scale 1.0, the first 3 layers dense; 294,912 positions; YaRN with factor 36 over 8,192 original positions, β 32 and α 1, apply_scale false; llama_4_scaling with β 0.1 over 8,192 positions; RMSNorm ε 10⁻⁶; θ 10,000; untied embeddings; vocabulary 131,072; FP8 quantization; and a vision encoder.
params.json 1–116 ↗ · mistralai/Mistral-Large-3-675B-Instruct-2512 @ 383ffea2c7d6
Excerpt
{
"dim": 7168,
"head_dim": 192,
"hidden_dim": 16384,
"kv_lora_rank": 512,
"llama_4_scaling": {
"beta": 0.1,
"original_max_position_embeddings": 8192
},
"max_position_embeddings": 294912,
"moe": {
"expert_hidden_dim": 4096,
"expert_model_parallel": 1,
"expert_parallel": 1,
"first_k_dense_replace": 3,
"num_expert_groups": 1,
"num_expert_groups_per_tok": 1,
"num_experts": 128,
"num_experts_per_tok": 4,
"num_shared_experts": 1,
"route_every_n": 1,
"routed_scale": 1.0
},
"n_heads": 128,
"n_kv_heads": 128,
"n_layers": 61,
"norm_eps": 1e-06,
"q_lora_rank": 1536,
"qk_nope_head_dim": 128,
"qk_rope_head_dim": 64,
"quantization_config": {
"config_groups": {
"FP8_BLOCK": {
"format": "float-quantized",
"input_activations": {
"actorder": null,
"block_structure": null,
"dynamic": true,
"group_size": 128,
"num_bits": 8,
"observer": null,
"observer_kwargs": {},
"strategy": "group",
"symmetric": true,
"type": "float"
},
"output_activations": null,
"targets": [
"Linear"
],
"weights": {
"actorder": null,
"block_structure": [
128,
128
],
"dynamic": false,
"group_size": null,
"num_bits": 8,
"observer": "static_minmax",
"observer_kwargs": {},
"strategy": "block",
"symmetric": true,
"type": "float"
}
}
},
"format": "float-quantized",
"global_compression_ratio": null,
"ignore": [
"model.embed_tokens",
"re:patch_merger.*",
"re:vision_encoder.*",
"re:vision_language_adapter.*",
"re:.*kv_a_proj_with_mqa$",
"re:.*q_a_proj$",
"re:.*gate$",
"lm_head"
],
"kv_cache_scheme": null,
"quant_method": "compressed-tensors",
"quantization_status": "compressed",
"sparsity_config": {},
"transform_config": {},
"version": "0.12.3.dev29+g73c2cf9.d20251119"
},
"rope_theta": 10000.0,
"tied_embeddings": false,
"v_head_dim": 128,
"vision_encoder": {
"adapter_bias": false,
"add_pre_mm_projector_layer_norm": true,
"hidden_size": 1664,
"image_break_token_id": 12,
"image_end_token_id": 13,
"image_size": 1540,
"image_token_id": 10,
"intermediate_size": 8192,
"max_image_size": 1540,
"mm_projector_id": "patch_merge",
"num_attention_heads": 16,
"num_channels": 3,
"num_hidden_layers": 48,
"patch_size": 14,
"rope_theta": 10000.0,
"spatial_merge_size": 2
},
"vocab_size": 131072,
"yarn": {
"alpha": 1,
"apply_scale": false,
"beta": 32,
"factor": 36,
"original_max_position_embeddings": 8192
}
}Contextual evidence from Attention RMSNorm
RMSNorm normalizes in float32, casts to the gain’s type, multiplies by the gain and casts back; the fused form first adds the residual in float32 and returns the normalized sum and the sum, cast back to the input type.
layernorm.py 9–62 ↗ · vllm-project/vllm @ 5df63a7203cd
Excerpt
@register_op
def rms_norm(
x: Tensor, weight: Tensor | None, epsilon: float, variance_size: int | None = None
) -> Tensor:
"""Weighted root-mean-square layer normalization."""
orig_dtype = x.dtype
x = x.to(torch.float32)
x_var = x if variance_size is None else x[..., :variance_size]
variance = x_var.pow(2).mean(dim=-1, keepdim=True)
x = x * torch.rsqrt(variance + epsilon)
if weight is not None:
x = x.to(weight.dtype) * weight
return x.to(orig_dtype)… lines 22–42 omitted …
@register_op(allow_inplace=True)
def fused_add_rms_norm(
x: Tensor,
x_residual: Tensor,
weight: Tensor | None,
epsilon: float,
variance_size: int | None = None,
) -> tuple[Tensor, Tensor]:
"""Fused add and weighted root-mean-square layer normalization."""
orig_dtype = x.dtype
x = x.to(torch.float32)
x = x + x_residual.to(torch.float32)
x_residual = x.to(orig_dtype)
x_var = x if variance_size is None else x[..., :variance_size]
variance = x_var.pow(2).mean(dim=-1, keepdim=True)
x = x * torch.rsqrt(variance + epsilon)
if weight is not None:
x = x.to(weight.dtype) * weight
return x.to(orig_dtype), x_residualA layer is MoE when routed experts exist, its index is at least first_k_dense_replace and divisible by moe_layer_freq, dense otherwise; each layer has an input RMSNorm and a post-attention RMSNorm with the configuration’s ε; the forward pass normalizes, attends with the position factors, then adds the residual inside the post-attention norm, applies the MLP or MoE, and returns the update and the residual.
deepseek_v2.py 1293–1423 ↗ · vllm-project/vllm @ 5df63a7203cd
Excerpt
is_moe_layer = (
config.n_routed_experts is not None
and layer_idx >= config.first_k_dense_replace
and layer_idx % moe_layer_freq == 0
)… lines 1298–1328 omitted …
if is_moe_layer:
self.mlp = DeepseekV2MoE(
config=config,
parallel_config=parallel_config,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
# aiter applies routed_scaling_factor internally
apply_routed_scale_to_output=not rocm_aiter_ops.is_fused_moe_enabled(),
)
else:
self.mlp = DeepseekV2MLP(
hidden_size=config.hidden_size,
intermediate_size=config.intermediate_size,
hidden_act=config.hidden_act,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
)
self.input_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
self.post_attention_layernorm = RMSNorm(
config.hidden_size, eps=config.rms_norm_eps
)… lines 1350–1351 omitted …
def forward(
self,
positions: torch.Tensor,
hidden_states: torch.Tensor,
residual: torch.Tensor | None,
llama_4_scaling: torch.Tensor | None = None,
) -> torch.Tensor:
full_num_tokens = positions.shape[0]
input_is_sequence_parallel = (
self.use_sequence_parallel_moe
and residual is not None
and hidden_states.shape[0] != full_num_tokens
)
# Self Attention
if residual is None:
residual = hidden_states
hidden_states = self.input_layernorm(hidden_states)
else:
hidden_states, residual = self.input_layernorm(hidden_states, residual)
if input_is_sequence_parallel:
hidden_states = tensor_model_parallel_all_gather(hidden_states, 0)
hidden_states = hidden_states[:full_num_tokens]
if self.use_mha:
hidden_states = self.self_attn(positions, hidden_states)
else:
hidden_states = self.self_attn(positions, hidden_states, llama_4_scaling)
if (
not isinstance(self.self_attn, DeepseekAttention)
and hidden_states.dtype == torch.float16
):
# Fix FP16 overflow
# We scale both hidden_states and residual before
# rmsnorm, and rmsnorm result would not affect by scale.
hidden_states *= 1.0 / self.routed_scaling_factor
if self.layer_idx == 0:
# The residual is shared by all layers, we only scale it on
# first layer.
residual *= 1.0 / self.routed_scaling_factor
if self.use_sequence_parallel_moe:
tp_world_size = get_tensor_model_parallel_world_size()
# small trick using minus, eg. -17 % 8 = 7
sp_pad = (-hidden_states.shape[0]) % tp_world_size
# pad if not divisible by world size
hidden_states = torch.nn.functional.pad(hidden_states, (0, 0, 0, sp_pad))
hidden_states = tensor_model_parallel_reduce_scatter(hidden_states, 0)
if not input_is_sequence_parallel:
residual = sequence_parallel_chunk(residual)
# Fully Connected
hidden_states, residual = self.post_attention_layernorm(hidden_states, residual)
if self.use_sequence_parallel_moe:
hidden_states = self.mlp(
hidden_states,
already_sequence_parallel=True,
)
else:
hidden_states = self.mlp(hidden_states)
if isinstance(self.mlp, DeepseekV2MLP) and hidden_states.dtype == torch.float16:
# Fix FP16 overflow
# Scaling the DeepseekV2MLP output, it is the input of
# input_layernorm of next decoder layer.
# The scaling of DeepseekV2MOE output would be done in the forward
# of DeepseekV2MOE
hidden_states *= 1.0 / self.routed_scaling_factor
return hidden_states, residual