Repository navigation
fix(paroquant): race-free, plan-invariant and correct fused rotation gradient; round-13 test triage (#4461, #4460, #4462) - #4499
Merged
Conversation
…ion (#4461) The fused backward sweep kept one barrier per rotation between apply_one and the gradient readback. That barrier is not needed (each thread reads back only the pair it just rotated) and it does not cover the real hazard: the next rotation's apply_one overwrites columns other threads are still reading for the current rotation (write after read). The theta gradient was sporadically corrupted (|err| up to 4.2 on ROCm, 1.7 on CUDA at 2048 features). Move the single barrier after the readback so it orders both the cross-rotation read-after-write and write-after-read, and mask the readback columns the same way apply_one does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aunch plan (#4460) rotate_pair_grad wrote one gradient partial per CTA_M-row tile, and CTA_M is chosen per shape by a timing-based autotune. Two cold runs on the same host picked different tiles for Llama-3.2-1B's 2048x2048 weight shape (cta_m 8 vs 16), so the fp32 summation order of the theta gradient changed and the quantized checkpoints diverged from layer 0 (22.43 vs 21.72 PPL). Sum every CTA's rows in fixed 4-row granules and fold the granules in ascending order, so the rounding sequence is identical for every cta_m/row_pad. cta_m=4 results are bit-identical to before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… triage (#4462) - test_ret_idx_cache_invalidation: _fused_module writes raw buffers through setattr, which bypasses the load hook, without declaring their layout. Since #4377 (db31a55) an unresolved layout means raw v1 checkpoint words, the same contract every product writer follows (loader v1->v2 conversion, packing, offload restore all call qzero_format/establish). Declare the v2 layout the fixture actually writes (logical zero codes, as the dense oracle decodes them) with qzero_format(format=2). - test_offload_run_namespace: the stub processor lacks release_run_workspace, which loop() now calls on failure too (a427804). - test_weight_only_looper: offload_to_disk=True binds a private per-run config copy (#4368), so the embed-only overrides are asserted on the run config. - test_model_test_helpers: the mocked parquet loader ignored rows; hosts with the local parquet take that loader's early path for rows > 0. - test_paroquant: _AFFINE_STE_TRITON_ENABLED was replaced by KernelConfig.paroquant_affine_ste_triton (27c6b7b); the AWQ fake must accept kernel=; skip the CUDA-only AWQ fast-path test on ROCm. - test_qqq_kernel_memory_4387: exclude the BLAS library's per-call GEMM workspace (8 MiB cuBLAS, 80 MiB hipBLASLt) from QQQ's transient bound; QQQ's own transient is 20.82 MiB on both platforms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…factors The fused theta backward (rotate_pair_grad, the grad_theta op and the torch fallback) sweeps both the activation and the incoming gradient back through each rotation before measuring it, so it holds x_in and g_in = R^T g_out. With dR/dtheta = R J the gradient is then sum(g_i x_j - g_j x_i), but the code applied the output-side formula A cos(theta) - B sin(theta) to the input-side gradient. The result is exact only at theta == 0 and drifts as the angles train (max error 0.7 / 7.1 / 18.5 against fp64 autograd for |theta| up to 0.05 / 0.25 / 1.0, on gradients of magnitude ~20). The non-fused optimizer path uses plain autograd and was already correct, so the fused (default CUDA/ROCm) and unfused ParoQuant runs optimized different objectives. Drop the sin/cos factors in all three paths (grad_theta loses its now-unused sin_t/cos_t arguments) and test every path, with and without channel scales, against fp64 autograd of the reference rotation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe the shared-memory ordering (#4461), the launch-plan-invariant gradient granule (#4460) and the input-side angle gradient, with before/after file:line evidence and the guarding tests. Link it from the README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Nov 16, 2026
main's #4499 rewrote the fused rotation-gradient partials around fixed 4-row granules; keep that tiling and apply the branch's mutable_data_ptr accessors to it. main also dropped the unused sin_t/cos_t arguments from grad_theta_kernel, so the launch follows the current signature.
Qubitium
added a commit
that referenced
this pull request
Nov 16, 2026
…bs (#4460) (#4505) ParoQuant checkpoints are meant to be reproducible with a fixed opt_seed. PR #4499 made CUDA bitwise-identical, but ROCm kept hipBLASLt because ParoQuant accumulates no Hessian. hipBLASLt selects GEMM kernels per process, so identically seeded runs produced different checkpoints (21.26 vs 21.44 PPL). Include ProcessorStep.PARO in the deterministic rocBLAS selection and document the accepted speed-for-reproducibility trade-off. The fused-rotation autotune timing knobs were read from GPTQMODEL_PAROQUANT_ROTATE_AUTOTUNE_* environment variables in rotation.cu, which AGENTS.md forbids. Replace them with internal constants that preserve the previous defaults; KernelConfig.paroquant_rotate_* remains the only control surface. Tests: a mocked-ROCm selection test and a source-grep test that no ParoQuant environment reads remain. ROCm numerical determinism cannot be executed on this host (no ROCm device); it is validated structurally and with the mocked platform.
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.
Fixes #4461
Fixes #4462
Partially fixes #4460. CUDA is now bit-reproducible; the remaining ROCm source is documented below.
ParoQuant fused rotation backward
Race (#4461)
rotate_pair_grad_kernelhad its only per-rotation barrier betweenapply_oneand the readback. So rotation r-1'sapply_onecould overwrite columns that other threads were still reading for rotation r.Launch-plan invariance (#4460)
CTA_Mtile, and the autotune is timing-based. Two cold Llama-3.2-1B runs picked cta_m 8 vs 16 and diverged from layer 0 (22.43 vs 21.72 PPL).Gradient formula
A cos θ - B sin θto the input-side gradient; the correct derivative isA = Σ(g_i x_j - g_j x_i). The unfused (autograd) path was already right.| |θ| up to | max error vs fp64 autograd |
|---|---|
| 0.05 | 0.7 |
| 0.25 | 7.1 |
| 1.0 | 18.5 |
rotate_pair_grad, ingrad_theta(its sin/cos arguments are removed) and in the torch fallback.Remaining ROCm nondeterminism
_needs_deterministic_hessiankeeps hipBLASLt for ParoQuant on ROCm, and hipBLASLt picks GEMM kernels per process. With rocBLAS pinned, two ROCm runs give bitwise-identical checkpoints.Tests:
test_paroquant_pair_grad_sweep_is_race_free,test_paroquant_pair_grad_is_launch_plan_invariant,test_paroquant_fused_rotation_theta_grad_matches_autograd.Docs:
docs/paroquant.md#fused-rotation-backward.Test triage (#4462)
test_ret_idx_cache_invalidation: the fixture wrote raw qzeros without declaring their layout. Since [BUG]fresh.load_state_dict(mod.state_dict())from a v1-loaded module into a freshly built v2-runtime module still skips the v1→v2 conversion (incomplete fix of #4304) #4377 an undeclared layout means raw v1 words, which is the contract every product writer follows. The fixture now declares v2.release_run_workspace;quantize()creates a new full-sizerun-<uuid>directory underoffload_to_disk_path, and it is never deleted (regression from 2bc2f63, #4202) #4368);rows;KernelConfigreplaces_AFFINE_STE_TRITON_ENABLED;kernel=;Results
qzeros_formatmarker #4351 vram-strategy test.qzeros_formatmarker #4351 test).ruffis clean.🤖 Generated with Claude Code