Skip to content

[diffusion] fix: stop reserving NCCL device buffers for single-rank groups - #35538

Merged
mickqian merged 3 commits into
sgl-project:mainfrom
mickqian:fix/single-rank-nccl-vram
Aug 20, 2026
Merged

mickqian merged 3 commits into
sgl-project:mainfrom
mickqian:fix/single-rank-nccl-vram

Conversation

@mickqian

@mickqian mickqian commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 GroupCoordinator returns early on world_size == 1 ("Bypass the function if we are using only 1 GPU"), and the device communicator is only constructed when world_size > 1. pynccl already skips communicator creation for single-rank groups; the underlying torch.distributed.new_group did not.

Measured on an RTX 3060 12 GiB with a bare torch.distributed repro:

device memory
CUDA context only 114 MiB
+ world group 584 MiB
each additional new_group([0]) +388 MiB

NCCL_MAX_NCHANNELS=1 drops the per-group cost to 10 MiB, which confirms these are
per-channel buffers for channels a one-rank communicator can never use.

Modifications

Add new_device_group() in group_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__, thePipelineGroupCoordinator single-rank branch and its skip_device_group, _DIT and _VAE in parallel_state.py, and the four ulysses/ring groups in parallel_groups.py.

The two-rank device_group_0_1 / device_group_1_0 pipeline 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 similarity returns the local value instead of running the collective.

Every other consumer of these groups already short-circuits: collectives in GroupCoordinator return early on world_size == 1, the device communicator is built only above 1, the ulysses/ring groups are reached only under sp_size > 1 in attention/layer.py and behind world_size <= 1 early returns in usp.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.

free VRAM after load peak VRAM VAE decode output SHA-256
before 6.51 GiB 11552 MiB OOM no output produced
NCCL_MAX_NCHANNELS=1 control 11.31 GiB 6886 MiB ok 78a2a963…
this PR 11.06 GiB 6830 MiB ok 78a2a963…

Two-GPU regression on the same box, --num-gpus 2: patched and unpatched produce the same output, SHA-256 361bb915…, so the multi-rank path is unaffected.

New unit test test_single_rank_device_group.py covers backend selection for single-rank and multi-rank groups (3 tests, 5 subtests). Existing test_cache_dit_integration.py passes with the guard (12 tests together).

CI note: multimodal-gen-test-1-npu-a3 is red here, but every diffusion testcase on that runner is red on unrelated branches too (see #35511, where ernie_image_t2i_1npu, flux_image_t2i_npu, flux_2_klein_4b_t2i_1npu, z_image_t2i_1npu and wan2_1_t2v_1.3b_1_npu all fail and the job ends with Executing 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

…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

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR labels Aug 19, 2026
…hange

Drop the now-unused torch import from parallel_groups.py, order the
group_coordinator import, and name the helper in the ordering comment.
@mickqian

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@mickqian

Copy link
Copy Markdown
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.
@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@mickqian

Copy link
Copy Markdown
Collaborator Author

CI attribution

Everything this change can affect is green: lint, multimodal-gen-unit-test,
multimodal-gen-component-accuracy, multimodal-gen-test-1-gpu (5 shards),
multimodal-gen-test-2-gpu (3 shards), multimodal-gen-test-1-b200,
multimodal-gen-test-1-5090, bcg-diffusion, diffusion-coverage-check, and on the
AMD side multimodal-gen-unit-test-amd-rocm720 and multimodal-gen-test-1-gpu-amd-rocm720 (0).

The red checks are pre-existing, each verified against branches that do not carry this
change:

check why it is red
call-gate / pr-gate (x2), pr-test-extra-finish, pr-test-amd-extra-finish the failing step is Require run-ci-extra label (optional); this PR has no run-ci-extra label. Same red on #35511 and #35468.
multimodal-gen-test-1-npu-a3, pr-test-npu-finish every diffusion testcase on that runner fails on unrelated branches too. On #35511: ernie_image_t2i_1npu, flux_image_t2i_npu, flux_2_klein_4b_t2i_1npu, z_image_t2i_1npu and wan2_1_t2v_1.3b_1_npu all fail, ending with Executing the custom container implementation failed.
multimodal-gen-test-2-gpu-amd-rocm720 already red on main: runs 32166850277 (08-18) and 32051441289 (08-17) fail all three shards at the same Run diffusion server tests (2-GPU) step with the same multi-hour runtime.

The NPU lane therefore cannot vet this change at the moment; the CUDA 1-GPU and 2-GPU
lanes can and do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant