Mistral Large 3

Compute query temperatures

×

One factor per position, from the position alone.

τt=1+0.1ln⁡(1+⌊t/8,192⌋){\htmlData{light=model-temperatures temperatures}{\tau_t}}=1+0.1\ln\big(1+\lfloor t/8{,}192\rfloor\big)
in
pp [T positions]
out
τ\tau [T positions]

vLLM computes the factors once per forward pass from the positions, when the configuration sets llama_4_scaling (deepseek_v2.py 445–452, 1531–1543), and hands them to every layer’s attention.

Explanation

tt is the position. τt=1\tau_t=1 for positions 0–8,191, 1.069 for 8,192–16,383, and one step higher every 8,192 positions: 1.358 at the last of the 294,912 positions.

Sources

In code_get_llama_4_scaling(original_max_position_embeddings=…, scaling_beta=…, positions=positions)

Open pinned code ↗

Direct evidence

Once per forward pass the model computes 1 + β·ln(1 + ⌊position / original_max_position_embeddings⌋) for every position from the configuration’s llama_4_scaling and hands it to every layer.

deepseek_v2.py 445–1571 ↗ · vllm-project/vllm @ 5df63a7203cd

Excerpt
def _get_llama_4_scaling(
    original_max_position_embeddings: int, scaling_beta: float, positions: torch.Tensor
) -> torch.Tensor:
    scaling = 1 + scaling_beta * torch.log(
        1 + torch.floor(positions / original_max_position_embeddings)
    )
    # Broadcast over num_heads and head_dim
    return scaling[..., None, None]

… lines 453–1530 omitted …

        # Compute llama 4 scaling once per forward pass if enabled
        llama_4_scaling_config = getattr(self.config, "llama_4_scaling", None)
        llama_4_scaling: torch.Tensor | None
        if llama_4_scaling_config is not None:
            llama_4_scaling = _get_llama_4_scaling(
                original_max_position_embeddings=llama_4_scaling_config[
                    "original_max_position_embeddings"
                ],
                scaling_beta=llama_4_scaling_config["beta"],
                positions=positions,
            )
        else:
            llama_4_scaling = None

… lines 1544–1568 omitted …

            hidden_states, residual = layer(
                positions, hidden_states, residual, llama_4_scaling
            )

vLLM’s adapter turns params.json into a DeepSeek-V3 configuration: a mixture of experts with shared experts is Mistral Large 3, run as MistralLarge3ForCausalLM with model_type deepseek_v3 and llama_4_scaling required; dim, n_layers, n_heads and hidden_dim become hidden_size, num_hidden_layers, num_attention_heads and intermediate_size; YaRN becomes rope_parameters of type yarn with mscale_all_dim 1, beta → beta_fast and alpha → beta_slow, and apply_scale false becomes attention_factor 1 (no magnitude correction); the MoE arguments are renamed and the adapter sets topk_method None, norm_topk_prob True and scoring_func softmax.

mistral.py 10–307 ↗ · vllm-project/vllm @ 5df63a7203cd

Excerpt


def adapt_config_dict(
    config_dict: dict[str, Any],
    defaults: dict[str, Any],
) -> PreTrainedConfig:
    config_dict = _remap_general_mistral_args(config_dict)
    config_dict = _remap_mistral_sliding_window(config_dict)

    if bool(config_dict.get("quantization")):
        config_dict = _remap_mistral_quantization_args(config_dict)

    is_mla = bool(config_dict.get("qk_nope_head_dim"))
    if is_mla:
        config_dict = _remap_mistral_mla_args(config_dict)

    is_moe = bool(config_dict.get("moe"))
    is_mistral_large_3 = (
        is_moe and (config_dict["moe"].get("num_shared_experts") or 0) > 0
    )
    if config_dict.get("model_type") == "mamba":
        config_dict["architectures"] = ["Mamba2ForCausalLM"]
    elif is_moe and is_mistral_large_3:
        config_dict = _remap_moe_args(config_dict)
        config_dict["model_type"] = "deepseek_v3"
        config_dict["architectures"] = ["MistralLarge3ForCausalLM"]

        assert "llama_4_scaling" in config_dict, (
            "MistralLarge3 expect llama4 scaling config."
        )
        llama_4_scaling_config_keys = ["original_max_position_embeddings", "beta"]
        assert all(
            [
                key in config_dict["llama_4_scaling"]
                for key in llama_4_scaling_config_keys
            ]
        ), (
            "llama_4_scaling config should define the keys: "
            f"{','.join(llama_4_scaling_config_keys)}"
        )
    elif is_moe:
        config_dict["architectures"] = ["MixtralForCausalLM"]
    else:
        config_dict["architectures"] = ["MistralForCausalLM"]

    if bool(config_dict.get("yarn")):
        config_dict = _remap_mistral_yarn_args(config_dict)

    if bool(config_dict.get("llama_4_scaling")):

