Skip to content

fix(qlinear): size GPTQ buffers by bits/pack_dtype_bits#2985

Merged
Qubitium merged 1 commit into
mainfrom
upstream-pack-dtype-bits-fix
Jul 26, 2026
Merged

fix(qlinear): size GPTQ buffers by bits/pack_dtype_bits#2985
Qubitium merged 1 commit into
mainfrom
upstream-pack-dtype-bits-fix

Conversation

@Qubitium

@Qubitium Qubitium commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

_register_gptq_buffers and PackableQuantLinear.pack_original sized packed qweight/qzeros with ceil(dim / pack_factor) (where pack_factor = pack_dtype_bits // bits) or, after the previous 3-bit fix, a hardcoded 32. Both are wrong when pack_dtype_bits does not equal 32 or when pack_dtype_bits / bits is not an integer (3-bit).

The correct number of packed words is ceil(dim * bits / pack_dtype_bits).

Changes

  • GPTQQuantLinear._register_gptq_buffers: qweight rows and qzeros columns now use math.ceil(dim * self.bits / self.pack_dtype_bits).
  • PackableQuantLinear.pack_original: qweight and qzeros allocation now uses math.ceil(dim * self.bits / self.pack_dtype_bits) instead of 32.

For 2/4/8-bit these formulas are equivalent to the old ceil(dim / pack_factor). For 3-bit (pack_dtype_bits == 32) this gives ceil(dim * 3 / 32), matching the 32-value packing loop and the pack_block/pack_gpu paths. For int8/int16 pack dtypes this no longer under-allocates the buffer.

Verification

  • ruff check gptqmodel/nn_modules/qlinear/__init__.py: passed
  • git diff --check: passed
  • pytest tests/test_pack.py tests/kernels/test_qlinear_hierarchy.py -q: 27 passed

…ck_factor or 32

The number of packed words is ceil(dim * bits / pack_dtype_bits), not ceil(dim / pack_factor).

- In _register_gptq_buffers, use in_features*bits/pack_dtype_bits and out_features*bits/pack_dtype_bits for qweight/qzeros rows/cols.

- In pack_original, use dim*bits/pack_dtype_bits for both qweight and qzeros.

This is equivalent to the previous pack_factor formula for 2/4/8-bit, and correct for 3-bit and non-32-bit pack dtypes (int8/int16).
@Qubitium Qubitium self-assigned this Jul 26, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@Qubitium
Qubitium merged commit 1c8020f into main Jul 26, 2026
6 checks passed
@Qubitium
Qubitium deleted the upstream-pack-dtype-bits-fix branch July 26, 2026 21:15
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.

1 participant