Skip to content

vllm.model_executor.models.muse_glimmer

Inference-only MuseGlimmer multimodal model for vLLM.

Native port of the MuseGlimmer text decoder (MuseGlimmerForCausalLM). The text stack is a Gemma2 derivative with the following MuseGlimmer-specific deltas, each of which is handled explicitly here:

  • SiLU-gated MLP (hidden_activation="silu"), not Gemma's gelu-tanh.
  • Scaleless RMSNorm on the token embeddings (no sqrt(hidden) scaling).
  • Per-layer sandwich RMSNorms with a baked +1 weight offset (x * (1 + w)), matching Gemma, but with distinct eps for the pre/post norms (rms_norm_eps vs post_norm_eps).
  • QK-norm (weightless, fp32) applied before RoPE, followed by a query pre-scale of qk_scale_factor / sqrt(head_dim).
  • A per-head sigmoid attention output gate.
  • iRoPE layout: NoPE layers use full attention, RoPE layers use sliding window attention. RoPE is applied NEOX-style (is_neox_style=True): the HF converter (convert_muse_glimmer_weights_to_hf.py, 20260806+) permutes q/k into the half-split (NEOX) layout via _permute_for_rope so they pair with rotate_half — matching the reference's interleaved rotation on the native (unpermuted) weights. Serving the permuted HF weights with is_neox_style=False scrambles q/k and causes token-repetition collapse.
  • Final logits are pre-scaled by output_multiplier and then tanh soft-capped at final_logit_softcapping.
  • Untied lm_head.

The vision path supports variable-resolution images and temporally patched videos. It mirrors the checkpoint's native vision encoder, including sparse block attention, 2-D RoPE, pixel-shuffle downsampling, and the two-layer adapter/projection stack.

Classes:

MuseGlimmerImagePixelInputs

Bases: TensorSchema

Batched variable-resolution image inputs.

Source code in vllm/model_executor/models/muse_glimmer.py
class MuseGlimmerImagePixelInputs(TensorSchema):
    """Batched variable-resolution image inputs."""

    type: Literal["image_pixels"]
    pixel_values: Annotated[
        torch.Tensor | list[torch.Tensor],
        TensorShape("bn", 3, "h", "w", dynamic_dims={"h", "w"}),
    ]
    feature_sizes: Annotated[torch.Tensor, TensorShape("bn")]

MuseGlimmerRMSNorm

Bases: Module

RMSNorm mirroring HF MuseGlimmer exactly (fp32 compute, cast at the end).

normed = _norm(x.float()) * (w.float() + weight_offset) cast back to the input dtype. When with_scale is False the layer is weightless (used for QK-norm and the token-embedding norm).

Source code in vllm/model_executor/models/muse_glimmer.py
class MuseGlimmerRMSNorm(nn.Module):
    """RMSNorm mirroring HF MuseGlimmer exactly (fp32 compute, cast at the end).

    ``normed = _norm(x.float()) * (w.float() + weight_offset)`` cast back to the
    input dtype. When ``with_scale`` is False the layer is weightless (used for
    QK-norm and the token-embedding norm).
    """

    def __init__(
        self,
        dim: int | None = None,
        eps: float = 1e-6,
        with_scale: bool = True,
        weight_offset: int = 0,
    ) -> None:
        super().__init__()
        self.eps = eps
        self.with_scale = with_scale
        self.weight_offset = weight_offset
        if with_scale:
            assert dim is not None
            self.weight = nn.Parameter(torch.zeros(dim))
        else:
            self.register_parameter("weight", None)

    def _norm(self, x: torch.Tensor) -> torch.Tensor:
        return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)

    def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
        out = self._norm(hidden_states.float())
        if self.with_scale:
            out = out * (self.weight.float() + self.weight_offset)
        return out.type_as(hidden_states)

MuseGlimmerVideoPixelInputs

Bases: TensorSchema

Batched variable-length, variable-resolution video inputs.

Source code in vllm/model_executor/models/muse_glimmer.py
class MuseGlimmerVideoPixelInputs(TensorSchema):
    """Batched variable-length, variable-resolution video inputs."""

    type: Literal["video_pixels"]
    pixel_values: Annotated[
        torch.Tensor | list[torch.Tensor],
        TensorShape(
            "bn",
            "ng",
            "c",
            "h",
            "w",
            dynamic_dims={"ng", "h", "w"},
        ),
    ]
    feature_sizes: Annotated[torch.Tensor, TensorShape("bn")]

_muse_glimmer_query_prescale(config)

Post-QK-norm query pre-scale (scale_query_by), normalized across the two config schemas so the net query scaling matches the native reference.

HF native modeling computes scale_query_by = qk_scale_factor / sqrt(head_dim) where the NATIVE qk_scale_factor is the raw params.json value (~43.784). The modular HF text_config PRE-FOLDS the 1/sqrt(head_dim) factor and ships qk_scale_factor = 43.784 / sqrt(128) = 3.87 already, expecting it applied directly. Both must yield the SAME scale_query_by (~3.87), then softmax uses scaling = head_dim**-0.5.

