Repository navigation
[diffusion] fix: stop reserving NCCL device buffers for single-rank groups - #35538
Merged
Merged
Conversation
…roups A single-GPU run still builds every parallel group -- DP, CFG, TP, SP, PP, VAE_DECODE, DIT, VAE, ulysses, ring -- each with one rank. None of them can ever communicate: every collective in GroupCoordinator returns early on world_size == 1, and the device communicator is only constructed above 1. But each still got an NCCL-backed process group, and NCCL sizes its per-channel device buffers up front, so each one reserved ~390 MiB that nothing could use. Give single-rank groups the gloo backend instead. Measured on an RTX 3060 12 GiB, Wan2.1-T2V-1.3B, layerwise offload, 320x576x9: free VRAM after load 6.51 GiB -> 11.06 GiB peak VRAM 11552 MiB -> 6830 MiB VAE decode OOM -> completes Before the fix 44% of the card was gone before a single weight was loaded, and decode could not run at any resolution. Output is bit-identical (same SHA-256 as an NCCL_MAX_NCHANNELS=1 control run), and per-step time is unchanged.
mickqian
requested review from
AgainstEntropy,
BBuf,
HaiShaw,
ping1jing2 and
yichiche
as code owners
August 19, 2026 14:48
Collaborator
Author
|
/tag-and-rerun-ci |
…hange Drop the now-unused torch import from parallel_groups.py, order the group_coordinator import, and name the helper in the ordering comment.
Collaborator
Author
|
/rerun-failed-ci |
1 similar comment
Collaborator
Author
|
/rerun-failed-ci |
…nk group cache-dit averages its residual-difference statistics across the TP x SP slice, using the DIT group. On a single GPU that group has one rank, so the average returns the input and the two collectives are pure overhead -- and with the group now on gloo they would stage device tensors through the host on every cached block of every step. Return the local value instead, which is what the collectives computed.
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
CI attributionEverything this change can affect is green: The red checks are pre-existing, each verified against branches that do not carry this
The NPU lane therefore cannot vet this change at the moment; the CUDA 1-GPU and 2-GPU |
This was referenced Aug 20, 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.
Motivation
On a single GPU, ~5 GiB of VRAM is gone before a single weight is loaded. On a 12 GiB consumer card that is 44% of the device, and it makes VAE decode fail at any resolution.
The cause is that a single-GPU run still builds every parallel group — DP, CFG, TP, SP, PP, VAE_DECODE, DIT, VAE, ulysses, ring — each with one rank, and each got an NCCL-backed process group. NCCL sizes its per-channel device buffers when the communicator is created, so every one of those groups reserved ~390 MiB (the first, the world group, ~470 MiB).
None of that memory can ever be used. Every collective in
GroupCoordinatorreturns early onworld_size == 1("Bypass the function if we are using only 1 GPU"), and the device communicator is only constructed whenworld_size > 1.pyncclalready skips communicator creation for single-rank groups; the underlyingtorch.distributed.new_groupdid not.Measured on an RTX 3060 12 GiB with a bare
torch.distributedrepro:new_group([0])NCCL_MAX_NCHANNELS=1drops the per-group cost to 10 MiB, which confirms these areper-channel buffers for channels a one-rank communicator can never use.
Modifications
Add
new_device_group()ingroup_coordinator.py, which gives single-rank groups the gloo backend and leaves multi-rank groups on the requested backend. Route the nine device-group creation sites through it:GroupCoordinator.__init__, thePipelineGroupCoordinatorsingle-rank branch and itsskip_device_group,_DITand_VAEinparallel_state.py, and the four ulysses/ring groups inparallel_groups.py.The two-rank
device_group_0_1/device_group_1_0pipeline pair is left alone; it is only reached when the group has exactly two ranks.One consumer needed a matching guard. cache-dit averages its residual-difference statistics across the TP x SP slice using the DIT group, and that all-reduce had no world-size check, so on a single GPU it would now stage device tensors through the host on every cached block of every step. Averaging over one rank returns the input, so the patched
similarityreturns the local value instead of running the collective.Every other consumer of these groups already short-circuits: collectives in
GroupCoordinatorreturn early onworld_size == 1, the device communicator is built only above 1, the ulysses/ring groups are reached only undersp_size > 1inattention/layer.pyand behindworld_size <= 1early returns inusp.py, and the VAE group has no consumer outside its getter.Accuracy Tests
Bit-exact. RTX 3060 12 GiB,
Wan-AI/Wan2.1-T2V-1.3B-Diffusers, layerwise offload of dit/text_encoder/vae, 320x576, 9 frames, 8 steps, seed 1234.NCCL_MAX_NCHANNELS=1control78a2a963…78a2a963…Two-GPU regression on the same box,
--num-gpus 2: patched and unpatched produce the same output, SHA-256361bb915…, so the multi-rank path is unaffected.New unit test
test_single_rank_device_group.pycovers backend selection for single-rank and multi-rank groups (3 tests, 5 subtests). Existingtest_cache_dit_integration.pypasses with the guard (12 tests together).CI note:
multimodal-gen-test-1-npu-a3is red here, but every diffusion testcase on that runner is red on unrelated branches too (see #35511, whereernie_image_t2i_1npu,flux_image_t2i_npu,flux_2_klein_4b_t2i_1npu,z_image_t2i_1npuandwan2_1_t2v_1.3b_1_npuall fail and the job ends withExecuting the custom container implementation failed). The NPU lane cannot vet this change right now.Speed Tests and Profiling
No change to per-step time — 1.10 s/step before, 1.06 s/step after, within the run-to-run noise band measured across this configuration. The groups involved never carried traffic.
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #32291208968
Latest PR Test (Extra): ❌ Run #32291208893