Skip to content

[MEM] Quantize memory: ROCm AWQ clip scratch (~256 MiB) defeats max_split cap (OLMoE 10.9 GiB reserved vs 2.3 allocated), MACaQ keeps dead H/W copies through flip sweep (-17% peak), QQQ/VPTQ/MACaQ/EXL3 duplicate sibling Hessians, pack_gpu 15x transient #4401

Closed

Description

@Qubitium

Audit of main @ beb6db8 (first measured at 27c6b7b) on an R9700 (ROCm 10.1, gfx1201), with the import-time ROCm allocator default max_split_size_mb:256,garbage_collection_threshold:0.7. Items 2–4 are generic (not HIP-specific).

1. [ROCm] AWQ clip-search scratch defeats the 256 MiB split cap: reserved VRAM grows ~256 MiB per module within each layer (3× allocated on dense models, 10.9 GiB on MoE); #4342 is incomplete (medium)

looper/awq_processor.py:3103-3136 sizes scratch_prod up to MSEConfig.resolve_budget_bytes, which defaults to 256 MiB on GPU (quantization/config.py:1773). token_chunk floor-divides the budget, so for many shapes the request lands just under 256 MiB: Qwen2.5-0.5B q/k/v/o/down request 255.94 / 255.31 MiB, and OLMoE expert down_proj about 255 MiB. The caching allocator rounds the request up to a 256 MiB segment. That is ≥ max_split_size_mb (_alloc_conf.py:48), and a free oversize segment can't serve a sub-256 MiB request, so every clip-eligible module mallocs a fresh 256 MiB segment. #4342 empties the cache only at the layer boundary (quantization/awq/quantize/scale.py:133-174), so within a layer reserved grows with the number of modules: 64 experts × 3 projections on MoE.

Qwen2.5-0.5B awq4, 6 layers:   default budget      peak alloc 0.479 GiB  peak reserved 1.494 GiB
                               clip_grid_budget=250M peak alloc 0.473 GiB peak reserved 0.740 GiB
OLMoE-1B-7B awq4, 64 samples:  default             peak alloc 2.349 GiB  peak reserved 10.887 GiB (layer 0: reserved 1.72 -> 9.72 GiB in 4 s
                                                                         while allocated stays 0.79 GiB; 1 alloc retry; 263 hipMallocs by layer 1)
                               clip_grid_budget=250M peak alloc 2.344 GiB peak reserved 2.637 GiB (134 hipMallocs)
Llama-3.2-1B: requests are 250/240 MiB (under the cap) -> 1.746 vs 1.711 GiB, unaffected (shape-dependent)

Fix (any one):

  • On ROCm, clamp the clip budget to max_split - 2 MiB so segments stay splittable.
  • Allocate scratch_prod once per layer at max size and reuse it across modules/experts.
  • Release per module instead of per layer.

