Skip to content

[Fix] awq: Match modules_to_not_convert against a fused layer's shards - #52304

Merged
BBuf merged 13 commits into
sgl-project:mainfrom
koladefaj:fix/awq-fused-not-convert
Nov 28, 2026
Merged

BBuf merged 13 commits into
sgl-project:mainfrom
koladefaj:fix/awq-fused-not-convert

Conversation

@koladefaj

@koladefaj koladefaj commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Fixes #52208. Same root cause in compressed-tensors: #52209, fixed in #52305.

is_layer_skipped_awq checked each modules_to_not_convert entry as a plain substring of the layer prefix. AWQ checkpoints list the checkpoint's unfused shards (self_attn.q_proj, self_attn.k_proj, self_attn.v_proj), and none of them is a substring of SGLang's fused self_attn.qkv_proj. So QuantTrio/Qwen3.6-27B-AWQ and QuantTrio/Qwen3.5-27B-AWQ build their full-attention qkv_proj as AWQ while the checkpoint stores those shards dense:

Modifications

  • is_layer_skipped_awq keeps the substring match on the layer itself, and otherwise resolves the fused layer's shards with resolve_dynamic_fused_shards (the model's packed_modules_mapping, then the shared fallback table) and matches each shard. All listed: unquantized. None: quantized. Some: ValueError, since that checkpoint cannot load correctly either way.
  • Its arguments are now keyword-only and it takes the quant config. All 7 in-tree call sites (AWQConfig, AWQCPUConfig, AWQMarlinConfig, NPU branch) are updated.
  • AWQConfig.from_config and AWQMarlinConfig.from_config read packed_modules_mapping from the config dict (the loader already puts it there, as for fp8 / gptq), so the model's own fused names reach the check, including the Marlin and MoeWNA16 fallbacks that rebuild from full_config.
  • Tests: a new TestIsLayerSkippedAWQ in test_is_layer_skipped.py, using the real QuantTrio list. The new cases fail on 448764da63 and pass with this change.

Notes for review:

  • A direct substring match on the fused name still wins before the shard check (existing behavior, e.g. linear_attn.in_proj_b matching in_proj_ba).
  • The fallback table is _DYNAMIC_FUSED_SHARDS, so the GDN in_proj_qkvz / in_proj_ba are expanded too, as GPTQ already does. For this checkpoint in_proj_ba hits the direct match and in_proj_qkvz has no listed shard, so both behave as before.
  • GPTQ has the same shard-agreement shape (is_checkpoint_module_unquantized, get_dynamic_override); I left sharing a helper with it out of this PR.

Accuracy Tests

