Skip to content

feat(w4a16): load-time compressed-tensors to AWQ normalization - #5159

Open
windreamer wants to merge 8 commits into
stack/c1-w4a16-densefrom
stack/c2-ct-normalize
Open

windreamer wants to merge 8 commits into
stack/c1-w4a16-densefrom
stack/c2-ct-normalize

Conversation

@windreamer

@windreamer windreamer commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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_quant gate on the load entry points (initial/draft/memdecode/hot-update): compressed-tensors streams normalize; fp8-static weight_scale params and group-32 ct keys pass through untouched.
  • Dispatch: group-128 compressed-tensors dense linears route to the awq family; group 32 keeps the packed ct modules.

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

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests: conversion round-trip and staging-order unit tests, a seeded tiny ct checkpoint generator, and engine-level gates (write + decode vs the bf16 reference); the memdecode build-model fake tracks the load-normalization kwarg this PR wires into the load entry points (normalize_ct at this layer; generalized to normalize_quant in PR 3).
  3. No new downstream dependencies.
  4. Docstrings updated accordingly.

@windreamer
windreamer added this pull request to stack #5162 November 18, 2026 11:01
@windreamer windreamer changed the title feat(w4a16): graft TurboMind W4A16 GEMM into the PyTorch engine feat(w4a16): load-time compressed-tensors to AWQ normalization Nov 18, 2026
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from f403e9f to 24591b5 Compare November 18, 2026 12:06
@windreamer
windreamer marked this pull request as ready for review November 18, 2026 12:10
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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
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

Comment thread lmdeploy/pytorch/config.py Resolved
Comment thread lmdeploy/pytorch/config.py Resolved
Comment thread tests/turbomind/test_ct_repack.py Resolved
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch 2 times, most recently from a473a90 to 8cf6d79 Compare November 19, 2026 05:03
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from 8cf6d79 to 6b0223f Compare November 19, 2026 09:36
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from 6b0223f to ce96f94 Compare November 20, 2026 05:15
@windreamer
windreamer removed this pull request from stack #5162 November 20, 2026 05:16
@windreamer
windreamer added this pull request to stack #5178 November 20, 2026 05:16
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from ce96f94 to 022038f Compare November 23, 2026 02:09
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from 022038f to 264ff42 Compare November 23, 2026 11:01
@windreamer
windreamer force-pushed the stack/c2-ct-normalize branch from 264ff42 to b94472e Compare November 25, 2026 03:43
windreamer and others added 8 commits November 25, 2026 15:03
- 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'].

This branch has not been deployed

No deployments
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.

3 participants