Skip to content

[BUG] Regression from #5019 (fix of #4891): AWQ with ExpertsRoutingBypass crashes on every MoE block ('SparseMoeBlock.forward() got an unexpected keyword argument position_ids'): the bypass wrapper's **kwargs makes _forward_accepts_var_kwargs pass all layer kwargs #5095

Closed

Description

@Qubitium

Found on main @ e75181d, RTX 4090 (1 GPU is enough), torch 2.15 + CUDA 13.2, transformers 5.22.

What is wrong

Since #5019 (fix of #4891), AWQ with MoEConfig(routing=ExpertsRoutingBypass()) crashes in layer 0 on standard MoE blocks:

TypeError: OlmoeSparseMoeBlock.forward() got an unexpected keyword argument 'position_ids'
TypeError: LinearQwen2MoeSparseMoeBlock.forward() got an unexpected keyword argument 'position_ids'
  awq_processor.py:4816 _iter_prepared_forward_outputs -> module(x, **module_kwargs)
  awq_processor.py:3346 all_experts_forward -> original_forward(hidden_states, **kwargs)

Cause:

  • For bypass routing, AWQ replaces the MoE block's forward with an instance-level wrapper all_experts_forward(hidden_states, **kwargs) (awq_processor.py:3313-3348).
  • fix(awq): replay a **kwargs block and fold the norm the layer owns (#4891) #5019 added _forward_accepts_var_kwargs (awq_processor.py:309). _sanitize_kwargs (:5100) and the position-id promotion (:4452) now treat any forward with a **kwargs catch-all as "accepts every layer kwarg" (needed for Hymba's HymbaBlock).
  • inspect.signature(moe_block.forward) now sees the wrapper's **kwargs. So the MoE block gets the whole decoder-layer kwargs (position_ids, attention_mask, position_embeddings, ...), and the wrapper forwards them to the original SparseMoeBlock.forward(hidden_states), which raises.

Before #5019, the name filter used the wrapper's signature too, but it kept only hidden_states, so nothing extra was forwarded.

Repro

olmoe2 = OLMoE-1B-7B-0924 with num_hidden_layers=2 (config copy, same weights). Qwen1.5-MoE-A2.7B (2 layers) fails the same way.

import json, gzip, torch
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization.config import AWQConfig, MoEConfig, ExpertsRoutingBypass
calib = [t for t in (json.loads(l)["text"][:1500] for l in gzip.open("c4-train.00000-of-01024.json.gz", "rt")) if len(t) >= 1000][:16]
m = GPTQModel.load("olmoe2", quantize_config=AWQConfig(bits=4, group_size=128, moe=MoEConfig(routing=ExpertsRoutingBypass())), dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=calib))
commit result
c060a9fc8 (= 7744cb898^, before #5019) OK, all 392 modules quantized, 1,817,856 expert rows captured
7744cb898 (#5019) .. e75181df5 (main) TypeError: OlmoeSparseMoeBlock.forward() got an unexpected keyword argument 'position_ids'

GPTQConfig with the same bypass routing, and AWQ with native routing, both quantize fine on main.

Suggested fix

  • Have the wrapper keep the block's real signature (functools.wraps(original_forward) sets __wrapped__, which inspect.signature follows) and call original_forward(hidden_states, **kwargs) only with the keys the original accepts.
  • Or let _forward_accepts_var_kwargs ignore the processor's own instance-level patch (look at type(module).forward instead of the bound instance attribute).

Test that should have caught it

tests/test_awq_moe_bypass_4223.py / tests/test_moe_bypass_batch_size.py should run the bypass path through _sanitize_kwargs with real layer kwargs (position_ids, attention_mask), for example on the tiny Qwen3-MoE fixture used by tests/test_dp_subset_early_stop_4904.py. The #5019 tests only cover Hymba's **kwargs block.

Severity

High for AWQ MoE users who use bypass routing (the documented way to give every expert calibration data): it is a hard crash on every standard MoE family since #5019. Native routing is unaffected.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Additional data from the full-suite triage on main @ 7b8f127.

    The existing test tests/test_awq_moe_bypass_4223.py::test_awq_bypass_replay_scales_every_expert already catches this regression. It is red on main on CPU-only, on RTX 4090 and on ROCm (R9700):

    E       TypeError: LinearQwen3MoeSparseMoeBlock.forward() got an unexpected keyword argument 'position_ids'
    

    I bisected it with the HEAD test on CPU over 3867c82af..7b8f12785. The first bad commit is 7744cb898 (#5019), which matches the root cause above. It passed at the previous full triage (3867c82af). (tests/test_moe_bypass_batch_size.py stays green, but it only covers config validation and never runs the bypass replay.)

    🤖 Generated with Claude Code

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-5095-awq-bypass is working on this issue now.

    Started 2026-11-18T05:37:24Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    claiming: fix the ExpertsRoutingBypass **kwargs detection so the bypass wrapper no longer forwards position_ids to SparseMoeBlock.forward

  3. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-root-5095-awq-bypass finished this issue.
    Pull request: #5142
    Fixed the #5019 regression by decorating AWQ's instance-level bypass replay wrapper with functools.wraps(original_forward), so inspect.signature reports the MoE block's real forward(hidden_states) instead of the wrapper's **kwargs; the wrapper now also forwards only keywords the original block declares. Hymba's genuine **kwargs block keeps the #4891 behavior. On the issue's 2-layer OLMoE-1B-7B-0924 + C4 repro, e2f9676 raises the reported TypeError and the PR quantizes 392 modules / 1,817,856 expert rows (pre-#5019 baseline). Added two regression tests and the mechanism diagrams in docs/moe-routing-override.md section 8.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions