Skip to content

[MEM] Regressions from the memory-fix commits: base-module offload re-reads embed_tokens into host RAM (+1 GiB RSS spike, 978c7c1), QQQ keeps the damped Hessian alive through the block pass (+C²·4 B VRAM, 5fbd636), sibling-share TLS cache pins activations after quantize (9626f50) #4463

Closed

Description

@Qubitium

Kind: regressions from #4395/#4400/#4391 fix commits. Confirmed at 489aed6 on an RTX 4090 (default allocator config), A/B against def6e61.

The old and new checkpoints are bitwise identical in every case (GPTQ with offload on and off, AWQ, GPTAQ, QQQ, RTN, EXL3). These are pure memory costs.

1. The base-module offload source-reference check reads full tensors into host RAM (medium, 978c7c1, #4395 item 4)

gptqmodel/utils/offload.py:435-515 _module_source_reference_index, line 498, does the following for every base-module tensor:

  1. handle.get_tensor(source_key) (a full owned copy through mmap);
  2. torch.equal(source, tensor);
  3. a full sha256 of the live tensor.

The noref path it replaced wrote from the live tensor and cost no extra RSS.

Inside the base-module offload_to_disk call (Llama-3.2-1B, GPTQ, offload_to_disk=True):

  • with the reference path: +1004 MiB peak (RssAnon 2324→2826, RssFile 455→957);
  • with _module_source_reference_index patched to return None: +0 MiB.

End to end, def6e61 → HEAD:

run peak RSS offload temp disk
Llama-3.2-1B GPTQ 3162 → 3932 MiB (+770) 985 → 483 MiB
Qwen2.5-0.5B GPTQ 2813 → 3113 MiB (+300) 436 → 179 MiB
Llama-3.2-1B GPTAQ 3394 → 4084 MiB (+690) –
Qwen2.5-0.5B GPTAQ 2813 → 3130 MiB (+317) –

The disk saving shows the fix works, but it trades about 1× the embedding size in RSS for it. For Llama-3-8B that is about 1 GiB anonymous plus 1 GiB file-backed. Comparing in bounded chunks (get_slice), or trusting LazyTurtle provenance, would avoid the full copy.

2. QQQ keeps the input Hessian alive for the whole block pass (medium, 5fbd636, #4400 item 3)

  • Before: gptqmodel/quantization/qqq.py:821-853 rebound H = cholesky(H)…; Hinv = H, which dropped the input Hessian.
  • Now: _inverse_hessian(H) keeps the caller's H for the CPU retry, and nothing deletes it afterwards.

Measured:

  • A single QQQ.quantize() on a 2048×8192 layer: peak minus base 832 → 1088 MiB (+256 MiB = 8192²×4). Q is bitwise identical.
  • End-to-end max_memory_allocated: Llama-3.2-1B 1419 → 1675 MiB (+18%); Qwen2.5-0.5B 479 → 569 MiB (+90 MiB = 4864²×4).

Fix direction: del H right after a successful inverse.

3. The sibling-input share cache pins the last batch's activation across the layer and after quantize() returns (low, 9626f50, #4391 item 4)

gptqmodel/looper/native_processor.py:91-110,146-168: process() bumps the epoch but does not drop tls.entries. They keep (inp, mask, entries) alive until the next capture on that thread or until the processor dies.

Qwen2.5-0.5B GPTAQ, bs=4, 32 samples, HEAD with sharing on vs _native_share_cache returning {}:

metric sharing on sharing off
max allocated 662.4 MiB 651.3 MiB
allocated at end of quantize() 22.7 MiB 11.6 MiB
RSS 3148 MiB 3110 MiB

At 128 samples, def6e61 → HEAD: allocated at quantize end 44.4 → 54.5 MiB; peak Qwen 717 → 727 MiB, Llama 2050 → 2069 MiB. The cost scales with batch × seq × hidden per worker thread.

(A separate review measured a 30% host-memory saving from sharing with CPU staging, so the cache does pay off in some setups. It just needs to be cleared when the layer finishes.)


Found during an AI-assisted review (Claude Code, round 13) of 489aed6; repros were run at that commit (A/B against def6e61 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions