Skip to content

fix: round ParoQuant bf16 rotation once in the fused kernel (#4317) - #4365

Merged
Qubitium merged 1 commit into
mainfrom
pr/4317
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4317

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

c45c1b0 made only the Torch reference accumulate the Givens sweep in FP32 and round once. The fused bf16 op that ParoLinear._rotate_inputs uses on GPU (and ParoQuantTritonLinear inherits unchanged — there is no separate Triton rotation) kept its running activation in an FP16 shared-memory workspace, so it rounded after every one of the krot stages. With krot=8, non-unit channel_scales and θ in ±1 rad, that drifts 3.6e-3–5.6e-3 from an FP64 oracle while the fixed reference sits at 2.4e-3–3.0e-3 — the reference was no longer a valid test oracle for what inference computes.

What Changed

  • gptqmodel_ext/paroquant/rotation.cuh
    • Replace RotateAccessBFloat16HalfWorkspace (fp16 workspace, per-stage rounding) with RotateAccessBFloat16FloatWorkspace: load_group widens BF16 input × BF16 channel scale into FP32, apply_one applies each Givens stage with FP32 fmaf on float2 row pairs, and store_group is the only narrowing point (__floats2bfloat162_rn).
    • Drop the now-unused RotateAccess<__nv_bfloat16> half-workspace specialization.
  • gptqmodel_ext/paroquant/rotation.cu
    • rotate_kernel_bf16_float_workspace uses an __align__(16) FP32 shared array; launcher renamed and the at::kBFloat16 dispatch case updated.
    • Shared-memory cost for the compiled variants is (CTA_M + ROW_PAD) * GROUP_SIZE * 4 = 3 KiB (CTA 4) to 9 KiB (CTA 16) — far below the static limit.
  • tests/test_paroquant_single_rounding_4317.py (new)
    • FP64 Givens oracle with the issue's krot=8 / non-unit scales / θ∈±1 fixture.
    • Pins reference-vs-oracle, CPU dispatch still selects the reference, and (when the extension is present) the fused op and ParoQuantTritonLinear._rotate_inputs match the single-rounding floor instead of the per-stage floor.

FP16 and FP32 rotation paths are untouched (their 11-bit significand does not need the wider workspace).

Tests

export GPTQ_BYPASS_SAFETY_CHECKS=1 PYTHONPATH=$PWD CUDA_VISIBLE_DEVICES=
python3 -m pytest tests/test_paroquant_single_rounding_4317.py -q
# 2 passed, 2 skipped (fused op / Triton-linear cases skip: extension not built here)

python3 -m pytest tests/test_paroquant.py tests/test_paroquant_bf16_rotation_4221.py \
  tests/test_paroquant_rotation_lifecycle.py tests/test_paroquant_rotation_pairs.py \
  tests/test_paroquant_capture_order.py tests/test_paroquant_positional_replay.py \
  tests/test_paro_branch_replay_masks.py tests/test_paroquant_single_rounding_4317.py -q
# 223 passed, 38 skipped

ruff check tests/test_paroquant_single_rounding_4317.py
# All checks passed

Not run: the CUDA/HIP extension cannot be compiled on this host (no nvcc, no built extensions), so the fused-kernel cases skip and the kernel change is verified by static review only (template instantiation set, shared-memory size, alignment, dispatch rename). A GPU host with the extension built should run the two skipped cases to confirm the 2.4e-3–3.0e-3 band.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4317

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

Labels

None yet

Projects

None yet

1 participant