Repository navigation
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>
8 of 13 tasks
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.
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/util/test_reduce_dbias.cu(new): checksreduce_dbiasbit for bit against a host sum in row order.Performance
One GB300 GPU, CuTeDSL backend on, this PR against its base main b9e8e57, on the same node:
bgrad_quantize)reduce_dbiasbgrad_quantize)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.
reduce_dbias, between two CUDA events.launch is enqueued. Launch overhead therefore stays outside the window.
round.
NVTE_ENABLE_CUTEDSL_BACKEND=1 NVTE_ACTIVATION_TABLE=1 python bench_quantize.py --op cast_dbias --m 4096 --n 7168 --in-dtype bf16 --fp8 e4m3 --direction both --swizzle 1 --reps 500 --warmup 20 --flush read(
--n 36864for the second row). The script is not in TE'sbenchmarks/.Testing
All on one GB300 (SM 10.3); the C++ tests were built for sm_103a.
NVTE_REPORT_IF_CUTEDSL_BACKEND_NOT_CHOSEN=ERRORtest_util --gtest_filter='*ReduceDbias*'(new)test_operatorFP8 dbias,*CastDBias*:*CastDBiasDGelu*test_operatorMXFP8 cast and dbias,*FusedCastMXFP8*:*SwizzledScalesFusedCastMXFP8*ReduceDbias512x65 and 1000x1028JAX.
Checklist: