Repository navigation
feat(w4a16): load-time compressed-tensors to AWQ normalization - #5159
Open
windreamer wants to merge 8 commits into
Open
windreamer wants to merge 8 commits into
windreamer wants to merge 8 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/c2-ct-normalize
branch
from
November 18, 2026 12:06
f403e9f to
24591b5
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
Unresolved critical defects break valid compressed-tensors checkpoint loading, regress group-32 expert-parallel execution, and cause test collection to fail without the TurboMind extension.
7 open issues
Limit the FP16 override to group-128 checkpoints · New Pass module prefixes to dense builders for ignore rules · New Drop weight_shape metadata from normalized checkpoints · New Guard TurboMind-dependent imports in CPU-only tests · New Preserve staging across update buckets · New Preserve normalization state across checkpoint shards · New Enable eager mode for the reference pipeline · New
What changed in this PR
Adds load-time conversion of group-128 compressed-tensors checkpoints into canonical AWQ layout, enabling dense W4A16 models to use TurboMind GEMM kernels within the PyTorch engine without offline conversion.
Changes:
- Adds packed-weight conversion utilities and group-128 AWQ dispatch.
- Integrates normalization into initial, draft, memory-model, and hot-update loading paths.
- Adds deterministic checkpoint fixtures, conversion tests, and engine-level parity checks.
| File | Description |
|---|---|
tests/turbomind/tiny_ct.py |
Generates seeded compressed-tensors checkpoint fixtures. |
tests/turbomind/test_ct_repack.py |
Tests packing order, exact conversion, and fixture determinism. |
tests/turbomind/test_ct_load_normalize.py |
Tests key normalization, staging order, and incomplete inputs. |
tests/pytorch/engine/test_w4a16_golden_gate.py |
Adds conversion, hot-update, weight-spill, and graph parity checks. |
lmdeploy/turbomind/ct_repack.py |
Implements compressed-tensors-to-AWQ conversion utilities. |
lmdeploy/pytorch/weight_loader/model_weight_loader.py |
Adds staged normalization to checkpoint loading. |
lmdeploy/pytorch/spec_decode/proposers/base.py |
Enables normalization when loading draft models. |
lmdeploy/pytorch/memdecode/agent.py |
Enables normalization when loading memory models. |
lmdeploy/pytorch/engine/model_agent/agent.py |
Integrates normalization into initial loading and hot updates. |
lmdeploy/pytorch/config.py |
Accepts group 128 and adjusts quantization dispatch and dtype selection. |
Review effort: Balanced
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
2 times, most recently
from
November 19, 2026 05:03
a473a90 to
8cf6d79
Compare
This was referenced Nov 19, 2026
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 19, 2026 09:36
8cf6d79 to
6b0223f
Compare
This was referenced Nov 19, 2026
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 20, 2026 05:15
6b0223f to
ce96f94
Compare
This was referenced Nov 20, 2026
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 23, 2026 02:09
ce96f94 to
022038f
Compare
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 23, 2026 11:01
022038f to
264ff42
Compare
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 25, 2026 03:43
264ff42 to
b94472e
Compare
qescccczmr
reviewed
Nov 25, 2026
- Group-128 compressed-tensors dense checkpoints normalize to the canonical AWQ layout at load time (ct_repack), so the TurboMind W4A16 channel serves them without an offline conversion step. - The normalization is opt-in per load entry point - initial, draft, memdecode, hot-update buckets and update_params - gated on quant method == compressed-tensors with group size 128, so fp8-static weight_scale parameters and group-32 packed ct keys (MoE experts) pass through untouched. - ct_to_awq allocates on the source device, keeping CUDA hot-update streams intact. - The compressed-tensors dispatch sends group-128 dense linears to the awq family; group 32 keeps the packed ct modules. Hot-update buckets flow through the same translation on all update paths. - Tests: ct->AWQ round-trip and staging-order unit tests, a seeded tiny ct checkpoint generator, and engine-level gates (conversion, TM route, spill, hot-update A-B-A roundtrip, CUDA-graph replay) sourced from one public AWQ checkpoint via HF/ModelScope.
…across shards Force fp16 only for compressed-tensors checkpoints whose group_size is 128: those normalize into the fp16 AWQ family. Group-32 packed-ct keeps its configured dtype, restoring bf16 (and DeepEP) deployments the blanket force broke. Let normalize_ct_weights carry staging across calls through a shared state so a linear whose weight_packed/weight_scale split across safetensors shards converts instead of failing checkpoint-integrity validation; load_model_weights spans one state over all shards and finalizes after the loop. The single-call contract is unchanged. Guard the group_size extraction against malformed config_groups so a broken checkpoint fails with the parser's ValueError instead of an AttributeError before it can raise.
…nd gate the eager reference Validate and consume per-linear weight_shape metadata during ct normalization instead of forwarding it: AWQ modules have no such parameter and real llm-compressor exports carry it. The tiny HF fixture now includes the metadata so the load path is covered. Keep one ct staging state per update transaction: a module split across update buckets no longer fails with an incomplete-shard error, staged tensors clone their storage so reused IPC buffers cannot corrupt them, and _finalize_updated_weights validates leftovers and resets the state. Move the pure-torch AWQ unpack helpers into ct_repack so test collection and awq_dequant work on installations without the TurboMind extension; weight_format re-exports them. Run the golden gate reference pipeline with eager_mode instead of clearing capture batch sizes, which merely restored default capture sizes and kept the graph runner active. Update the weight-update test fixtures to the current agent contract (model_config and ct staging state).
e49a262 authored test_tiny_ct_spills_packed_torch_weights asserting the pre-CPU-direct spill contract (empty qweight, _spill resident) against a base that had already collapsed the dense route to CPU-direct packing — GitHub Actions unit_test red at every stack head since. Renamed to test_tiny_ct_keeps_torch_weights_cpu_resident: the packed quant storages (qweight/scales) stay host-resident WITH data as the CPU-direct pack source (mod.cpu_resident, device.type == 'cpu', numel != 0); the TM channel holds the packed copy; CUDA parameter bytes remain > 0. No dependence on spill internals.
…eometry - normalize_ct records each converted prefix's expected (out, k) at conversion and checks trailing weight_shape metadata against it instead of silently dropping it (PR 5159 review thread 4691049178). - Regression: two-order parametrized test — the same malformed metadata is rejected whether it arrives before or after the packed tensors.
…ders - LlamaAttention/LlamaMLP/LlamaDecoderLayer/LlamaForCausalLM thread module prefixes into the linear builders so compressed-tensors ignore rules are evaluated per real projection; group-128 CT + ignore=['lm_head'] now constructs (PR 5159 Copilot thread 4613769723, reviewer reply 4691049610). - Regression: construction tests for the ignore-list model and exact-rule exclusions of o_proj / down_proj.
… key
- lm_head's module prefix is 'lm_head' (compressed-tensors rules match by exact
equality; 'model.lm_head' can never match) — audit note N1 on PR 5159.
- Test pins the exact-match contract: get_quant_method('lm_head') is None while
'model.lm_head' stays quantized under ignore=['lm_head'].
windreamer
force-pushed
the
stack/c2-ct-normalize
branch
from
November 25, 2026 08:53
b94472e to
c18bbdb
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 compressed-tensors group-128 dense checkpoints: they normalize to the canonical AWQ layout in memory at load time, so the TM W4A16 channel (PR 1) serves them without an offline conversion step.
Modification
ct_repack: in-memory compressed-tensors → canonical AWQ conversion (round-trip err = 0 against the packed reference).normalize_quantgate on the load entry points (initial/draft/memdecode/hot-update): compressed-tensors streams normalize; fp8-staticweight_scaleparams and group-32 ct keys pass through untouched.BC-breaking
None. Additive; non-ct and group-32 ct checkpoints behave exactly as before (one deliberate relax: prefix-less ct linear builds, previously rejected, now build when no ignore rules — required by the group-128 feature).
Use cases
compressed-tensors group-128 W4A16 models (e.g. llm-compressor output) run on the TM W4A16 channel with zero offline conversion.
Checklist
normalize_ctat this layer; generalized tonormalize_quantin PR 3).