Repository navigation
[Common] Pipeline the dbias reduction of the MXFP8 and FP8 quantize - #3852
Conversation
common::reduce_dbias sums the FP32 dbias workspace column by column for the MXFP8 quantize (CUDA and CuTeDSL backends) and the FP8 tensor-scaling quantize. It ran 256 threads per CTA with four columns each, so a 7168-column workspace got 7 CTAs, and each thread waited on one load per row. Use one thread per column, 64 per CTA. On sm_80 and newer, copy each column into shared memory with cp.async, 32 rows per stage and 4 stages deep, and add each stage once it has landed; below sm_80, load the column directly. Each column is still added in row order from 0 and rounded once, so dbias does not change. Any column count is now accepted. Add test_reduce_dbias, which checks the reduction bit for bit against that sum on the host for FP32, BF16 and FP16 output. Signed-off-by: Teddy Do <tdophung@nvidia.com>
|
I went through the pipeline maths and the test matrix; the ordering argument holds up. What I could not find in the PR is the resource side, and one coverage gap. The pipeline is correct as written. With Resource cost — worth a number in the description. Coverage gaps, both small:
One note on the test itself: comparing with |
@lxcxjxhx I can post the occupancy on the description if needed. But the above reasonging should explain why we should see where the speed up comes from. Also, about the shapes, the shapes and numbers are in the Perforrmance section in the desc, comparing between main (before merge to main that just happened) with this PR. About the row=0 case, I dont think this is a realistic case to test, as nothing calls. reduce_dibaisd with an empty workspace in practice. So it is quite unrealistic of a test. Same with sm_80, yes, we do not test it in CI because it is again an unreallistic case of users and we have limmited resource on our CI |
|
You are right on both counts and I was wrong on the shared-memory one. The 48 KB I quoted is the per-block static shared memory limit, not what an SM has. With 164 KB on Ampere and 228 KB on Hopper, 32 KB per CTA is six CTAs — and as you say, the grid is one 64-thread CTA per 64 columns, so a 7168-column workspace is 112 CTAs against 152 SMs, below one wave anyway. The occupancy number in your table (18.75% theoretical, 3.3% achieved) already said this; I read the "100% / 12.7%" column as an SM total rather than an occupancy figure and drew the wrong conclusion from it. Same for the shapes: the Performance table has both shapes with per-round medians, the round-1/round-2 split, and the SHA-256 check that dbias and the FP8 data are bit-identical. My sentence "the description doesn't say for which shapes and by how much" was wrong — it does, and more completely than most PRs. On the two coverage points, your reasoning holds and I withdraw both: an empty workspace is not a call site that exists, and pre-sm_80 is a CI resource decision, not a test gap this PR should carry. A code comment saying the Nothing left from my side. |
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryThe PR pipelines
Reviews (3) · Last reviewed commit: "Move the dbias reduction test into the c..." · Reviewed by Greptile |
Signed-off-by: Teddy Do <tdophung@nvidia.com>
|
/te-ci |
Signed-off-by: Teddy Do <tdophung@nvidia.com>
| } | ||
| stg_vec.store_to(thread_out_base); | ||
| #else | ||
| for (size_t r = 0; r < rows; ++r) acc += in[r * cols]; |
There was a problem hiding this comment.
Emmmm so do we just lose the vectorized memory load and store with < sm80? (I guess that is OK since they are old anyway?)
There was a problem hiding this comment.
yeah basically, the case for < sm_80 is just so that sm_70/75 can still compile.
kainzhong
left a comment
There was a problem hiding this comment.
I feel the new test is a bit over engineering (we have existing numeric tests and this new test feels like a specific case LLM constructs to make it bit-exact) but it probably doesn't hurt anyway.
Description
common::reduce_dbiasadds up the FP32 dbias workspace (one partial row per CTA of the quantize kernel) into thedbias vector. It serves:
quantize_mxfp8.cuh,quantize_mxfp8_cutedsl.cuh);quantize_fp8.cuh).The grouped reduction (
grouped_reduce_dbias) and the cast-transpose dbias reductions are separate kernels and do notchange.
The old kernel ran 256 threads per CTA with four columns each (two for FP32 output). A 7168-column BF16 workspace
therefore launched 7 CTAs, and each thread waited on one load per row. This PR uses one thread per column, 64
threads per CTA:
cp.async, 32 rows per stage and 4stages deep, and adds each stage once it has landed.
Each column is still added in row order from 0 and rounded once, so dbias is bit-identical to before. The
cols % nveccheck is dropped: any column count works.The change is on by default for every caller above; there is no option. It was split out of #3761.
Type of change
Changes
transformer_engine/common/cast/core/grouped_layout.cuh: the newreduce_dbias_kerneland its launch.tests/cpp/operator/test_cast_dbias.cu:CastDBiasOrderTestSuitechecks dbias bit for bit against the row-order sumof the 128-row tile sums.
sums; BF16 and FP16 mostly check the rounding. FP16 input spans 2^-24..2^13, so most of its sums stay finite and
some overflow.
its 64-thread CTA.
Performance
One GB300 GPU, CuTeDSL backend on, this PR against its base main b9e8e57, on the same node:
reduce_dbiasgrid, main -> PRbgrad_quantize)reduce_dbiasbgrad_quantize)reduce_dbiaslaunch): the reducer sees a 32 x N workspace at both shapes. The 32 KB ofshared memory per CTA caps the PR at 6 CTAs per SM, but even 576 CTAs on 152 SMs is 0.63 waves, so the cap only
binds past about 58k columns. Main's 7 / 36 CTAs leave most SMs idle, which is where the speedup comes from.
equal to the CUDA backend's.
reduce_dbias.Measurement details:
nvcr.io/nvidia/pytorch:26.10-py3, build 477939455, index digestsha256:6d347d649d5dd108b4652f1b9cea6a3c859692ac408617a9108616da40e3da1f.NVTE_FRAMEWORK=pytorch NVTE_WITH_CUTEDSL=1 NVTE_CUDA_ARCHS=100(nvcc 13.4).NVTE_ENABLE_CUTEDSL_BACKEND=1 NVTE_ACTIVATION_TABLE=1in both arms; the tables donot apply to a plain cast, and main ignores the variable. The kernels each arm launched were checked with
torch.profiler.
tex.bgrad_quantizecall with anMXFP8Quantizer(MXFP8 block scaling): BF16 input fromrandn,E4M3 output, rowwise and columnwise, GEMM-swizzled scales.
--clock-control none, on the thirdcall (after the CuTeDSL compile).
reduce_dbias, between two CUDA events.launch is enqueued. Launch overhead therefore stays outside the window.
round.
Testing
The table ran on one GB300 (SM 10.3), with the C++ tests built for sm_103a.
NVTE_REPORT_IF_CUTEDSL_BACKEND_NOT_CHOSEN=ERRORtest_operatorFP8 dbias,*CastDBias*:*CastDBiasDGelu*test_operatorMXFP8 cast and dbias,*FusedCastMXFP8*:*SwizzledScalesFusedCastMXFP8*The new
CastDBiasOrderTestSuiteran on one GB200 (SM 10.0), with the C++ tests built for sm_100a:test_operator --gtest_filter='*CastDBias*': 233 passed (CastDBiasOrder65,CastDBias84,CastDBiasDGelu84).compute-sanitizer racecheck and synccheck on
CastDBiasOrder65X80 and 512X1040: 0 hazards, 0 errors.With the reduction's adds reversed, 55 of the 65 cases fail, all in FP32: every case with 31 or more tiles. With 1
or 2 tiles there is no other order.
Lint: cpplint 1.6.0 and clang-format 18.1.6 are clean.
Not run here: the minimum-version builds (GCC 11, sm_70, where the plain-loop path compiles), the MXFP8 suites
on SM 10.0, and JAX.
Checklist: