Skip to content

AWQ: DeepSeek-VL2 scale-search replay crashes (root rotary called without required seq_len) #6631

Done

Description

@Qubitium

Bug

AWQ quantization of DeepSeek-VL2 (deepseek_vl_v2) crashes in the scale-search replay on any device:

File "gptqmodel/looper/awq_processor.py", line 6582, in _prepare_module_forward
File "gptqmodel/looper/awq_processor.py", line 6725, in _build_position_embeddings
TypeError: DeepseekV2RotaryEmbedding.forward() missing 1 required positional argument: 'seq_len'

Reproduced on origin/main 44aa0f9, CPU, tiny random-init model from the test helpers.

Cause

AWQProcessor._prepare_module_forward rebuilds position_embeddings with the decoder's root rotary
(_resolve_root_rotary finds language.model.rotary_emb through _scan_root_rotary) and calls it as
rotary(x, position_ids). The DeepSeek-VL2 port's DeepseekV2RotaryEmbedding.forward(x, position_ids, seq_len)
(gptqmodel/models/ports/deepseek_vl_v2/modeling_deepseek.py:86) requires a third positional seq_len, which
DeepseekV2Model.forward computes as max(past + length, int(position_ids.max()) + 1) (line 502). The replay
never passes it, so every attention replay raises a TypeError that the scale-group fallback does not catch.

Repro

import json, sys, torch
from pathlib import Path
sys.path.insert(0, "tests")
from test_deepseek_vl_v2_local_port import tiny_config, tokenizer_fixture
from gptqmodel import BACKEND, CalibrationConfig, GPTQModel
from gptqmodel.models.definitions.deepseek_vl_v2 import DeepSeekVLV2QModel
from gptqmodel.models.ports.deepseek_vl_v2.modeling_deepseek_vl_v2 import DeepseekVLV2ForCausalLM
from gptqmodel.quantization.config import AWQConfig

work = Path("/tmp/dsvl2_tiny"); work.mkdir(exist_ok=True)
torch.manual_seed(0)
model = DeepseekVLV2ForCausalLM(tiny_config()).eval(); model.save_pretrained(work)
tok = tokenizer_fixture(work)
(work / "processor_config.json").write_text(json.dumps({"mask_prompt": False}))
DeepSeekVLV2QModel.loader.load_processor(work, config=model.config, tokenizer=tok).save_pretrained(work)
q = GPTQModel.load(str(work), quantize_config=AWQConfig(bits=4, group_size=16, offload_to_disk=False, device="cpu"),
                   dtype=torch.float32, trust_remote_code=False)
rows = [[{"role": "<|User|>", "content": "hello world"}, {"role": "<|Assistant|>", "content": "hello world"}]] * 8
q.quantize(CalibrationConfig(dataset=rows, batch_size=1, min_length=1), backend=BACKEND.TORCH)  # TypeError

Suggested fix direction

Make the replay call the root rotary with the arguments its forward requires. That could mean a declared
replay hook on the definition (awq_module_replay_inputs), or a generic rule that passes seq_len when the rotary
signature requires it, using the same value the native model forward computes. A rotary the replay cannot call
should be reported through the unsupported-replay path (_AWQScaleGroupError), not raised as a bare TypeError.

Related: this rotary is also stateless (no parameters or buffers), so on CUDA it would hit the stateless-rotary
CPU placement bug fixed in the phi4mm PR (fix/phi4mm-awq-cuda-rotary).

Found while fixing the phi4mm AWQ CUDA rotary crash.

Activity

  1. added a commit that references this issue on Dec 1, 2026
    5444368
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