Repository navigation
fix(awq): derive the decoder seq_len for replay rotaries - #6641
Merged
Merged
Conversation
DeepSeek-VL2's root rotary is stateless and its forward requires the decoder's `seq_len`. AWQ's scale-search replay rebuilt position_embeddings with `rotary(x, position_ids)`, so every replayed attention raised `TypeError: ... missing 1 required positional argument: 'seq_len'` on CPU and CUDA. The native decoder computes `max(past + length, int(position_ids.max()) + 1)`. Resolve each rotary forward implementation's replay plan once (the parameter names plus the required arguments beyond `(x, position_ids)`), derive `seq_len` from the replayed positions for any rotary that requires it, and route other underivable required arguments through `_AWQScaleGroupError` so the configured plain-quantization fallback applies. `_refresh_forward_kwargs_from_cache` uses the same builder instead of calling the rotary directly. The end-to-end DeepSeek-VL2 regression asserts that every layer's q/k/v attention group produced a real AWQ scale-search loss (not the plain fallback) and that the rotary received the native `max(activation_length, max_position + 1)` value. A fallback-only variant fails that assertion. The MODEL_MAP scan found only DeepSeek-VL2 with a required third argument consumed by a `position_embeddings` attention. Baichuan, InternLM and Xverse also take `seq_len`, but compute it inside their attention forwards, which do not accept `position_embeddings`, so the replay never rebuilds them. Fixes #6631
Qubitium
force-pushed
the
fix/deepseek-vl2-awq-rotary-seq-len
branch
from
December 1, 2026 11:08
330b3bc to
5444368
Compare
Qubitium
marked this pull request as ready for review
December 1, 2026 11:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6631. DeepSeek-VL2 AWQ scale-search replay crashed on every device with
TypeError: DeepseekV2RotaryEmbedding.forward() missing 1 required positional argument: 'seq_len'.Root cause:
AWQProcessor._build_position_embeddingscalled the decoder's root rotary asrotary(x, position_ids). The vendored DeepSeek-VL2 rotary is stateless and its forwardrequires
seq_len; the native decoder computesseq_len = max(past + length, int(position_ids.max()) + 1)(gptqmodel/models/ports/deepseek_vl_v2/modeling_deepseek.py:502-503)and every decoder layer consumes the resulting
position_embeddings.Fix at the shared replay owner:
required arguments beyond
(x, position_ids)), not once per replay batch.seq_lenfrom the replayed positions for any rotary that requires it._AWQScaleGroupErrorfor any other required argument the replay cannot derive,so the configured plain-quantization fallback applies instead of a bare
TypeError._refresh_forward_kwargs_from_cachenow uses the same builder instead of calling therotary directly.
real AWQ scale-search loss (not the plain fallback) and that the rotary received the
native
max(activation_length, max_position + 1)value.The
MODEL_MAPscan found only DeepSeek-VL2 with a required third rotary argument consumedby a
position_embeddingsattention. Baichuan, InternLM and Xverse also takeseq_len, butcompute it inside their attention forwards, which do not accept
position_embeddings, sothe replay never rebuilds them. Transformers typed rotaries (
layer_type/attention_type)are unchanged.
What Changed
gptqmodel/looper/awq_processor.py: cached rotary replay-plan resolution, required-argumentderivation (
seq_len) and the unsupported-replay error path; refresh uses the same helper.tests/test_awq_rotary_device.py: focused regression for the nativeseq_lenformula,the unsupported-replay error, and once-per-implementation replay-plan resolution.
tests/test_deepseek_vl_v2_local_port.py: real tiny DeepSeek-VL2 AWQ quantization from thevendored port config on CPU, asserting the attention groups were scored and the rotary
received the derived
seq_len.No API or behavior change for rotaries whose forward only takes
(x, position_ids).Tests
Environment: GB10 (
sm_121), torch 2.15.0+cu132, transformers 5.23.0. CPU was used for thereplay regressions; the end-to-end DeepSeek-VL2 AWQ quantization was run on CPU and GB10.
Regression files, main (
e91673fc) vs branch (54443687):121 passed, 4 failed, 5 skipped. All four failures are the added tests: threeassert the fixed replay behavior (
TypeError: ... missing ... 'seq_len', theunderivable-argument path, and the end-to-end quantize), one asserts the new replay-plan
cache exists.
125 passed, 5 skipped.Focused red/green:
python -P -m pytest -q tests/test_awq_rotary_device.py -k "seq_len or underivable" python -P -m pytest -q tests/test_deepseek_vl_v2_local_port.py -k awq_quantize_tiny2 failedwithTypeError: _SeqLenTrackingRotary.forward() missing 1 required positional argument: 'seq_len'/_UnderivableRotary.forward() ... 'cache_position';the end-to-end DeepSeek-VL2 test fails with
TypeError: DeepseekV2RotaryEmbedding.forward() missing 1 required positional argument: 'seq_len'.13 passedfortest_awq_rotary_device.py; the end-to-end test passes.Fallback-only mutation check: temporarily making a required
seq_lenraise_AWQScaleGroupErrorletsquantize()finish but fails the end-to-end assertion withlayer 0 self_attn.q_proj used the plain quantization fallback instead of the AWQ scale search, so the test distinguishes a real fix from fallback masking.AWQ CPU baseline from the onboarding skill:
Result:
591 passed, 3 skipped(the skips are unavailable local DeciLM/EXAONE/Nanbeigefixtures).
Tiny DeepSeek-VL2 AWQ (the #6631 reproduction, widened only so the AWQ CPU kernel can pack
the tiny projections;
group_size=16, fp16, CPU):TypeError: DeepseekV2RotaryEmbedding.forward() missing 1 required positional argument: 'seq_len'.Seeded Qwen2.5-0.5B-Instruct AWQ A/B (CPU, 8 fixed calibration rows, bits=4, group_size=128):
config.jsonandquantize_config.jsonidentical.quant_log.csvdiffers only in the wall-clocktimecolumn; loss/sample columns match.bash format/check.sh:All checks passed!(ruff 0.14.2).Skipped and unverified:
test_variable_length_awq_runs_on_remote_family[decilm|exaone|nanbeige]: local fixturesunavailable on this host; their variable-length replay paths were not rerun.
test_tiny_qwen2_vl_quantizes_with_awq_and_gptq[awq|gptq]: local Qwen2-VL fixtureunavailable.
Measured Impact
Not a performance/accuracy change. The only measured effect is that the previously failing
DeepSeek-VL2 AWQ quantize now completes on CPU and GB10, and the Qwen2.5 A/B checkpoint is
bit-identical.
Model Support / Module Plan
Not applicable: no new model, alias or definition. The existing DeepSeek-VL2 module-plan
tests are included in the run above.
AWQ onboarding safety
DeepseekV2Model.forwardcomputesseq_len = max(past + length, int(position_ids.max()) + 1)and passesposition_embeddingsto every decoder layer;DeepseekV2Attention.forwardconsumes them.neutral-fold/candidate-search/rollback tests are included in the baseline run above.
quantize completes); the other layouts are unchanged.
argument now reaches the existing
_AWQScaleGroupErrorfallback contract.Logic Flow Documentation
Not applicable: this is a local call-convention fix inside the existing replay helper. It
does not change stages, source-of-decision, selection order, or tensor lifecycle. The new
branch only routes an underivable required argument through the existing fail-closed
_AWQScaleGroupErrorpath.Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, fusion or packing change.
Notes
The signature cache is keyed by the underlying
forwardfunction, so the per-device rotarycopies and every replay chunk reuse it. The
seq_lenderivation uses a host read of thereplayed positions only when the rotary actually requires
seq_len, matching the nativedecoder's formula.