Respect the current CUDA stream in blockwise quantization - #2052
Open
heiheiha798 wants to merge 2 commits into
Open
Respect the current CUDA stream in blockwise quantization#2052heiheiha798 wants to merge 2 commits into
heiheiha798 wants to merge 2 commits into
Conversation
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.
Summary
Blockwise CUDA quantization currently launches on the legacy default stream even when PyTorch has selected a different current stream. This can let quantization run before a producer on that current stream has finished writing its input.
This change:
The public schema, Python API, output allocation, launch geometry, quantization math, and existing C ABI are unchanged.
Tracking:
Reproduced failure
Slurm job 5099 built the exact baseline
95f9af309d4d5793847169c39288dcd3fcbdf564for the official CUDA 13 x64 target input75;80;86;89;90;100;120and ran on one NVIDIA B300 SXM6 AC (CC 10.3, 148 SMs).The reproducer recorded a pending blocker event before entering the test stream, made that stream wait, filled the input there, and immediately called the public quantizer. All four baseline paths read stale data while the final input itself was correct:
Archived evidence is listed in the linked fork draft PR.
Correctness and safety
Slurm job 5101 built production/test commit
86aabee18f42d54448e26cb281aea8fe083b8b16with the same official-compatible target list and asserted the loaded temporary library path.compute-sanitizer --tool racecheck: 0 hazards, 0 errors, 0 warnings.compute-sanitizer --tool synccheck: 0 errors.The final head
56d8d94082568e7d6a8c0788e4247583cdbb65d5changes only the tracked benchmark after that production/test commit. Job 5104 separately built and loaded that exact final head and rechecked bitwise equality throughout the benchmark matrix.CPU collection also remains healthy: 33 passed, 22 CUDA-only skips, 345 deselected. Full
pre-commit run --all-filespasses.B300 measurement
Job 5104 built isolated baseline and candidate source trees with CUDA 13.0.88 and the official-compatible targets, asserted both native library paths, and measured on the same B300 allocation. The tracked CLI interleaves variants after 20 warmups for 7 rounds, retaining every sample, per-round medians, p10/p90, bootstrap ratio intervals, and input-byte effective bandwidth.
Default-stream direct latency covered 36 cells: FP16/BF16/FP32 x General8/FP4/NF4 x
n={524288,8388608,67108864,536870912}elements. Those counts are 1 MiB, 16 MiB, 128 MiB, and 1 GiB for FP16/BF16 inputs, and 2 MiB, 32 MiB, 256 MiB, and 2 GiB for FP32 inputs. The worst baseline/candidate ratio was0.98310, equivalent to a 1.72% candidate slowdown, so the <=2% regression gate passed.The correct two-stream pinned-H2D plus compressed-NF4 pipeline covered six cells. The baseline explicitly waits for both copies before stream-0 quantization; the candidate chains each copy and public quantizer on its current stream.
These gains are 0.47%-1.08%, below the 5% performance-claim threshold. This PR is therefore a correctness fix and makes no B300 speedup claim. Nsight Systems confirms H2D and quantization activity in the serialized-baseline and current-stream-candidate ranges; its one-shot range durations include setup and are not used as performance claims.
Archived evidence is listed in the linked fork draft PR.
Reproduction
After building baseline and candidate into isolated source trees with the CUDA 13 x64 target list, run:
The exact build and invocation transcript is listed in the linked fork draft PR.
Limitations
hipcc, so HIP compile/runtime validation was unavailable. The shared source remains syntactically scoped through the existing CUDA/HIP stream compatibility layer, but downstream HIP CI is required.