Repository navigation
feat(gptq): load-time GPTQ repack onto the AWQ path - #5160
Open
windreamer wants to merge 6 commits into
Open
windreamer wants to merge 6 commits into
windreamer wants to merge 6 commits into
Conversation
Collaborator
Author
|
This change is part of the following stack:
Change managed by git-spice. |
This was referenced Nov 18, 2026
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 18, 2026 12:06
276b744 to
747ae6a
Compare
windreamer
marked this pull request as ready for review
November 18, 2026 12:10
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical loading and conversion defects reject valid GPTQ checkpoints, mishandle sharded weights, ignored layers, and CUDA tensors, and produce AWQ exports with incompatible metadata and unsupported group-index tensors.
8 open issues
Honor ignore rules when GPTQ module prefixes are unavailable · New Accept sequential GPTQ g_idx buffers without enabling act-order · New Retain incomplete modules until the checkpoint stream is fully read · New Normalize components across all checkpoint shards · New Allocate repacked tensors on the input device · New Rewrite destination config metadata to AWQ · New Validate and omit GPTQ g_idx tensors from AWQ output · New Gather tensors across shards and update the output weight index · New
What changed in this PR
This PR adds load-time GPTQ-to-AWQ repacking so the PyTorch engine can serve GPTQ dense models through the existing W4A16 kernels without offline conversion.
Changes:
- Adds GPTQ packing, dequantization, verification, and offline conversion utilities.
- Routes GPTQ dense linears through AWQ and integrates normalization into model loading and weight updates.
- Adds CPU layout and validation tests plus CUDA kernel parity and routing tests.
| File | Description |
|---|---|
tests/pytorch/kernel/test_tm_gemm_gptq.py |
Tests CUDA kernel parity and supported-shape routing. |
tests/pytorch/kernel/test_gptq_repack.py |
Tests packing semantics, geometry checks, normalization, and dispatch. |
lmdeploy/turbomind/gptq_repack.py |
Implements GPTQ-to-AWQ conversion and reference utilities. |
lmdeploy/pytorch/weight_loader/model_weight_loader.py |
Adds GPTQ stream normalization to checkpoint loading. |
lmdeploy/pytorch/spec_decode/proposers/base.py |
Enables quantization normalization for draft-model loading. |
lmdeploy/pytorch/memdecode/agent.py |
Enables normalization for memory-model loading. |
lmdeploy/pytorch/engine/model_agent/agent.py |
Integrates normalization into initial loading and online updates. |
lmdeploy/pytorch/config.py |
Adds GPTQ configuration parsing, dtype handling, and dense-layer dispatch. |
Review effort: Balanced
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 18, 2026 13:15
747ae6a to
610935c
Compare
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 19, 2026 02:31
610935c to
ae5c5fd
Compare
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 19, 2026 05:03
ae5c5fd to
0c2ee8c
Compare
This was referenced Nov 19, 2026
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 19, 2026 09:36
0c2ee8c to
ef44f16
Compare
This was referenced Nov 19, 2026
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 20, 2026 05:15
ef44f16 to
b98f5ba
Compare
This was referenced Nov 20, 2026
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 23, 2026 02:09
b98f5ba to
a1006f4
Compare
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 23, 2026 11:01
a1006f4 to
f751f87
Compare
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 25, 2026 03:44
f751f87 to
3df196c
Compare
qescccczmr
reviewed
Nov 25, 2026
- GPTQ dense checkpoints repack to the canonical AWQ layout at load time (gptq_repack): pack axis, nibble order, and the zero-point offset are absorbed in-flight, so the AWQ and TurboMind W4A16 channels serve GPTQ without an offline conversion. - The repack rejects desc_act (act-order) checkpoints loudly and verifies geometry on demand with a synthesized symmetric zero reference. - GPTQ dispatches dense linears to the awq family and honors ignored modules; MoE keeps the raw method and fails loudly (no GPTQ MoE implementation). bits != 4 is rejected at parse. - The load-time repack gate is QuantizationConfig.load_normalize(), shared by the initial, draft, memdecode, and hot-update paths; fp8-static and group-32 ct keys pass through untouched. - Tests: repack round-trips and trap guards (nibble order, zero offset, geometry rejections, desc_act), kernel parity on CUDA, and config dispatch; the TM cross-check skips cleanly without a built extension.
… route MoE through AWQ Accept AutoGPTQ's identity group-index buffers: a non-decreasing consecutive g_idx is the default no-act-order export and is consumed; only a reordered mapping raises. desc_act is also rejected at config parse. Keep a staged GPTQ module until its components arrive instead of flushing on the next prefix: shard and bucket boundaries can interleave a module's tensors, and an early flush synthesized a wrong asymmetric pad. Allocate repacked outputs on the input device so hot-update IPC tensors do not mix CPU and CUDA operands, and gather quant components across all safetensors shards in convert_checkpoint: the converted output is a single model.safetensors with the quant config rewritten to AWQ and identity g_idx dropped. Route GPTQ MoE through the AWQ family like dense linears: normalize_gptq_weights covers expert prefixes, so grouped experts land on the same verified route as ct group-128.
…oad fake - c3 renamed the load-time normalization kwarg normalize_ct -> normalize_quant (d4fea0f); the fake fixed for the c2 signature went stale again from this branch up. - Follows the c2 fix (8cf6d79 pre-restack) which is still correct at its own layer; this commit adapts the same fake to the c3+ signature so the test stays green through c4/c5.
…shape, and pin the config.json match
Three defects from the C3 serial review:
- normalize_gptq_weights staged update-path tensors without cloning. Update buckets deliver views into a reused IPC buffer, so a module whose scales arrive in a later bucket converted from the buffer's stale contents - silent wrong weights on GPTQ hot updates. The ct normalizer already made this defensive copy; the gptq half now mirrors it.
- _gptq_sym_qzeros synthesized (g, n) instead of (g, n//8) int32 words, so gptq_to_awq(verify=True) crashed on exactly the symmetric-no-qzeros checkpoints the module documents as supported. Default loads were unaffected (verify=False).
- convert_checkpoint's fname.endswith('config.json') also rewrote tokenizer_config.json / generation_config.json, contradicting the byte-for-byte passthrough docstring. Basename pinned; passthrough regression-tested.
Regression tests: verify-accepts-synthesized-zeros, update-path buffer-reuse clone, sibling-config byte passthrough.
- checkpoint_format threads through gptq_to_awq/convert_shard and the load-time normalize stream: v1 applies the +1 offset, v2 keeps the stored symmetric zero; the nibble-overflow guard now evaluates after the format-correct offset and names the format (PR 5160 review thread 4691021304). - convert_checkpoint reads the source config.json format and drops the stale v2 marker from the output AWQ config; unknown checkpoint formats are rejected loudly at parse. - Regression: reviewer's symmetric case (all codes/zeros = 8, unit scales) dequantizes to zero through the full v2 path; first-principles mixed-zeros v2 reference; v1 offset pinned by a guard test.
- _finalize_updated_weights passes the transaction's checkpoint_format into finalize_gptq_weights instead of letting the leftover flush default to v1 while the shard streams used the parsed format (audit note N2 on PR 5160; unreachable today, consistency only).
windreamer
force-pushed
the
stack/c3-gptq-repack
branch
from
November 25, 2026 08:53
3df196c to
bb5c873
Compare
This branch has not been deployed
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.

Motivation
TurboMind's strongest-performing assets are its mixed-precision W4A16 GEMM kernels, but the TurboMind runtime is being retired in favor of the PyTorch engine. This stack grafts the W4A16 GEMM family into the PyTorch engine: weights are packed into TurboMind kernels at load time, forward runs on TurboMind kernels, and the PyTorch engine keeps owning scheduling, KV-cache management, and CUDA graphs.
This PR teaches the load path to serve GPTQ dense checkpoints: the GPTQ pack axis, nibble order, and zero-point offset are absorbed at load time, landing on the same canonical AWQ layout as PRs 1-2 — and GPTQ MoE checkpoints route through the same AWQ path (grouped-MoE specifics land in PR 4 and #5169).
Modification
gptq_repack+normalize_gptq_weights: GPTQ/AWQ pack discrimination is decisive (qwidth/scales relation); symmetric checkpoints synthesize the zero reference on flush.desc_act(act-order) checkpoints andbits != 4fail at parse/load with clear errors instead of deep inside kernels.update-path staging defensively clones tensors against IPC-buffer reuse (a module
whose scales arrive in a later bucket than its weights converted from stale buffer
contents — silent wrong weights on hot updates);
_gptq_sym_qzerossynthesizes thecorrect
(g, n//8)int32 word shape (verify=Truecrashed on exactly thesymmetric-no-qzeros checkpoints this module documents);
convert_checkpointrewrites only the exact
config.jsonbasename (sibling configs pass throughbyte-for-byte). Three regression tests pin all three.
BC-breaking
None. Additive; non-GPTQ checkpoints behave exactly as before.
Use cases
GPTQ W4A16 models (mainstream GPTQ exports without
desc_act) run on the TM W4A16 channel with zero offline conversion; GPTQ MoE checkpoints dispatch through the same path (grouped route in PR 4, full pipeline wiring in #5169).Checklist
normalize_quantrename this PR introduces.