Repository navigation
Optimize NF4 single-token GEMV on Blackwell - #2098
Draft
PiotrPotocki wants to merge 2 commits into
Draft
PiotrPotocki wants to merge 2 commits into
PiotrPotocki wants to merge 2 commits into
Conversation
This branch has not been deployed
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
Optimize the fused 4-bit SIMT matrix-vector path for single-token NF4 decoding on NVIDIA Blackwell SM120 GPUs.
On an NVIDIA RTX PRO 4500 Blackwell, the geometric-mean latency across 16 benchmark cases decreased from 44.744 µs to 41.130 µs, an 8.08% latency reduction (1.088× speedup).
Implementation
Changes are contained in
csrc/gemm_4bit_simt.cu:.cgpacked-weight loads on SM120 and preload the next K group during single-row computation.M=1,N<=4096,K=4096, and block size 64.The device-code optimizations are guarded for SM120. No public API, quantization format, or runtime dependency is added.
Performance
Measured using the production
torch.ops.bitsandbytes.gemm_4bit.defaultoperator.M=1uint8(N, K)(4096, 14336),(14336, 4096),(12288, 4096),(4096, 4096)Each case used 100 warm-up calls, followed by 30 batches of 10,000 calls. CUDA events bracketed the operator calls on the current stream, with synchronization after the end event. Batch duration was divided by 10,000, and the median per-call time across batches was recorded.
The aggregate score is the equally weighted geometric mean of the 16 case medians.
The largest measured reduction was 19.34% for FP16 with ordinary statistics at
(N=4096, K=14336). The narrow BF16 double-quantized case was effectively unchanged, with a measured difference of approximately 0.17%.These are operator-level measurements on one GPU, not end-to-end model decoding results.
Correctness validation
The local validation passed:
torch.nn.functional.linear.Existing repository test tolerances were not changed. Additional local checks used fixed dtype-specific tolerances established against the baseline.
Scope and review notes
Tooling attribution
Developed with assistance from OptiMind, Unikie’s agentic code-performance optimization tool, which proposed and evaluated candidate changes through automated builds, correctness checks, benchmarking, and profiling. OptiMind is not a runtime dependency.