Skip to content

[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

Closed

Description

@Qubitium

Severity: medium. Kind: new; present at def6e61.

  • 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:

  1. apply_one(r), which writes x_grp / g_grp in shared memory;
  2. __syncthreads();
  3. 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.

Impact


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions