Skip to content

fix(awq,qlinear): keep clip scratch splittable and bound pack_gpu transient (#4401) - #4437

Merged
Qubitium merged 2 commits into
mainfrom
fix/awq-pack-memory-4401
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/awq-pack-memory-4401

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Two remaining memory findings from #4401 (item 2, MACaQ dead copies, already shipped in #4431):

  1. AWQ clip-search scratch defeats the allocator split cap. scratch_prod is sized up to MSEConfig.resolve_budget_bytes (256 MiB default) and token_chunk floor-divides the budget, so many shapes request just under 256 MiB (e.g. 255.94 / 255.31 MiB). The caching allocator rounds that to a 256 MiB segment, which is >= max_split_size_mb, so a freed segment cannot serve the next sub-cap request: every clip-eligible module mallocs a fresh segment. fix: release the AWQ per-layer ROCm allocator cache (#4313) #4342 only releases at the layer boundary, so reserved VRAM grows with modules within a layer (OLMoE: 10.9 GiB reserved vs 2.3 allocated).
  2. pack_gpu transient is ~15x the fp16 weight. block_in=8192 covers the whole input dimension for most layers, so the fp32/int32/int64 packing chain holds ~32 bytes per element at once.

Addresses items 1 and 4 of #4401. Item 3 (QQQ/VPTQ/MACaQ/EXL3 sibling-Hessian dedup) remains open.

What Changed

  • _alloc_conf.py: allocator_max_split_bytes() / clamp_budget_below_allocator_split() read Torch's effective allocator settings (_accelerator_getAllocatorSettings, with the same env precedence Torch uses as a fallback) and clamp a budget to max_split - 2 MiB.
  • awq_processor.py: clamp the resolved clip budget below the split cap. Only chunk sizes change; clip bounds stay bitwise identical.
  • nn_modules/qlinear/__init__.py: PACK_GPU_MAX_BLOCK_ELEMS = 4M; pack_gpu derives block_in = min(requested, 4M // out_features) rounded to 32. Blocks partition the input axis into disjoint output rows, so packing stays bit-exact.
  • quantization/config.py: docstring note on the clamp.
  • Tests: CPU allocator model asserting reserved memory is flat within a MoE layer, GPU-derived block pinning against the CPU pack_block(block_in=8192) reference, and bit-exact packing tests.

Tests

PYTHONPATH=/root/work-4401b /root/venv/bin/python -m pytest \
  tests/test_pack_gpu_bit_exact.py tests/test_awq_rocm_layer_cache_4313.py \
  tests/test_alloc_conf.py tests/test_pack.py tests/test_awq_clip_consistency.py -q
123 passed, 4 subtests passed

PYTHONPATH=/root/work-4401b /root/venv/bin/python -m pytest \
  tests/test_awq_per_module_bits.py tests/test_awq_weight_mean.py -q
205 passed, 1 skipped
/root/venv/bin/python -m ruff check <changed files>
All checks passed!

Measured on the available NVIDIA GB10 with PYTORCH_ALLOC_CONF=max_split_size_mb:256 (real _compute_best_clip, 8-expert MoE shape): reserved after each expert projection was 276/532/788/.../2068 MiB before (+1792 growth) and flat at 274 MiB after; clip bounds bitwise equal. pack_gpu peak: 14336x4096 1659 -> 269 MiB, 8192x2048 474 -> 166 MiB, qweight/qzeros bitwise identical.

Not executed: actual ROCm hardware (none here); the split-cap path was reproduced on CUDA with the same allocator rules plus a CPU model. The AWQ CUDA JIT extension cannot build (CUDA_HOME absent), so the full AWQ end-to-end run was CPU-only.

Logic Flow Documentation

Not applicable — budget/block-size selection only; the clip search and packing outputs are bitwise unchanged and pinned by tests.

Review Requirements

  • Reviewed; reads allocator settings, no new env-var behavior switch.
  • Bit-exactness pinned for both changes.

…nsient (#4401)

Item 1: size the AWQ clip-search workspace below the active caching
allocator's max_split_size (2 MiB headroom) so a near-cap request does not
force a fresh segment per module. Within a MoE layer, reserved VRAM grew
~256 MiB per expert projection while allocated memory stayed flat; the
per-layer release from #4313 only bounded cross-layer growth. The clamp
only changes chunk sizes, so clip bounds stay bitwise identical.

Item 4: derive pack_gpu's input block from a 4 Mi-element budget
(out_features * block_in) instead of the whole-matrix 8192 default. The
fp32/int32/int64 packing chain peaked at ~14.8x the fp16 weight; the
derived block is bitwise identical because blocks only partition the input
axis into disjoint output rows.

Adds a CPU allocator model that asserts reserved memory is flat within a
MoE layer, and bit-exact packing tests against the old whole-matrix path.
Comment thread tests/test_pack_gpu_bit_exact.py Fixed
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