… lines 59–113 omitted …

def _remap_mistral_yarn_args(config: dict) -> dict:
    yarn_config_map = {
        "factor": ("factor", float),
        "original_max_position_embeddings": ("original_max_position_embeddings", int),
        "beta": ("beta_fast", float),
        "alpha": ("beta_slow", float),
    }

    yarn_config = config.get("yarn") or {}
    config["rope_parameters"] = {
        "rope_type": "yarn",
        "mscale_all_dim": 1,
    }

    if rope_theta := config.pop("rope_theta", None):
        config["rope_parameters"]["rope_theta"] = rope_theta

    for old_name, (new_name, cast) in yarn_config_map.items():
        if old_name in yarn_config:
            # Cast to remove Transformers > v5 type warnings
            config["rope_parameters"][new_name] = cast(yarn_config.pop(old_name))

    # `apply_scale: false` means no magnitude correction, which Transformers
    # spells as an explicit attention_factor of 1.
    if not yarn_config.pop("apply_scale", True):
        config["rope_parameters"]["attention_factor"] = 1.0

    assert len(yarn_config) == 0, f"Unparsed yarn config: {yarn_config}"

    return config


def _remap_general_mistral_args(config: dict) -> dict:
    # Mistral key -> HF key
    config_mapping = {
        "dim": "hidden_size",
        "norm_eps": "rms_norm_eps",
        "n_kv_heads": "num_key_value_heads",
        "n_layers": "num_hidden_layers",
        "n_heads": "num_attention_heads",
        "hidden_dim": "intermediate_size",
    }
    # HF key -> (Mistral key, default value)
    top_level_mapping_with_default = {
        "model_type": ("model_type", "transformer"),
        "hidden_act": ("activation", "silu"),
        "tie_word_embeddings": ("tied_embeddings", False),
        "max_seq_len": ("max_seq_len", config.get("max_position_embeddings", 128_000)),
        "max_position_embeddings": ("max_position_embeddings", 128_000),
        "dtype": ("dtype", config.get("dtype")),
    }

    for key, new_key in config_mapping.items():
        if key in config:
            config[new_key] = config.pop(key)

    for new_key, (key, default_value) in top_level_mapping_with_default.items():
        config[new_key] = config.pop(key, default_value)

    return config

… lines 174–284 omitted …

def _remap_moe_args(config: dict) -> dict:
    moe_config_map = {
        "route_every_n": "moe_layer_freq",
        "first_k_dense_replace": "first_k_dense_replace",
        "num_experts_per_tok": "num_experts_per_tok",
        "num_experts": "n_routed_experts",
        "expert_hidden_dim": "moe_intermediate_size",
        "routed_scale": "routed_scaling_factor",
        "num_shared_experts": "n_shared_experts",
        "num_expert_groups": "n_group",
        "num_expert_groups_per_tok": "topk_group",
    }
    moe_config = config.get("moe", {})
    for old_name, new_name in moe_config_map.items():
        if old_name in moe_config:
            value = moe_config.pop(old_name)
            config[new_name] = value

    config["topk_method"] = None
    config["norm_topk_prob"] = True
    config["scoring_func"] = "softmax"

    return config