RTX A40 (SM86), main 448764da63 with and without this change applied, QuantTrio/Qwen3.6-27B-AWQ. GSM8K: sgl-eval 0.1.3, 200 examples, --num-threads 64 --max-tokens 4096 --temperature 0.7 --top-p 0.8 --chat-template-kwarg enable_thinking=false. --dtype bfloat16 because the checkpoint is fp16 and fp16 GDN serving hits a separate crash at the first prefill (#31719, fix in #36289).

Build Load GSM8K
main ValueError: Incompatible dense checkpoint shard ...qkv_proj -
this PR ok 96.50%

Earlier runs on the same GPU: v0.5.23 scored 0.00%, and main with self_attn.qkv_proj appended to modules_to_not_convert through --json-model-override-args scored 98.00%. The only code change since those GPU runs is a comment rewrap.

main
$ PYTHONPATH=<main @ 448764da63>/python python3 -m sglang.launch_server --model-path QuantTrio/Qwen3.6-27B-AWQ --port 30000 --mem-fraction-static 0.85 --context-length 8192 --dtype bfloat16
[2026-11-22 05:38:54 PID507] Load weight begin. avail mem=44.10 GB
Multi-thread loading shards:  12% Completed | 1/8 [00:00<00:02,  2.60it/s][2026-11-22 05:38:54 PID507] Scheduler hit an exception: Traceback (most recent call last):
  File "/root/main/python/sglang/srt/managers/scheduler.py", line 7256, in run_scheduler_process
    scheduler = Scheduler(server_args, port_args)
  File "/root/main/python/sglang/srt/managers/scheduler.py", line 639, in __init__
    self.init_model_worker()
  File "/root/main/python/sglang/srt/managers/scheduler.py", line 1212, in init_model_worker
    self.init_tp_model_worker()
  File "/root/main/python/sglang/srt/managers/scheduler.py", line 1115, in init_tp_model_worker
    self.tp_worker = TpModelWorker(**worker_kwargs)
  File "/root/main/python/sglang/srt/managers/tp_worker.py", line 322, in __init__
    self._init_model_runner()
  File "/root/main/python/sglang/srt/managers/tp_worker.py", line 490, in _init_model_runner
    self._model_runner = ModelRunner(
  File "/root/main/python/sglang/srt/model_executor/model_runner.py", line 537, in __init__
    self.initialize()
  File "/root/main/python/sglang/srt/model_executor/model_runner.py", line 753, in initialize
    self.load_model()
  File "/root/main/python/sglang/srt/model_executor/model_runner.py", line 1411, in load_model
    loaded = load_model_with_memory_saver(
  File "/root/main/python/sglang/srt/model_executor/model_runner_components/load_model_utils.py", line 440, in load_model_with_memory_saver
    model = loader.load_model(
  File "/root/main/python/sglang/srt/model_loader/loader.py", line 1073, in load_model
    self.load_weights_and_postprocess(
  File "/root/main/python/sglang/srt/model_loader/loader.py", line 1082, in load_weights_and_postprocess
    DefaultModelLoader.load_weights_only(model, weights, target_device)
  File "/root/main/python/sglang/srt/model_loader/loader.py", line 1116, in load_weights_only
    model.load_weights(weights)
  File "/root/main/python/sglang/srt/models/qwen3_5.py", line 2529, in load_weights
    validate_quant_param_compatibility(name, params_dict)
  File "/root/main/python/sglang/srt/layers/quantization/utils.py", line 450, in validate_quant_param_compatibility
    raise ValueError(
ValueError: Incompatible dense checkpoint shard 'model.layers.11.qkv_proj.weight' cannot be loaded into quantized layer 'model.layers.11.qkv_proj'.
[2026-11-22 05:38:54] Received sigquit from a child process. It usually means the child failed.
this PR
$ PYTHONPATH=<main @ 448764da63 + this PR>/python python3 -m sglang.launch_server --model-path QuantTrio/Qwen3.6-27B-AWQ --port 30000 --mem-fraction-static 0.85 --context-length 8192 --dtype bfloat16
[2026-11-22 05:39:41 PID955] Load weight begin. avail mem=44.10 GB
[2026-11-22 05:39:53 PID955] Load weight end. elapsed=11.94 s, type=Qwen3_5ForConditionalGeneration, quant=awq, bits=4, avail mem=24.24 GB, mem usage=19.86 GB.
[2026-11-22 05:46:14] The server is fired up and ready to roll!
sample (temperature 0): 'The capital of France is Paris, and 17 multiplied by 23 equals 391.'
$ sgl-eval run gsm8k --base-url http://127.0.0.1:30000/v1 --num-examples 200 --num-threads 64 --max-tokens 4096 --temperature 0.7 --top-p 0.8 --chat-template-kwarg enable_thinking=false
* score                =  96.50%

Speed Tests and Profiling

Not affected: the change runs once per layer at model construction.

Checklist


CI States

Latest PR Test (Base): ✅ Run #45949452126
Latest PR Test (Extra): ⊘ Skipped -- add the run-ci-nv-extra label to opt in.
Latest PR Test (AMD ROCm 10): ⚠️ Run #45949454042

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] A few things to fix before this can go in.

…on shard-name matches

Addresses review: Qwen2.5-VL vision attn.qkv_proj is one tensor (not in its mapping), Whisper v_proj matching kv_proj must check K, Gemma 4 attention_k_eq_v layers have no v_proj.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] A few things to fix before this can go in.

@koladefaj

Copy link
Copy Markdown
Contributor Author

ab600ec also fixes three things I found while reviewing this round:

  • Router entries: mlp.gate / gate matched inside gate_proj and raised on dense MLPs (GLM-4-MoE, DeepSeek shared experts). Shard matching now has to end on a module boundary, which also stops model.layers.1 from matching model.layers.12.
  • Partial model mappings: a declared mapping no longer disables the fallback. DeepSeek-V3 declares only fused_qkv_a_proj_with_mqa, and LFM2-MoE declares only gate_up_proj, so their remaining fused layers still expand through _FALLBACK_FUSED_SHARDS. A fused name is kept as one tensor only when the model scopes it to some other path, which is the Qwen2.5-VL vision case. This now follows the same rule as [Fix] compressed-tensors: Expand fused layers in the ignore list without a packed_modules_mapping #52305.
  • Gemma3n's leading-dot keys (".qkv_proj": [".q_proj", ...]) are normalised.

Tests: test_router_entry_does_not_split_gate_up_proj, test_layer_entry_does_not_reach_later_layers, test_partial_model_mapping_keeps_the_fallback, test_leading_dot_mapping_keys_are_leaf_names.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] A few things to fix before this can go in.

@koladefaj

Copy link
Copy Markdown
Contributor Author

@BBuf Thanks, all four 02:28 findings reproduce on ab600ecb1e:

  • w8a8_fp8: W8A8Fp8Config has no packed_modules_mapping, so _declare_k_eq_v_qkv_shards raises AttributeError.
  • moe_wna16: it builds a fresh AWQConfig.from_config(full_config) per layer, so the Gemma 4 K=V update is lost.
  • Bailing: the linear-attention qkv_proj is one packed query_key_value tensor, but the fallback splits it into q/k/v.
  • ChatGLM: the module-boundary matching I added breaks mlp.dense_. AutoAWQ skips modules by plain substring, so that should be reverted.

Each of these comes from the same root cause: AWQ guesses from packed_modules_mapping how each fused layer is stored, and every model stores some of them differently. Before patching them one by one, I'd like to check a different approach with you.

GPTQ already reads this from the checkpoint itself: _CheckpointTensorManifest in gptq.py (#38854) classifies each module as dense (.weight) or quantized (.qweight) from the safetensors index. AWQ uses the same qweight convention, so it could reuse the manifest:

  • Qwen2.5-VL vision attn.qkv, Bailing query_key_value and ChatGLM dense_h_to_4h are classified directly from the checkpoint.
  • Gemma 4 K=V gives dense q_proj/k_proj and no v_proj, so the layer is dense, with no model-side registration. That removes the w8a8_fp8 and moe_wna16 problems.
  • Whisper and partial lists still raise on genuinely mixed shards.
  • When no manifest is available, modules_to_not_convert with plain substring matching stays as the fallback.

That would revert the Qwen2.5-VL and Gemma 4 model edits and keep the change in awq.py, moe_wna16.py and the tests. Would you be OK with that direction for this PR, or would you rather I keep the mapping approach and fix the four cases individually?

@BBuf

BBuf commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] @koladefaj BBuf, do you prefer switching AWQ to the checkpoint manifest in this PR or fixing the four cases in the current mapping? The manifest approach still needs to handle Gemma 4’s missing V explicitly, since the GPTQ resolver only returns dense when every expected shard is present and dense.

@BBuf

BBuf commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Let's fix the four cases in the current mapping in this PR (including reverting the module-boundary matching for ChatGLM) and leave the switch to the checkpoint manifest for a follow-up.

… moe_wna16, declare Bailing's query_key_value, substring-match self-mapped layers

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] A few things to fix before this can go in.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] One thing to fix before this can go in.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BBuf Review Agent] One thing to fix before this can go in.

Comment thread python/sglang/srt/models/llama.py Resolved
@koladefaj

Copy link
Copy Markdown
Contributor Author

Merged the latest main (c7be2a0) into the branch in edf65e1. There were no conflicts, and the PR's diff against main is unchanged. The AWQ and Quark unit tests pass on the merged head (test_is_layer_skipped.py, test_quark_config.py: 83 passed), and CI is now running on edf65e1.

@BBuf

BBuf commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions

Copy link
Copy Markdown
Contributor

✅ Approved by BBuf: CI runs on edf65e1.

@github-actions

This comment has been minimized.

@BBuf

BBuf commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions

Copy link
Copy Markdown
Contributor

✅ Approved by BBuf: CI runs on dfdab18.

@koladefaj

Copy link
Copy Markdown
Contributor Author

The base-a-test-cpu (4) failure on both PRs came from main, not from these changes. test_gdn_chunk_output_dispatch.py raised NameError: name 'is_batch_invariant_mode_enabled' is not defined. #44194 added that call to chunk_fwd_o, and the test runs the function in a hand-built namespace. Main fixed the test in #52843 an hour after I merged main into these branches.

I merged the latest main (f4284f2, which includes #52843) here in 29d6a38. There were no conflicts, and the PR's diff against main is unchanged. Locally the AWQ and Quark unit tests and the GDN test pass (84 passed), and ruff format and check are clean.

Could you /tag-and-rerun-ci this head? On timing: #52305 needs the same main merge, and the per-author limit only lets its Base run start about 120 minutes after this one. I'll hold #52305 until then.

@BBuf

BBuf commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions

Copy link
Copy Markdown
Contributor

✅ Approved by BBuf: CI runs on 29d6a38.

@BBuf

BBuf commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

1 similar comment
@BBuf

BBuf commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

…onvert

# Conflicts:
#	python/sglang/srt/layers/quantization/awq/awq.py
@koladefaj

koladefaj commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @BBuf, thanks for retrying CI. The run on 29d6a38 never got a GPU runner: all the GPU jobs sat waiting with no runner assigned and were cancelled at 03:02 UTC, so no tests ran. I then merged main (1ef18f0), which reset the approval, so Base now fails with "no run-ci approval". Could you /tag-and-rerun-ci again when you have a moment? I won't push to this branch until the run finishes.

#52305 is in the same state. Base allows one run per author every 2 hours, so it may be best to tag that one about 2 hours after this.

@sglang-bot

Copy link
Copy Markdown
Member

/tag-and-rerun-ci

@sglang-bot sglang-bot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[sglang-bot Review Agent] LGTM. Let's wait for CI.

@sglang-bot

Copy link
Copy Markdown
Member

/tag-and-rerun-ci

@sglang-bot

Copy link
Copy Markdown
Member

/rerun-failed-ci

@sglang-bot

Copy link
Copy Markdown
Member

[sglang-bot Review Agent] Could you merge the latest main into this branch? test/registered/unit/models/test_inkling2.py changed on main after this branch (2ef5a07 [CI] inkling2: Run the vision attention unit test eagerly on aarch64 hosts (#532), and a CI rerun replays the old code.

@sglang-bot

Copy link
Copy Markdown
Member

/tag-and-rerun-ci

@sglang-bot

Copy link
Copy Markdown
Member

/rerun-failed-ci

1 similar comment
@sglang-bot

Copy link
Copy Markdown
Member

/rerun-failed-ci

@koladefaj

Copy link
Copy Markdown
Contributor Author

@BBuf CI is green on the latest head (71e6c96), including the GB300 rerun. Ready to merge whenever you have a moment, along with #52305. Thanks for the reviews!

@BBuf
BBuf merged commit 1840464 into sgl-project:main Nov 28, 2026
211 of 227 checks passed
@koladefaj

Copy link
Copy Markdown
Contributor Author

@BBuf Filed the checkpoint-manifest follow-up we agreed on here as #53739. It has one open question on how to handle Gemma 4's missing v_proj (two options). I'd appreciate your preference before I start on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

3 participants