Skip to content

feat(exl3): add bounded covariance accumulation with an FP64 outer sum - #3587

Merged
Qubitium merged 2 commits into
ModelCloud:mainfrom
tpurtell:upstream/09-bounded-covariance-20261108
Nov 8, 2026
Merged

Qubitium merged 2 commits into
ModelCloud:mainfrom
tpurtell:upstream/09-bounded-covariance-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add an explicit reusable accumulator that computes FP32 products over at most 128 actual input rows, accumulates products in FP64, and returns owned FP32 snapshots. Reject invalid geometry, nonfinite inputs and failed partial states. The utility does not change the default quantization pipeline; native-source consumers remain in the fork remainder.

Stack

Layer 9/36 of a dependency-ordered fork extraction. Depends on #3586. Review only this layer.

GitHub requires this cross-fork PR to target upstream main, so its Files changed tab includes earlier stack layers. After the predecessor lands, rebase this branch and retarget the next layer; do not merge later layers out of order. No predecessor is merged automatically.

Tests

CUDA_VISIBLE_DEVICES='' HIP_VISIBLE_DEVICES='' OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest -q tests/test_exl3_hessian_accumulator.py

20 passed in 0.27 seconds. Used Python 3.12, Torch 2.14.1, Transformers 5.19.0. No model quantization, GPU work, downloads, or heavyweight model validation. Unit fixtures are small and CPU execution is constrained to one math thread.

Review and remaining validation

This layer and its dependency diff were reviewed for scope, existing extension points, and compatibility with the resolved fork snapshot. New focused regression coverage is included. Kept as a draft for maintainer review; hardware paths and end-to-end model behavior have not been revalidated in this session. No speed claim. Original integration/history is preserved in tpurtell#3.

Independent FP64 covariance reference covers FP16/BF16/FP32 inputs, row-product boundaries, cancellation, signed zero, half-ULP storage neighbors and failure poisoning. Normalized matrix error is asserted below 1e-6, and discrete/storage boundary cases match exactly. CPU checks passed; actual GPU full-stream covariance validation is a readiness blocker, and production pipeline integration remains deferred.

@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 9/36 — bounded covariance accumulator

Rebased onto the layer-8 branch (ea590da0); no conflicts. Diff vs the predecessor is only the two new files (gptqmodel/utils/exl3_hessian.py, tests/test_exl3_hessian_accumulator.py). Pushed as ef7a8c5e.

Verified

  • tests/test_exl3_hessian_accumulator.py → 20 passed
  • ruff check clean
  • CUDA probe (RTX 5090): 301×64 FP16 rows, relative error 7.1e-8 vs an FP64 oracle; setting allow_tf32=True raises the guard as intended

Fixed

  • CI-blocking lint — format/check.sh runs ruff check over tests, and the new test tripped E702 (semicolon statements) plus I001 (import order) in both files. Rewrote the test in repo style and sorted the module imports. No behavior change; all 20 tests still pass. The PR could not have merged as-is.

Functional review

The accumulator itself is sound: inputs are validated (dtype, width, nonempty, finite), each chunk is converted to FP32 and multiplied as mm(value.T, value), the product is accumulated into an FP64 tensor, any failure poisons the instance, and snapshot() returns owned FP32 storage with a finite-representability check. The tests are genuinely independent (FP64 oracles, exact chunk boundaries, half-ULP ties, cancellation, poison state).

Notes (not blockers)

  • Default device="cuda:0" hardcodes a device index. None (current device) or "cpu" would be less surprising on multi-GPU or CPU-only hosts; callers can already override it.
  • torch.isfinite(product).all() runs per chunk and forces a GPU sync plus a full read of the width×width FP32 product. For wide layers with many 128-row chunks this is significant overhead. If that matters, check the FP64 running sum once per add (or at a coarser cadence) instead.
  • The TF32 guard raises before entering the try block, so _failed stays False and the caller can fix the setting and retry — that looks intentional, worth keeping explicit.
  • The class is not thread-safe and does not document it.
  • The module is not exported from gptqmodel/utils/__init__.py and is not wired into the pipeline, matching the stated "fork remainder" scope.

@Qubitium
Qubitium marked this pull request as ready for review November 8, 2026 08:10
@Qubitium
Qubitium force-pushed the upstream/09-bounded-covariance-20261108 branch 2 times, most recently from b15b48d to 4c75347 Compare November 8, 2026 08:21
tpurtell and others added 2 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.
@Qubitium
Qubitium force-pushed the upstream/09-bounded-covariance-20261108 branch from 4c75347 to 5181cdb Compare November 8, 2026 08:35
@Qubitium
Qubitium merged commit 0762aec 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