Repository navigation
perf(exl3): tile Hessian symmetrization and release the capture partial (#4818) - #4837
Merged
Merged
Conversation
…al (#4818) `restore_hessian_symmetry_` materialized `(H + H.T) * 0.5` and `(H - symmetric).abs()` on top of the fp64 working copy, so the EXL3 congruence peaked at ~4x C^2 fp64 on the largest projection. `prepare_exl3_hessian` also left the GPTQ capture's per-device fp32 partial deferred through the whole EXL3 solve even though `materialize_global_hessian` had already reduced it into `capture.H`. ## What changed - Apply the symmetry average one tile pair at a time (default tile 1024). Elementwise add/sub are commutative and exact per element, so `H` and `correction_max_abs` are bitwise identical to the untiled form while the temporaries are bounded by one tile instead of another C^2 matrix. - Release the deferred capture partials right after `capture.finalize_hessian()` in `prepare_exl3_hessian`, mirroring what `GPTQ.quantize` does before its memory-heavy phase. The partial is dead there: `materialize_global_hessian` has reduced it into `H`, cleared `_device_hessian_partials`, and left only the deferred-release list. A later `finalize_hessian` returns the already-materialized `H`. ## Measured (GPU 7, PG506-230, torch 2.15, CUDA 13.0) `regularize_and_transform_hessian_` extra peak over the pre-call live set: | shape | fp64 C^2 | before | after | | --- | --- | --- | --- | | C=4096 | 128.0 MiB | 512.2 MiB | 152.2 MiB | | C=8192 | 512.0 MiB | 2048.2 MiB | 536.3 MiB | End-to-end single 8192^2 projection through `quantize_exl3` with 64 calibration rows: peak growth 2885.3 -> 2629.3 MiB. The 256 MiB delta is the released fp32 partial; at this shape the projection's global peak sits in the tile-solve phase rather than the congruence. ## Tests - `test_tiled_restore_is_bitwise_identical_to_untiled` (20 cases: 10 shapes including ragged tiles 63/65/129/1031, fp32 and fp64) compares `H` and `correction_max_abs` bit-for-bit against the untiled reference. - `test_tiled_restore_is_bitwise_identical_to_untiled_on_cuda` (2 cases). - `test_regularized_congruence_extra_peak_is_one_working_copy` asserts the C=8192 congruence extra peak is at most 1.2x the fp64 C^2 bytes. - `test_prepare_exl3_hessian_releases_deferred_capture_partials` asserts no `_deferred_hessian_sources`, no partials, and that the partial's last reference is gone after `prepare_exl3_hessian`. - `test_prepare_exl3_hessian_returns_independent_views` was stale-skipped ("lands in a later stack layer"); the function has landed, so it runs. ### Red evidence on origin/main (e33acc8) `test_regularized_congruence_extra_peak_is_one_working_copy[8192]`: AssertionError: EXL3 fp64 congruence extra peak 2048.2 MiB exceeds 614.4 MiB (1.2x the 512.0 MiB fp64 C^2 working copy) for C=8192 `test_prepare_exl3_hessian_releases_deferred_capture_partials`: AssertionError: assert [(tensor(...), <torch.cuda.Event ...>)] == [] The two files scored 24 failed, 7 passed on unmodified main (the 22 tiled bitwise cases cannot exist before tiling; the memory and lifecycle tests fail at their intended assertions). ### Green - New/changed tests: **31 passed** `python -m pytest tests/test_exl3_hessian_symmetry.py tests/test_gptq_shared_hessian.py -q` - Family suite: **75 passed, 4 skipped, 2 failed** `tests/test_exl3_hessian_*.py tests/test_exl3_workspace*.py tests/test_exl3_trellis_k.py tests/kernels/test_kernel_compile_levels_gptq.py` The 2 failures are `test_exl3_workspace_release.py::test_looper_releases_tile_workspace_when_run_ends[False|True]` (`AttributeError: 'types.SimpleNamespace' object has no attribute 'model'` and `ModuleLooper object has no attribute '_inflight_layer'`). They fail identically on origin/main and are unrelated to this change. Skips are hardware/dependency: cuda:1, AVX512-BF16 CPU kernel, Machete SM90, BitBLAS. - `ruff check` clean on all four changed files. Bitwise equality held for every tested shape and both dtypes, on CPU and CUDA. Logic flow: localized memory fix inside two existing functions; no control-flow, decision mechanism, or selection-order change, so no logic-flow docs page is required. Fixes #4818
This was referenced Nov 17, 2026
sLaffey
pushed a commit
to sLaffey/GPTQModel
that referenced
this pull request
Nov 18, 2026
…lCloud#4978) Seven tests went red because their doubles/oracles predate library changes that behave as intended. This is test-only; no product code changes. - test_fusion_kernel_backends: gc.collect() before the weakref check; ModelCloud#4871 leaves transient Dynamo trace garbage that keeps the pre-fusion weight alive. The refs are still asserted dead afterwards. - test_failed_run_fence_4595: del qmodel + gc.collect() so ModelCloud#4829's finalizer runs before the no-leak assertion; a late finalizer must not recreate the released run dir. - test_exl3_projection_resume: add _release_deferred_hessian_sources() to the _Capture double (ModelCloud#4837). - test_kernel_audit_regressions: stub _needs_torch_fallback=lambda: False on the SimpleNamespace self (ModelCloud#4835). - test_moe_resave_preserves_experts_4589: accept the earlier RuntimeError "does not provide tensors" refusal (ModelCloud#4810); still assert no safetensors. - test_positional_mask_capture_4660: build the native oracle with the same mask-derived position_ids the capture uses (ModelCloud#4930). - test_qqq_kernel_memory_4387: snapshot the oracle weight/s_channel before the first forward, which may drop the checkpoint layout (ModelCloud#4856).
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.
perf(exl3): tile Hessian symmetrization and release the capture partial (#4818)
restore_hessian_symmetry_materialized(H + H.T) * 0.5and(H - symmetric).abs()on top of the fp64 working copy, so the EXL3congruence peaked at ~4x C^2 fp64 on the largest projection.
prepare_exl3_hessianalso left the GPTQ capture's per-device fp32partial deferred through the whole EXL3 solve even though
materialize_global_hessianhad already reduced it intocapture.H.What changed
Elementwise add/sub are commutative and exact per element, so
Handcorrection_max_absare bitwise identical to the untiled form while thetemporaries are bounded by one tile instead of another C^2 matrix.
capture.finalize_hessian()inprepare_exl3_hessian, mirroring whatGPTQ.quantizedoes before its memory-heavy phase. The partial is deadthere:
materialize_global_hessianhas reduced it intoH, cleared_device_hessian_partials, and left only the deferred-release list. Alater
finalize_hessianreturns the already-materializedH.Measured (GPU 7, PG506-230, torch 2.15, CUDA 13.0)
regularize_and_transform_hessian_extra peak over the pre-call live set:End-to-end single 8192^2 projection through
quantize_exl3with 64calibration rows: peak growth 2885.3 -> 2629.3 MiB. The 256 MiB delta is
the released fp32 partial; at this shape the projection's global peak
sits in the tile-solve phase rather than the congruence.
Tests
test_tiled_restore_is_bitwise_identical_to_untiled(20 cases: 10shapes including ragged tiles 63/65/129/1031, fp32 and fp64) compares
Handcorrection_max_absbit-for-bit against the untiled reference.test_tiled_restore_is_bitwise_identical_to_untiled_on_cuda(2 cases).test_regularized_congruence_extra_peak_is_one_working_copyasserts theC=8192 congruence extra peak is at most 1.2x the fp64 C^2 bytes.
test_prepare_exl3_hessian_releases_deferred_capture_partialsassertsno
_deferred_hessian_sources, no partials, and that the partial's lastreference is gone after
prepare_exl3_hessian.test_prepare_exl3_hessian_returns_independent_viewswas stale-skipped("lands in a later stack layer"); the function has landed, so it runs.
Red evidence on origin/main (e33acc8)
test_regularized_congruence_extra_peak_is_one_working_copy[8192]:test_prepare_exl3_hessian_releases_deferred_capture_partials:The two files scored 24 failed, 7 passed on unmodified main (the 22
tiled bitwise cases cannot exist before tiling; the memory and lifecycle
tests fail at their intended assertions).
Green
python -m pytest tests/test_exl3_hessian_symmetry.py tests/test_gptq_shared_hessian.py -qtests/test_exl3_hessian_*.py tests/test_exl3_workspace*.py tests/test_exl3_trellis_k.py tests/kernels/test_kernel_compile_levels_gptq.pyThe 2 failures are
test_exl3_workspace_release.py::test_looper_releases_tile_workspace_when_run_ends[False|True](
AttributeError: 'types.SimpleNamespace' object has no attribute 'model'and
ModuleLooper object has no attribute '_inflight_layer'). They failidentically on origin/main and are unrelated to this change. Skips are
hardware/dependency: cuda:1, AVX512-BF16 CPU kernel, Machete SM90,
BitBLAS.
ruff checkclean on all four changed files.Bitwise equality held for every tested shape and both dtypes, on CPU and
CUDA.
Logic flow: localized memory fix inside two existing functions; no
control-flow, decision mechanism, or selection-order change, so no
logic-flow docs page is required.
Fixes #4818