Skip to content

[BUG] AWQ crashes on DeepSeek-V4 (KeyError: 'sliding_attention'): scale-search rotary is called with the architecture layer_type instead of V4's rope_layer_type ('main'/'compress') #4695

Closed

Description

@Qubitium

Found on main @ 12c1273, AMD R9700 (ROCm 10.1).

What is wrong

AWQ crashes on every DeepSeek-V4 checkpoint in the first scale search. GPTQ on the same model completes.

AWQProcessor._prepare_module_forward (looper/awq_processor.py:4016) rebuilds position_embeddings with rotary(x, pos, **self._rotary_layer_type_kwargs(rotary, module)). _rotary_layer_type_kwargs (:4071-4109) passes the module's architecture layer_type ("sliding_attention", "compressed_sparse_attention", "heavily_compressed_attention").

DeepSeek-V4 deliberately decouples rotary types from architecture types. DeepseekV4RotaryEmbedding.layer_types comes from config.rope_parameters (["main", "compress"]), and the attention selects with self.rope_layer_type = "main" if self.layer_type == "sliding_attention" else "compress" (modeling_deepseek_v4.py:774). So the rotary indexes self.rope_type[layer_type] with an architecture name and raises:

  File "gptqmodel/looper/awq_processor.py", line 2598, in _quantize_layer
  File "gptqmodel/looper/awq_processor.py", line 3051, in _search_best_scale
  File "gptqmodel/looper/awq_processor.py", line 4016, in _prepare_module_forward
    module_kwargs["position_embeddings"] = rotary(
  File ".../transformers/modeling_rope_utils.py", line 122, in wrapper
    rope_type = self.rope_type if layer_type is None else self.rope_type[layer_type]
KeyError: 'sliding_attention'

Repro

Uses the real DeepSeek-V4-Flash config (the 3-layer DeepSeek-V4-Flash-3L-BF16 config.json: layer_types = ['sliding_attention', 'sliding_attention', 'compressed_sparse_attention'], rope_parameters keys ['main', 'compress']). Only n_routed_experts is changed (8), to make it small. Random init.

cfg = AutoConfig.from_pretrained("DeepSeek-V4-Flash-3L-BF16", n_routed_experts=8, num_experts_per_tok=2)
AutoModelForCausalLM.from_config(cfg).to(torch.bfloat16).save_pretrained(D)   # + tokenizer
m = GPTQModel.load(D, AWQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
m.quantize(c4_rows, batch_size=1)    # KeyError: 'sliding_attention'
m = GPTQModel.load(D, GPTQConfig(bits=4, group_size=128), dtype=torch.bfloat16)
m.quantize(c4_rows, batch_size=1)    # completes

A tiny AutoConfig.for_model("deepseek_v4") model fails the same way, with KeyError: 'heavily_compressed_attention'.

Suggested fix

In _rotary_layer_type_kwargs, prefer the attention's own rotary selector when it has one (rope_layer_type). More generally, only pass a value that is a key of the rotary's rope_type/layer_types mapping, and otherwise fall back to the captured position_embeddings. DeepSeek-V4 attention computes its own rotary from position_ids, so it may not need AWQ to synthesize position_embeddings at all.

Test that should have caught it

tests/test_awq_scaling_groups.py builds deepseek_v4 groups but never runs _search_best_scale. An AWQ quantize smoke test on a tiny deepseek_v4 config (seconds on CPU/GPU) would hit this immediately.

Severity

High for DeepSeek-V4 / V4-Flash / V4-Pro users: AWQ cannot quantize the family at all.

🤖 Generated with Claude Code

Activity

  1. ZX-ModelCloud commented on Nov 17, 2026

    @ZX-ModelCloud
    Collaborator

    Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.

  2. added a commit that references this issue on Nov 18, 2026
    5de4c7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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