Skip to content

[MEM] EXL3 quantize peaks at 2.3x GPTQ: restore_hessian_symmetry_ holds 4 fp64 C^2 copies and the GPTQ capture's deferred Hessian partial is never released; Llama-3.1-8B layer peak 9.2 -> 3.8 GiB with a bitwise-identical tiled fix #4818

Closed

Description

@Qubitium

Found on main @ dba142d, RTX 4090 (CUDA 13.2, torch 2.15).

What is wrong

EXL3 quantization peaks at 2.3x GPTQ on the same model. The peak sits on the largest projection (down_proj) and comes from two avoidable allocations.

  1. restore_hessian_symmetry_ (exllamav3/modules/quant/exl3_lib/quantize.py:755-773) holds four C^2 fp64 matrices at once. regularize_and_transform_hessian_ (:819) already holds the fp64 working copy transformed. Then:
    symmetric = (H + H.transpose(0, 1)) * 0.5                        # +1 fp64 C^2 (+1 transient)
    correction_max_abs = float((H - symmetric).abs().max().item())   # +2 fp64 C^2
    A tiled version gives bitwise-identical H and correction_max_abs, because elementwise add/sub are commutative and exact per element. It also never holds more than one tile pair.
  2. The GPTQ capture's per-device Hessian partial stays allocated through the whole EXL3 solve. prepare_exl3_hessian (looper/exllamav3_processor.py:206-236) calls capture.finalize_hessian(). materialize_global_hessian reduces the partial into a new result_accum and only defers the partial's release (_defer_hessian_sources, quantization/gptq.py:1452). GPTQ's own quantize() frees it with _release_deferred_hessian_sources() (gptq.py:2205/2429/2437), but no EXL3 path calls it. A second fp32 C^2 therefore stays live during EXL3's fp64 congruence, LDL and tile solve.

Measured: Llama-3.1-8B-Instruct truncated to 2 layers, EXL3Config(bits=4), 64 C4 samples

                              peak allocated   peak reserved
GPTQConfig(bits=4)            4016 MiB         5572 MiB   (same model, 4 layers)
EXL3 4-bit, main              9236 MiB         9974 MiB
EXL3, both fixes patched      3784 MiB         4874 MiB   (-59%)

Live blocks at the 9236 MiB peak (torch.cuda.memory._record_memory_history), on mlp.down_proj, C=14336:

3136 MiB  quantize.py:765 restore_hessian_symmetry_   (H - symmetric, .abs(): 2 x 1568 fp64)
1568 MiB  quantize.py:764 restore_hessian_symmetry_   (symmetric)
1568 MiB  quantize.py:819 regularize_and_transform_hessian_ (transformed, needed)
 784 MiB  gptq.py:1095 compute_hessian_xtx            (deferred capture partial, already reduced)
 784 MiB  gptq.py:1364 materialize_global_hessian     (the Hessian EXL3 consumes, needed)
 512 MiB  quantize.py:159 _allocate_temp_buffers      (tile scratch)

regularize_and_transform_hessian_ alone, random PSD H, current vs tiled symmetrization (1024x1024 tiles):

C=14336: extra peak 6272 -> 1604 MiB, 0.52 -> 0.35 s, H bitwise equal, correction_max_abs equal
C= 8192: extra peak 2048 ->  536 MiB, 0.29 -> 0.15 s, H bitwise equal, correction_max_abs equal

Minimal repro of item 1

import torch, gptqmodel.exllamav3.modules.quant.exl3_lib.quantize as Q
n = 14336
X = torch.randn(2 * n, n, device="cuda"); H = X.T @ X / (2 * n); del X
su = (torch.randn(n, device="cuda").sign() + 1e-5).sign().unsqueeze(1)
a0 = torch.cuda.memory_allocated(); torch.cuda.reset_peak_memory_stats()
Q.regularize_and_transform_hessian_(H, su=su, diag_mean=H.diagonal().mean(), quant_args={"sigma_reg": 0.025})
print((torch.cuda.max_memory_allocated() - a0) / 2**20)   # 6272 MiB (fp64 working copy is 1568)

Suggested fix (both verified above)

def restore_hessian_symmetry_(H, quant_args, tile=1024):
    n = H.shape[0]; corr = H.new_zeros(())
    for i in range(0, n, tile):
        for j in range(i, n, tile):
            a, b = H[i:i+tile, j:j+tile], H[j:j+tile, i:i+tile]
            s = (a + b.T) * 0.5
            corr = torch.maximum(corr, (a - s).abs().max()); corr = torch.maximum(corr, (b - s.T).abs().max())
            a.copy_(s); b.copy_(s.T)
    ...  # record "mean-with-transpose-*" and float(corr) exactly as now

In prepare_exl3_hessian, call capture._release_deferred_hessian_sources() right after capture.finalize_hessian(...). This mirrors what GPTQ.quantize does before its memory-heavy part.

Test that should have caught it

tests/test_exl3*: a CUDA test that runs regularize_and_transform_hessian_ at C=4096 should assert an extra peak of at most ~1.2x the fp64 C^2 bytes, and that the result is bitwise equal to the current implementation. A processor-level test should assert that after prepare_exl3_hessian the capture has no _deferred_hessian_sources.

Severity

Medium: EXL3 on an 8B model needs about 9.2 GiB of VRAM per layer instead of about 3.8 GiB. That decides whether it fits on 12-16 GB cards, and the fix is free (bitwise identical, and faster).

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Taking this.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-c75f32a4f12a finished this issue.

    Pull request: #4837

    Tiling EXL3 Hessian symmetrization and releasing the dead GPTQ capture partial

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