Skip to content

fix(modelopt): expand is_layer_excluded for fused and model.-prefixed names - #36761

Open
chakshu-dhannawat wants to merge 1 commit into
sgl-project:mainfrom
chakshu-dhannawat:fix/modelopt-is-layer-excluded
Open

chakshu-dhannawat wants to merge 1 commit into
sgl-project:mainfrom
chakshu-dhannawat:fix/modelopt-is-layer-excluded

Conversation

@chakshu-dhannawat

@chakshu-dhannawat chakshu-dhannawat commented Aug 28, 2026

Copy link
Copy Markdown

This PR fixes the ModelOptQuantConfig.is_layer_excluded matcher so mixed-precision ModelOpt FP4/FP8 checkpoints correctly honor their exclusion lists when SGLang builds fused modules or renames model.visual.* to visual.* during load (reported in #36596).

Changes:

  • python/sglang/srt/layers/quantization/modelopt_quant.py:
    • Expand a prefix through packed_modules_mapping before matching, so an exclude entry like *.self_attn.q_proj also matches a built qkv_proj.
    • Also test model.-prefixed variants of every candidate prefix, so model.visual.* exclusions still match after the vision tower is renamed to visual.*.
  • test/registered/unit/layers/quantization/test_modelopt_nvfp4.py: add TestModelOptIsLayerExcluded covering exact match, language_model. prefix stripping, fused-module expansion, model.visual/visual renaming, and wildcard patterns.

The new unit tests pass:

python -m pytest test/registered/unit/layers/quantization/test_modelopt_nvfp4.py::TestModelOptIsLayerExcluded -v

All existing tests in test_modelopt_nvfp4.py still pass, and ruff check --select=F401,F821,UP037 and black are clean on the changed files.


CI States

Latest PR Test (Base): ❌ Run #33132248773
Latest PR Test (Extra): ❌ Run #33132248698
Latest PR Test (AMD ROCm 7.2): ❌ Run #33132248727

… names

ModelOpt FP4/FP8 mixed-precision checkpoints list excluded modules by unfused projection names (e.g. q_proj) or model.visual.* prefixes, but is_layer_excluded only matched the literal prefix. Expand the candidate set using packed_modules_mapping and also test model.-prefixed variants so fused modules and vision towers are correctly excluded.

Fixes sgl-project#36596
@github-actions github-actions Bot added quant LLM Quantization blackwell SM100/SM120 labels Aug 28, 2026
divyvasal added a commit to divyvasal/sglang that referenced this pull request Sep 10, 2026
ModelOpt writes some vision-language checkpoints with the decoder nested under
`model.language_model.*` while sglang builds it as `model.*`. The strip in
`apply_weight_name_mapper` only fires for a *leading* `language_model.`, so an
interior one never matches: every layer the checkpoint keeps in BF16 is built as
an FP4 module and the load dies on a shape mismatch.

Seen on nvidia/GLM-5.3-Flash-NVFP4, whose exclusion list is written as
`model.language_model.layers.N.self_attn*`, `...mlp.gate` and
`...mlp.shared_experts*`. With TP8 on 8xB200 the first mismatch is:

    AssertionError: target.shape=torch.Size([4096, 256]),
                    loaded_weight.shape=torch.Size([4096, 512])

the FP4-packed parameter against the BF16 tensor the checkpoint actually ships.

Expand the interior form alongside the existing leading-strip, at the same point
and in the same shape. Names without the segment are untouched, and the
expansion is exact rather than a wildcard, so it cannot widen a match: layer 10's
gate stays excluded while layer 11's is not.

This is the decoder half of sgl-project#36596. sgl-project#36761 covers the fused-module and
`model.`-prefixed vision-tower halves on the prefix side; the two are orthogonal
and touch different functions. On this checkpoint neither alone is sufficient:
sgl-project#36761 fixes `visual.*`, this fixes `model.layers.*`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant