[CUDA] Support bfloat16 in AllReduce, AllGather and AllToAll - #31571
Merged
Conversation
GetNcclDataType had no mapping for BFloat16, so any bf16 tensor reaching a collective failed with "Tensor type not supported in NCCL". The AllReduce kernel additionally used AllIEEEFloatTensorTypes(), which excludes BFloat16 since it is not an IEEE format, and the three op schemas did not list tensor(bfloat16). Map BFloat16 to ncclBfloat16, spell out the AllReduce kernel type constraint as float/double/float16/bfloat16, and add tensor(bfloat16) to the AllReduce, AllGather and AllToAll schemas. The AllGather and AllToAll kernels already register AllTensorTypes(), so the schema was the only thing blocking bf16 there.
tianleiwu
enabled auto-merge (squash)
August 3, 2026 18:54
nenad1002
approved these changes
Aug 3, 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.
Description
Adds bfloat16 support to the CUDA collective ops
AllReduce,AllGatherandAllToAll.Three things blocked bf16 today:
GetNcclDataTypehad noBFloat16case, so any bf16 tensor reaching a collective failed at runtime withTensor type not supported in NCCL. Now mapped toncclBfloat16.AllReduceCUDA kernel usedDataTypeImpl::AllIEEEFloatTensorTypes(), which excludesBFloat16because bf16 is not an IEEE format. Replaced with an explicitfloat/double/MLFloat16/BFloat16list.tensor(bfloat16). Added to all three. Note that theAllGatherandAllToAllkernels already registerDataTypeImpl::AllTensorTypes(), so for those two the schema was the only thing rejecting bf16 — no kernel change was needed.Motivation and Context
bf16 is the native dtype of most current LLMs, so a tensor-parallel graph built from one is bf16 end to end. Hitting an fp32-or-fp16-only
AllReduceat every layer boundary forces either a cast pair around each collective (extra kernels and bandwidth on the critical path, twice per layer) or exporting the whole model in fp16.This came up while bringing up a tensor-parallel + expert-parallel DeepSeek-V4 export on 8×H200, where each of the 43 layers issues two
AllReduceon bf16 activations.Testing
Validated end to end rather than by unit test, since the distributed collective tests require a multi-GPU host and are opt-in:
AllReduceper layer × 43 layers, producing correct token sequences.Happy to add a bf16 case to the existing distributed collective test if reviewers would like it in this PR.
Note for reviewers
ncclBfloat16requires NCCL ≥ 2.10 (mid-2021). CMake currently only version-checks NCCL for theUSE_NCCL_P2Pdefine (≥ 2.7) and does not enforce a floor, so in principle a build against NCCL 2.7–2.9 would now fail to compile this file. Every CUDA 12/13 toolchain ships far newer NCCL, so I left it unguarded rather than adding#if NCCL_VERSION_CODE >= NCCL_VERSION(2,10,0)clutter — but let me know if you would prefer the guard or a hard CMake floor.