Repository navigation
fix(awq,qlinear): keep clip scratch splittable and bound pack_gpu transient (#4401) - #4437
Merged
Merged
Conversation
…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.
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.
Summary
Two remaining memory findings from #4401 (item 2, MACaQ dead copies, already shipped in #4431):
scratch_prodis sized up toMSEConfig.resolve_budget_bytes(256 MiB default) andtoken_chunkfloor-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).pack_gputransient is ~15x the fp16 weight.block_in=8192covers 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 tomax_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_gpuderivesblock_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.pack_block(block_in=8192)reference, and bit-exact packing tests.Tests
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_gpupeak: 14336x4096 1659 -> 269 MiB, 8192x2048 474 -> 166 MiB,qweight/qzerosbitwise 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_HOMEabsent), 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