tests/test_awq_rocm_layer_cache_4313.py only mocks empty_cache; it needs a reserved-within-layer check on a MoE layer. Cross-layer growth (#4313) remains fixed, including bs=4.

2. MACaQ macaq_quantize_weight keeps the dead pre-scaled Hessian, rotated Hessian and pre-scaled weight alive through the flip sweep (medium-low)

After rotation, hessian and weight (the pre-scaled copies, quantization/macaq.py:543-544) are never read again. After flip_hessian = rotated_hessian.clone() (:557), rotated_hessian (:548-549) isn't read either, but all of them stay referenced until return. Together with the caller's H2, that's 4 C²-sized fp32 copies per module through the sweep, with all 7 modules of a layer running concurrently.

peak above inputs, current vs with `del hessian, weight` after rotation and `del rotated_hessian` after the clone:
  2048x8192 weight: 2098 -> 1522 MiB    8192x2048: 1378 -> 1282 MiB    packed output sha identical
Llama-3.2-1B macaq, 4 layers: peak allocated 5.025 -> 4.174 GiB (-17%), reserved 7.158 -> 6.746 GiB

At 8B, down_proj alone (C=14336, 784 MiB per copy) saves ~1.6 GiB per module. Fix: the two dels, or apply the pre-scale and ridge in place.

3. Shared-input Hessian dedup exists only in GPTQProcessor: QQQ, VPTQ (fp64), MACaQ and EXL3 accumulate identical Hessians for q/k/v and gate/up (low-medium)

The SharedInputPlan leader/follower path lives only in looper/gptq_processor.py:404-516. add_batch in quantization/qqq.py:558/640, vptq.py:309/332 and macaq.py:675/696 accumulates per module with no plan, and looper/exllamav3_processor.py:2158 builds plain GPTQ() capture tasks. Keying each add_batch input by pointer, shape and content:

Llama-3.2-1B, 2 layers: add_batch calls on an input another module already accumulated
  qqq4  1152 / 2688 (43%)  groups {(q,k,v): 384, (gate,up): 384}
  vptq  1152 / 2688        (fp64: k+v+up ~7.0 s of 48 s add_batch time)
  macaq  384 / 896
  exl3_4 1152 / 2688
  gptq4 (control) 0

That's 48 MiB (fp32) / 96 MiB (VPTQ fp64) of redundant Hessians per layer on 1B, and 192 / 384 MiB on 8B, plus the redundant accumulation matmuls. Fix: reuse GPTQProcessor's plan and Hessian adoption in these processors, avoiding the extra-C² adoption overhead of #4400 item 1. (GPTAQ/FOEM at bs>1 is #4391 item 4.)

4. pack_gpu (auto-selected whenever a GPU exists) packs the whole matrix in int64/fp32, a transient of ~15× the fp16 weight (low-medium)

nn_modules/qlinear/__init__.py:2227-2234 sets block_in=8192, which covers the whole input dimension for most layers. :2338-2362 then rounds in fp32, transposes in int32, converts .to(int64), shifts and sums, about 32 bytes per element live at once. utils/packing.py:99-111 auto-selects "gpu".

weight          fp16     peak block_in=8192   block_in=1024     (output identical)
14336x4096   112 MiB     1656 MiB (14.8x)      578 MiB (5.2x)    block_in=256: 253 MiB, same time
8192x2048     32 MiB      473 MiB (14.8x)      289 MiB
Llama-3.2-1B rtn4 whole run: peak allocated 0.530 GiB default -> 0.261 GiB with block_in=256

For GPTQ, packing is usually off the peak path, but overlapping packs pushed the Llama-1B peak from 1.420 to 1.539 GiB in one run. Fix: derive block_in from an element budget (e.g. out_features * blk ≤ 4M).

Measurements (ROCm, peak allocated / reserved GiB)

method Qwen2.5-0.5B Llama-3.2-1B
gptq4 0.505 / 0.838 1.420 / 2.26
gptaq4 1.27–1.39 / 2.12 2.807 / 5.305
awq4 0.480 / 1.494 1.066 / 1.793
qqq4 0.533 / 0.691 1.534 / 2.018
vptq 1.921 / 3.678 —
exl3_4 3.049 / 5.916 4.936 / 14.19 (≈2.06 GiB is the #4391 tile scratch)
paro4 0.392 / 0.613 1.177 / 1.602
macaq 1.383 / 1.773 5.21 / 7.65
rtn4 0.142 / 0.209 0.530 / 0.779

Checked, clean

Plausible, not verified

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed by an AI agent: item 1 (ROCm AWQ clip scratch vs split cap) and item 4 (pack_gpu block_in transient). The MACaQ dead-copy item is already merged via #4431.

  2. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed by an AI agent: item 3 (shared-input Hessian dedup for QQQ/VPTQ/MACaQ/EXL3). Items 1, 2, 4 are merged (#4437, #4431).

  3. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed by an AI agent: item 3 (shared-input Hessian dedup for QQQ/VPTQ/MACaQ/EXL3). Branch fix/sibling-hessian-dedup-4401; items 1, 2, 4 landed in #4437/#4431.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions