Skip to content

feat(exl3): preserve Hessian conditioning and projection diagnostics - #3591

Merged
Qubitium merged 6 commits into
ModelCloud:mainfrom
tpurtell:upstream/11-exl3-numerical-diagnostics-20261108
Nov 8, 2026
Merged

Qubitium merged 6 commits into
ModelCloud:mainfrom
tpurtell:upstream/11-exl3-numerical-diagnostics-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the fork quantizer changes for FP64 Hessian congruence, symmetry restoration, per-projection RNG isolation, and structured reconstruction/Hessian error metrics. Preserve the existing arithmetic and failure evidence rather than redesigning it.

This is layer 11/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3588. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream main.

Incremental change: 5 files, +601/−46 lines, including carried tests and the mechanism reference. No merge is automatic. Review value and API shape first; substantial rework can follow that feedback.

Flow and existing-code boundary

flowchart TD
    S0["regularize_and_transform_hessian_"]
    S1["restore_hessian_symmetry_"]
    S2["quantize_exl3"]
    S3["reconstruction_error_metrics"]
    E["RuntimeError, ValueError"]
    S0 -->|"calls where selected"| S1
    S0 -->|"raises on rejected input/state"| E
    S1 -->|"raises on rejected input/state"| E
    S3 -->|"raises on rejected input/state"| E
    style E fill:#fee,stroke:#b22
Loading
Before this extraction layer Carried implementation
API absent in the previous stack layer (path/symbol checked) gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.py:688: regularize_and_transform_hessian_
API absent in the previous stack layer (path/symbol checked) gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.py:666: restore_hessian_symmetry_
Previous stack layer: gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.py:1014 gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.py:1266: quantize_exl3
API absent in the previous stack layer (path/symbol checked) gptqmodel/exllamav3/modules/quant/exl3_lib/quantize.py:1053: reconstruction_error_metrics

Committed reference: docs/exl3-numerical-diagnostics.md, linked from README. Class entry points/calls and rejected-state paths describe code present in this branch, rather than planned integrations.

Validation

Carried test files: tests/test_exl3_hessian_symmetry.py, tests/kernels/test_exllamav3_kernel.py

This packaging pass checked Python parsing, whitespace, dependency order and balanced Mermaid blocks. The author reports successful prior use of these features. Per the requested resource limit and feedback-first scope, existing model quantization, GPU/ROCm tests, heavyweight CPU workloads and full model benchmarks were not rerun; no new performance or model-accuracy claim is made. Tests accompanying earlier stack layers retain their previously reported results.

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: layer 11/36 — Hessian conditioning + projection diagnostics

Rebased onto the layer-10 branch (ded8fcc1); no conflicts. Diff vs the predecessor is the quantizer, the two tests, the doc page and the README link. Pushed as cdfc330d.

Validated on hardware (this layer touches the quantizer, so I ran it)

  • CUDA (RTX 5090, sm_120): tests/kernels/test_exllamav3_kernel.py + tests/test_exl3_hessian_symmetry.py → 22 passed (18 kernel, 4 symmetry), 4.1s
  • ROCm (R9700, gfx1201): symmetry → 4 passed; kernel file → 9 passed, 9 skipped (the native EXL3 reference tests skip under ROCm as expected)
  • CPU: symmetry → 3 passed, 1 skipped
  • ruff check clean
  • Manual probe of reconstruct_exl3_tensors against ExllamaV3TorchLinear for 3inst/mcg/mul1: max abs diff ~0.003, consistent with the FP16 runtime reconstruction

Fixed

  1. CI-blocking import order — tests/kernels/test_exllamav3_kernel.py tripped I001; the repo gate runs ruff check over tests. Sorted.
  2. Wrong exception type for bad inputs — regularize_and_transform_hessian_ did su.shape / diag_mean.numel() before type checks, so a non-tensor raised AttributeError instead of the intended ValueError. Added isinstance guards.
  3. Diagonal regularizer regression — the FP64 congruence used transformed[idx, idx] += regularization, which builds index tensors and does a gather/scatter on every projection. Replaced with transformed.diagonal().add_(regularization) (the original code's stated intent).

Notes (not blockers)

  • _random_signs() is now unused in this tree (kept for "upstream backends"). It is dead code until a later layer wires it.
  • Sign sequence change: sv used to come from a seed+1 stream; it now continues the single projection-local generator after su. Still deterministic, but the same seed produces different weights than the previous layer. Confirm this is the intended fork sequence.
  • "seed": None now raises ValueError ("must be an integer"), whereas the old path fell back to the global RNG. If None means "unseeded", it needs handling.
  • quant_args["error_metrics"] can contain NaN/Inf (it reports *_finite flags rather than rejecting). Any later JSON persistence with allow_nan=False would fail.
  • reconstruct_exl3_tensors has no automated test. It works (manually checked above); a kernel-test case comparing it to the native module would lock it in.
  • reconstruction_error_metrics requires 16×16 divisibility. That is safe: EXL3 weights are multiples of the 128-wide Hadamard blocks.
  • The K <= 8 guard is correct, not over-tight: reconstruct_kernel_instances covers K=1..8 and exl3_packed::bit_count = 8.
  • restore_hessian_symmetry_ allocates (H + H.T) * 0.5 (two temporaries); symmetric = H + H.T; symmetric *= 0.5 would halve that.

The FP64 congruence + symmetry restoration is the right shape for this fix: it preserves the sigma_reg margin, records the contract and correction magnitude, and the CUDA symmetry test confirms the 2048-wide expert-down case stays positive-definite.

@Qubitium
Qubitium marked this pull request as ready for review November 8, 2026 08:10
@Qubitium
Qubitium force-pushed the upstream/11-exl3-numerical-diagnostics-20261108 branch 2 times, most recently from 17762c5 to 2cdc454 Compare November 8, 2026 08:22
tpurtell and others added 6 commits November 8, 2026 08:35
The new test file used semicolons (E702) and unsorted imports (I001), and the
module import block was unsorted; format/check.sh runs ruff check over tests,
so the PR could not merge as-is. No behavior change: 20 tests still pass.
…utputs

- Keep progress.json until the destination rename commits. A crash after the
  complete manifest is written but before the rename now resumes the finished
  shards instead of recomputing them; add a rename-crash regression test.
- Reject manifest/progress shard paths that escape the root or are symlinks.
- Make _fsync_directory a no-op off POSIX; clean up _atomic_json temp files on
  failure and write them 0644.
- Declare xxhash (the writer hashes every shard, so it is not recovery-only)
  and raise a clear ImportError when it is missing.
Extract the existing working fork feature for first maintainer feedback. Preserve carried code and tests; limit validation to lightweight structural checks. See the linked mechanism reference for actual API/call and failure paths.
- Reject non-tensor su/diag_mean with ValueError instead of AttributeError.
- Use diagonal().add_() for the FP64 regularizer; advanced indexing built index
  tensors and a gather/scatter pair on every projection.
- Sort imports in the kernel test (CI ruff I001 gate).
@Qubitium
Qubitium force-pushed the upstream/11-exl3-numerical-diagnostics-20261108 branch from 2cdc454 to 90f87ad Compare November 8, 2026 08:36
@Qubitium
Qubitium merged commit 80bf18a into ModelCloud:main Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants