bench(ffn): add H100 cuBLAS and vLLM comparisons - #348
Open
frank-2077 wants to merge 1 commit into
Open
Conversation
|
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 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
This PR removes avoidable tensor-layout materializations from the deterministic
SM90 GEMMs used by the Qwen3 FFN while preserving its bitwise-consistency
contract. The optimized path consumes canonical
[out, in]weights directlyand writes canonical contiguous weight gradients directly, without changing
the fixed MMA/K-tree reduction or TP/CP/SP collective order.
On an NVIDIA H100 80GB, the layout change improves the stripped Qwen3-8B FFN
by 2.36–2.40x in forward and 1.22–1.70x in forward + backward versus an
in-process replay of the previous layout contract. All deterministic outputs,
input gradients, and weight gradients remain bitwise identical. The PR also
adds reproducible cuBLAS-preferred and vLLM batch-invariant reference paths,
raw H100 results, and separate forward and forward + backward figures.
Note
These are operator-only, single-GPU measurements of a stripped TP=1,
three-GEMM FFN core. They do not load or benchmark a model checkpoint,
tokenizer, dataset, scheduler, communication path, or serving engine. The
vLLM reference is forward-only and is not an end-to-end vLLM benchmark.
Comparison contract
7207ebdand the public deterministicqwen3_ffnpathdHidden, and all three weight gradientsdirect_copy_kernellaunch countscuBLAS and vLLM use different reduction orders and are numerical/performance
references, not bitwise references. The legacy comparison is replayed in the
same process and build so that it isolates layout materialization cost from
cross-build noise.
Design
[out, in]weights directly, avoiding the previous
weight.t().contiguous()round trip.GEMM result directly as canonical contiguous
[out, in], removing threelarge post-GEMM transposes.
[out, in]weight representation forinput-gradient GEMMs.
fallback kernels.
TMA operands, clone only when the base pointer is not 16-byte aligned.
instruction order, fixed K-tree, no-Split-K behavior, and TP/CP/SP
communication/reduction order.
table under
benchmarks/, pinned to vLLM PR#53247 merge commit
7797b602.Operator test matrix
H=4096,I=12288,M=1/8/32/128dHidden, and all weight gradients match the replayed legacy path bitwiseM=1/8/32/128H100 environment
9.0)595.71.053.11.152.13.0+cu13013.03.7.1H=4096,I=12288,M=1/8/32/128highest; preferred BLAS libraryCublas2026-08-27T13:36:55Z15ca2627f7b1843901dc59877d6db623399dd86a814a99aresults.jsonrecordsgit_dirty=truebecause the benchmark, vendored vLLMreference, and generated artifacts had not yet been committed when the run was
captured. It also records SHA-256 hashes for the benchmark, vLLM kernel,
configuration table, and built CUDA extension.
Correctness results
All deterministic entries below are raw BF16 mismatch counts. Timing is
aborted if any count is non-zero.
dHiddendGateWdUpWdDownWThe optimized timing core also matches the public deterministic
qwen3_ffnpath bitwise for every value above, and every returned weight gradient has its
parameter-matching shape, stride, and contiguous layout.
CUDA BLAS is not expected to match bitwise. Before timing, every output and
gradient must remain below the benchmark gates of 2% relative-L2 error and 5%
normalized maximum error.
dHiddenrel. L2dWeightrel. L2The vLLM path is checked numerically against the optimized deterministic path
and separately checked for identical-first-row batch invariance.
Reproduction commands (the recorded benchmark exposed physical GPU 5 as
logical
cuda:0; select any target H100 throughCUDA_VISIBLE_DEVICES):CUDA_VISIBLE_DEVICES=0 python -m pytest -q \ tests/test_det_gemm.py \ tests/distributed/test_det_gemm_simulated_tp.py \ tests/test_benchmark_qwen_ffn_layout.py \ tests/test_qwen_ffn.py # 67 passed, 14 skippedCUDA_VISIBLE_DEVICES=0,1 python -m pytest -q \ tests/test_qwen_ffn.py::test_qwen_ffn_tp_correctness_and_batch_invariance \ tests/test_qwen_ffn.py::test_qwen_ffn_tp_sp_correctness_and_batch_invariance \ tests/test_qwen_ffn.py::test_qwen_ffn_world2_tp_sp_and_cp_match_tp1_cp1_bitwise # 3 passedPerformance results
CUDA events measure complete stripped-FFN calls. Forward samples use a
prefix-balanced cycle over all 24 execution-order permutations of legacy,
optimized, CUDA BLAS, and vLLM. Forward + backward uses the balanced six-order
cycle over the three training-capable paths. Tables and figures report median
latency; the JSON artifact retains p95/min/max and every raw sample.
Forward
Forward + backward
Layout speedup = replayed legacy / optimized. Ratios above 1 in the twoOptimized / referencecolumns mean that the reference in the denominator isfaster; they are not speedup claims for the deterministic path.
Layout-copy profile
One warmed M=128 call was captured with
torch.profiler:Full H100 report ·
Raw JSON ·
Summary CSV
Interpretation and limitations
transpose views, seeded BF16 inputs, and RL-Kernel SwiGLU as the other paths.
It measures the vendored matmul kernels, not vLLM serving.
(N,K)=(12288,4096)and(4096,12288)donot match PR #53247's BF16 tuned table. All vLLM rows therefore use the
upstream default
BM=128, BN=128, BK=64, 8 warps, 3 stages; these are notshape-tuned PR #53247 results.
Cublasas the preferred BLAS library in this environment,but
torch.matmuldoes not guarantee a specific cuBLAS algorithm.charts. Further GEMM tiling/scheduling work is separate from the layout-only
optimization in this PR.