You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] ParoQuant rotate_pair_grad_kernel shared-memory write-after-read race: fused rotation gradient intermittently wrong (|err| up to 2.5); flaky test_paroquant_pair_grad_reduce_folds_tiles_in_ascending_order #4461
ROCm: confirmed on an R9700 (gfx1201) at 489aed6. A one-line barrier fixes it.
CUDA: affected by inspection. The source is the same, and the 64-thread block spans 2 warps.
Where
gptqmodel_ext/paroquant/rotation.cu:412-436. Each iteration of the rotation loop does:
apply_one(r), which writes x_grp / g_grp in shared memory;
__syncthreads();
a readback of columns i, j for rotation r.
There is no barrier before the next iteration's apply_one(r-1). That call writes columns that other threads may still be reading for rotation r. The comment at :378-380 ("a single barrier per rotation covers the staging") is wrong: one barrier covers only read-after-write, not write-after-read.
Repro
Inputs:group_size=128, krot=8, cta_m=4, rows 16 or 192, float32, rotation buffers from build_random_rotation_buffers(seed=31).
Run: call torch.ops...rotate_pair_grad(x, g, pairs, theta, 128, 4, 0)[2] 30 times in one process, compare each result with the ascending per-tile reference sum, and repeat in 10 processes.
Actual at HEAD: 6 of 10 processes produce wrong results, with up to 12 distinct outputs per 30 calls and a max abs diff of 0.8–2.53.
Expected: bit-identical output, which is the kernel's documented contract.
With the barrier: adding if (r != KROT-1) __syncthreads(); at the top of the loop gives 0 of 10 bad processes and 1 distinct result per process.
The guarding test is flaky.tests/test_paroquant.py::test_paroquant_pair_grad_reduce_folds_tiles_in_ascending_order failed 4 of 6 runs at def6e61 and 1 of 6 at HEAD.
Found during an AI-assisted review (Claude Code, round 13) of 489aed6; repros were run at that commit (A/B against def6e61 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.
Activity
fix(paroquant): race-free, plan-invariant and correct fused rotation …