Skip to content

Fix: Zero point underflow in AWQ Exllama v2 kernel - #2351

Merged
Qubitium merged 3 commits into
ModelCloud:mainfrom
12345txy:fix/exllamav2-zero-point-negative-value
Jan 12, 2026
Merged

Qubitium merged 3 commits into
ModelCloud:mainfrom
12345txy:fix/exllamav2-zero-point-negative-value

Conversation

@12345txy

Copy link
Copy Markdown
Contributor

Fix: Zero Point Calculation Error in unpack_reorder_pack for ExLlamaV2 AWQ Asymmetric Quantization

Description

Fixes a critical bug in unpack_reorder_pack function where zero_point values of 0 are incorrectly handled when using ExLlamaV2 kernel with AWQ asymmetric quantization.

Problem

When izeros=0, the operation izeros = izeros - 1 results in -1. The negative value is incorrectly processed in pack_exllama, causing zero_point to incorrectly change from 0 to 15. This leads to:

  1. 57,276 zero_point values incorrectly changed (across 48 layers)
  2. Wrong dequantization: weight = (qweight - zero_point_wrong) * scale
  3. NaN/Inf in model outputs: Wrong weights lead to NaN or Inf values in logits
  4. NaN in PPL calculation: NaN logits propagate to loss and perplexity calculations

Root Cause

In packing_utils.py:85, when izeros=0:

  • izeros - 1 becomes -1 (negative value)
  • The negative value -1 (0xFFFFFFFF) is incorrectly handled in pack_exllama:
    • When taking the lower 4 bits, -1 & 0xF = 15 (0xF)
    • This causes zero_point to incorrectly change from 0 to 15

Causal Chain:

izeros - 1 (when izeros=0) 
→ -1 (negative value) 
→ pack_exllama incorrectly processes as 15 
→ zero_point changes from 0 to 15 
→ wrong dequantization 
→ wrong weights 
→ NaN/Inf in logits 
→ NaN in loss 
→ NaN in PPL

Solution

Replace izeros = izeros - 1 with izeros = torch.where(izeros > 0, izeros - 1, izeros) to avoid negative values when izeros=0.

Changes

File: gptqmodel/quantization/awq/utils/packing_utils.py
Function: unpack_reorder_pack()
Line: 85

Before:

# Subtract 1 from the izeros tensor (exllama adds 1 during inference)
# We can remove it if we remove the +1 in the exllama code
izeros = izeros - 1

After:

# Subtract 1 from the izeros tensor (exllama adds 1 during inference)
# We can remove it if we remove the +1 in the exllama code
# Fix: Avoid negative values when izeros=0
# When izeros=0, subtracting 1 would result in -1, which is incorrectly
# packed as 15 in pack_exllama, causing zero_point calculation errors.
# Only subtract 1 when izeros > 0 to avoid this issue.
izeros = torch.where(izeros > 0, izeros - 1, izeros)

Testing

Verification Steps

  1. Quantize a model with AWQ asymmetric quantization (sym=False)
  2. Load the model with ExLlamaV2 kernel
  3. Run perplexity evaluation - should not produce NaN
  4. Verify zero_point values are correctly preserved

Test Results

After applying the fix:

  • ✅ Zero_point values of 0 remain 0 (no longer incorrectly changed to 15)
  • ✅ No negative values are produced
  • ✅ Dequantization is correct
  • ✅ Model outputs do not contain NaN/Inf
  • ✅ PPL calculation produces valid results

@Qubitium Qubitium changed the title Fix: Zero point calculation error in unpack_reorder_pack for ExLlamaV2 AWQ asymmetric quantization Fix: Zero point underflow in AWQ Exllama v2 kernel Jan 12, 2026
@Qubitium
Qubitium merged commit dcae9cf into ModelCloud:main Jan 12, 2026
@Qubitium

Copy link
Copy Markdown
Collaborator

@12345txy Thank for the bug fix. We have confirmed this bug and verified the fix.

@Qubitium

Copy link
Copy Markdown
Collaborator

New/comprehensive fix is in: #2352

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants