perf: calibrate 4-bit GEMM dispatch for SM103 - #2
Draft
heiheiha798 wants to merge 3 commits into
Draft
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
dequantize + F.linearand leave SM100/B200 behavior unchangedCloses #1.
Why
The existing
major == 10heuristic was calibrated with B200 data and grouped B300 with it. Direct measurements on a B300 SXM6 AC (148 SMs) show that the fused kernel wins consistently at near-wave occupancy through M=32, including square, wide-K, and wide-N model projections. The larger custom tile selected at M=33 generally loses, so this change keeps that boundary conservative.Performance
Both paths were measured in the same Slurm allocation with alternating order. The native SM103 densification used 20 warmups and 7 rounds of 100 CUDA-event samples per path. Values below are fp16/NF4/blocksize 64/nested statistics; bf16 showed the same crossover.
After building the desired bitsandbytes CUDA library, the reported native crossover methodology is reproduced by running this command inside a one-B300 Slurm allocation:
The preset covers all 162 reported dtype/shape/M cells.
--case NAME:N:K:M1,M2,...can be repeated to replace the preset, while--dtype,--blocksize,--quant-type, and--[no-]compress-statisticscontrol focused runs. The CLI refuses to run unless exactly one NVIDIA B300 with compute capability 10.3 is visible. It records the Slurm job, node, existing Git commit ID, software/library identity, complete samples, percentiles, the current candidate decision asdispatch_custom, and custom/fallback correctness in JSONL.Native build evidence:
4716, pilot/build4721, densification4724cmake -G Ninja -DCOMPUTE_BACKEND=cuda -DCOMPUTE_CAPABILITY=103 -DCMAKE_BUILD_TYPE=Release ...Published-binary-compatible code paths were measured separately using the repository's CUDA 13 x86_64 target list (
75;80;86;89;90;100;120), with 20 warmups and 5 rounds of 100 samples per path. The crossover matched the native build:4730The pilot also found a possible custom win through M=64 for very large vocabulary projections. It is intentionally excluded here because the near-wave M<=32 rule has broader native and compatible coverage and a cleaner boundary.
Tracked-harness smoke on the native SM103 library:
4752, commite32fde2f51d9d7f2279db82580b514f67085a06e, B300 SXM6 AC (SM103, 148 SMs)--case tracked_smoke:8192:8192:31,32,33 --dtype fp16 --warmup 2 --repetitions 5 --rounds 20.8585, M=320.8807, M=331.2152; dispatch selected custom/custom/fallback respectively0.001953125; max relative RMS error9.08e-06Validation
Slurm job
4772on B300/SM103 at exact candidate commitdd86a57cd53862e2f21cbbc716bb48695d3a1f89:test_gemm_4bitselection: 200 passedmatmul_4bit: 1,442 passed, 864 skippedmatmul_4bit: 768 passedThe job used Python 3.12.3, PyTorch 2.13.0+cu130, CUDA 13.0, driver 580.126.09, and a B300 SXM6 AC with 148 SMs. Job
4771exited at the shell commit gate before Python, GPU initialization, or tests because its wrapper contained an incorrect expected commit ID; it is recorded as a failed setup attempt and is not validation evidence.Local static checks:
All ten pre-commit hooks passed, including full-repository Ruff, format, YAML, whitespace, typos, and clang-format checks. The CPU-only collection check used PyTorch 2.13.0+cpu (no CUDA runtime or raw-stream symbol) and cleanly collected then skipped only the 14 CUDA selector cases. No C++ kernels, build targets, public APIs, or non-SM103 dispatch thresholds are changed.