Precedence
  1. explicit scale_query_by (already the final factor) -> use as-is.
  2. else derive from qk_scale_factor:
  3. if it is already the folded value (~= qk_scale_factor/sqrt(hd) is NOT what we want; detect the native form and divide) — we decide by magnitude: the native raw value is folded * sqrt(head_dim). If qk_scale_factor is close to folded_expected * sqrt(hd) we treat it as native and divide; otherwise it is already folded, use directly.
Source code in vllm/model_executor/models/muse_glimmer.py
def _muse_glimmer_query_prescale(config) -> float:
    """Post-QK-norm query pre-scale (``scale_query_by``), normalized across the
    two config schemas so the net query scaling matches the native reference.

    HF native modeling computes ``scale_query_by = qk_scale_factor / sqrt(head_dim)``
    where the NATIVE ``qk_scale_factor`` is the raw ``params.json`` value
    (~43.784). The modular HF ``text_config`` PRE-FOLDS the ``1/sqrt(head_dim)``
    factor and ships ``qk_scale_factor = 43.784 / sqrt(128) = 3.87`` already,
    expecting it applied directly. Both must yield the SAME ``scale_query_by``
    (~3.87), then softmax uses ``scaling = head_dim**-0.5``.

    Precedence:
      1. explicit ``scale_query_by`` (already the final factor) -> use as-is.
      2. else derive from ``qk_scale_factor``:
         - if it is already the folded value (``~= qk_scale_factor/sqrt(hd)`` is
           NOT what we want; detect the native form and divide) — we decide by
           magnitude: the native raw value is ``folded * sqrt(head_dim)``. If
           ``qk_scale_factor`` is close to ``folded_expected * sqrt(hd)`` we treat
           it as native and divide; otherwise it is already folded, use directly.
    """
    head_dim = config.head_dim
    sqrt_hd = head_dim**0.5

    explicit = getattr(config, "scale_query_by", None)
    if explicit is not None:
        return float(explicit)

    qk_scale = getattr(config, "qk_scale_factor", None)
    if qk_scale is None:
        # No scale info at all: fall back to the plain 1/sqrt(head_dim) identity
        # (net query scaling then just the softmax scaling); should not happen
        # for real MuseGlimmer checkpoints, which always carry qk_scale_factor.
        return 1.0

    qk_scale = float(qk_scale)
    # Disambiguate native (raw, ~43.78) vs modular (folded, ~3.87). The native
    # form, when divided by sqrt(head_dim), yields the folded target; the folded
    # form is already the target. Native values are ~sqrt(head_dim)x larger than
    # folded. Use a threshold at sqrt(head_dim) (with margin): if qk_scale is
    # comparable to or larger than sqrt(head_dim), it is the native raw value and
    # must be divided; otherwise it is already folded and used directly.
    #   head_dim=128 -> sqrt=11.31; native 43.78 > 11.31 (divide -> 3.87),
    #   folded 3.87 < 11.31 (use as-is).
    if qk_scale >= sqrt_hd:
        return qk_scale / sqrt_hd
    return qk_scale

_muse_glimmer_use_attn_output_gate(config)

Whether the per-head sigmoid attention output gate is applied. MuseGlimmer ALWAYS applies it; the modular HF text_config omits use_attn_output_gate (reads as None). Missing/None -> True; only explicit False disables.

Source code in vllm/model_executor/models/muse_glimmer.py
def _muse_glimmer_use_attn_output_gate(config) -> bool:
    """Whether the per-head sigmoid attention output gate is applied. MuseGlimmer ALWAYS
    applies it; the modular HF ``text_config`` omits ``use_attn_output_gate``
    (reads as ``None``). Missing/None -> True; only explicit ``False`` disables."""
    val = getattr(config, "use_attn_output_gate", None)
    return True if val is None else bool(val)

_muse_glimmer_use_qk_norm(config)

Whether QK-norm is applied. MuseGlimmer ALWAYS applies QK-norm; the modular HF text_config schema simply omits use_qk_norm (reads as None). Treat a missing/None flag as True — only an explicit False disables it.

Source code in vllm/model_executor/models/muse_glimmer.py
def _muse_glimmer_use_qk_norm(config) -> bool:
    """Whether QK-norm is applied. MuseGlimmer ALWAYS applies QK-norm; the modular HF
    ``text_config`` schema simply omits ``use_qk_norm`` (reads as ``None``).
    Treat a missing/None flag as True — only an explicit ``False`` disables it."""
    val = getattr(config, "use_qk_norm", None)
    return True if val is None else bool(val)

_text_config(config)

MuseGlimmer checkpoints may nest the text config under text_config (multimodal MuseGlimmerConfig) or expose it directly (MuseGlimmerTextConfig).

Source code in vllm/model_executor/models/muse_glimmer.py
def _text_config(config):
    """MuseGlimmer checkpoints may nest the text config under ``text_config``
    (multimodal ``MuseGlimmerConfig``) or expose it directly
    (``MuseGlimmerTextConfig``)."""
    return getattr(config, "text_config", config)