[perf][gemm]: tile short-token FFN weight gradients - #351
Merged
Merged
Conversation
Flink-ddd
requested review from
KJLdefeated,
bitborne and
inaniloquentee
as code owners
August 28, 2026 03:02
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This was referenced Aug 28, 2026
[perf][gemm]: optimize long-token FFN deterministic path
inaniloquentee
approved these changes
Aug 28, 2026
maxiaosong1124
approved these changes
Aug 28, 2026
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 short-token CUDA deterministic GEMM backward path used by the Qwen3 FFN benchmark in PR #348.
When tokens < 32, the three weight-gradient GEMMs currently transpose the input and fall back to a 16x16 scalar launch. For Qwen3-8B shapes this creates roughly 200k CTAs per GEMM. This change adds a deterministic 128x128 tiled outer-product kernel that:
Validation
Benchmark command from PR #348:
H100 benchmark results
A single-run benchmark was collected on an NVIDIA H100 80GB HBM3 with CUDA 12.4 and PyTorch 2.4.1+cu124. The comparison uses the benchmark's optimized.median_ms values; both branches used the same Triton compatibility workaround (tl.range(..., flatten=True) removed because the installed Triton does not accept that keyword).
All correctness checks passed for tokens 1, 8, 32, and 128. The largest gain is in the intended short-token forward + backward cases: 1.464x at M=1 and 1.458x at M=8. A higher-sample repeat is pending because the GPU is currently busy.
The CUDA 12.4 build-compatibility follow-up is included in commit 8fbd363.
Nsight Systems kernel profile
The H100 trace confirms that the optimization is localized to the intended short-token deterministic dW path. These are aggregated kernel-time breakdown charts from cuda_gpu_kern_sum for the same tokens=1,8 profiling run (CUDA 12.4, H100 80GB HBM3). They are not synthetic timings: the source data came from the before/after .nsys-rep reports on the target node. These are kernel-time breakdown charts, not standard call-stack flame graphs. A true Nsight flame graph requires CPU/Python stack sampling and will be added from a dedicated trace when the H100 is available.
Before
After
The replaced kernel is det_gemm_naive<bf16,true>: 90 launches and 157.657 ms before, versus 90 det_gemm_db_small_k launches and 12.006 ms after (13.13x kernel-time speedup, 92.38% reduction). The existing det_gemm_sm90_kernel row remains effectively unchanged (392.263 ms → 391.452 ms), which is a control for the short-token-specific change.
Detailed source data and calculation: kernel_summary.md.
The kernel-breakdown artifacts are included in commits 949b088 and adb575d.
Nsight Systems event-level details
The screenshots below are direct views from the same before and after.nsys-rep traces.
Before
The selected event is det_gemm_naive<bf16, bool(1)>, with approximately 1.75 ms per launch.
After
The selected event is det_gemm_db_small_k, with approximately 94–178 us per launch.