Skip to content

fix(cuda): add portable QQQ bias before output rounding - #3662

Merged
Qubitium merged 2 commits into
mainfrom
audit/cuda-qqq-bias-20261108
Nov 8, 2026
Merged

Qubitium merged 2 commits into
mainfrom
audit/cuda-qqq-bias-20261108

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add portable QQQ bias to the FP32 scaled accumulator before the output cast. The old path cast the accumulator to FP16/BF16 first, so a finite biased result could become inf. This is a local numerical ordering change in QQQTorchLinear.forward; dispatch and persistent weight storage are unchanged.

Before and after

Path Previous code New code
QQQ Torch bias qqq.py:722-727 cast the FP32 scaled result to the activation dtype, then added bias Add bias to the FP32 accumulator and cast once

The mechanism and measurements are in CUDA quantized linear epilogue, already linked from the README. A flow diagram is unnecessary here because the change only reorders one numerical epilogue inside one function.

Validation

NVIDIA GB10 (SM 12.1), PyTorch 2.15.0+cu132:

  • Eight packed QQQ cases across CPU/CUDA, FP16/BF16, and 2D/3D inputs exactly matched an independent FP64 Torch oracle after output rounding. With 128 unit weights, input 516, and bias -1024, the old FP16 output was inf; the corrected output is 65024.
  • Repeated forwards retained no new expanded weight.
  • PYTHON_GIL=1 pytest -q tests/test_qqq_cpu.py tests/test_qqq_jit.py tests/kernels/test_inference_numeric_range.py -k 'qqq and not native_qqq_small_activation_scale and not test_qqq_forward_uses_jit_kernel and not test_qqq_forward_raises_runtime_error_when_jit_ops_missing': 28 passed, 52 skipped. The skipped cases require native extensions or CPU instructions unavailable here. The three excluded native CUDA tests cannot build because CUDA_HOME is unset.
  • ruff check and git diff --check passed.

Full-module resident FP16 timing: five warmups, median of seven sets of 20 CUDA-event timed calls, 1024 input and output features. Peak is allocator delta including temporary weight and library scratch.

Rows Old New Old peak New peak
1 0.5655 ms 0.5820 ms 37.01 MiB 37.01 MiB
16 0.5679 ms 0.5811 ms 37.15 MiB 37.15 MiB

Native QQQ has a separate FP16 output contract and was outside this portable-path change.

@Qubitium
Qubitium marked this pull request as ready for review November 8, 2026 19:03
@Qubitium
Qubitium merged commit cf7a33b into main Nov 8, 2026
6 checks passed
@Qubitium
Qubitium deleted the audit/cuda-qqq-bias-20261108 branch November 8, 2026 19:06
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.

1 participant