Repository navigation
Conversation
… deadlock DeviceMesh._init_one_process_group reuses the default (WORLD) process group -- instead of creating a dedicated communicator -- for any mesh dimension (including one produced by DeviceMesh._flatten) whose ranks span every rank, unless an explicit backend_override is passed. FSDP shards parameters on dp_shard * cp. When dp_shard == 1 (the common CP-only configuration), that flattened axis spans every rank, and so does CPs own cp axis. Both silently collapsed onto the same WORLD process group / NCCL communicator. dp_replicate (pure DDP) and edp_shard (EP with no other sparse-region parallelism) have the same failure mode on their own, single-axis groups. FSDP issues its all-gather/reduce-scatter from its own dedicated CUDA streams, while CP's collectives run on the default/compute stream. Nothing orders those two streams against each other, so the two collectives can be enqueued in different host-side orders across ranks. Two collectives sharing one communicator must be posted in the same order by every rank, so a mismatched order deadlocks NCCL instead of merely serializing -- this is config-deterministic (whether the groups collide) but the deadlock itself is a scheduling race, which is why it does not reproduce on every run. Fix: give FSDP's shard/replicate axes a dedicated backend_override so they never alias the default group, whether built directly (dp_replicate, edp_shard, in ParallelismContext.build_mesh) or flattened later from multiple axes (dp_shard * cp, in resolve_fsdp_mesh). Adds a CPU regression test reproducing the dp_shard=1/cp=world_size collision and the pure-DDP dp_replicate=world_size collision.
|
Hi @zpcore! Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention. You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
This looks like a real issue but can you describe what's your settings to make this happen? I have ran CP8 and CP16 with dp_shard being 1 multiple times, I never encountered such an issue. |
|
Btw, @zpcore can you sign Meta CLA, thanks! |
|
Hi @fegin , we noticed this deadlock occasionally in training jobs. @tranle-fw is the expert working on the fix. Hi @tranle-fw, is there an easy way to reproduce the race condition? |
…ten under FSDP2's name
fully_shard validates every shard name against the storage mesh's dim
names, so passing the flattened 'dp_shard_cp' name broke all CP configs.
Keep the ('dp_shard', 'cp') tuple and pre-flatten with the same
'_'.join name FSDP2 uses so its own flatten hits the cached dedicated PG.
The unit test now goes through _validate_mesh/_get_mesh_info.
|
@tranle-fw can you provide the settings including parallelisms and hardware settings? Thanks |
|
@fegin This is race condition so it's extremely hard to reproduce. The hang happens since FSDP all-gather is scheduled on a different stream than our CP communication. This cause indeterministic ordering on the GPU kernel execution order. For example, rank0 can execute CP comm first, while rank1 can execute FSDP all-gather since there's no cross-rank order synchronization. I added a simple local repro that forces this misalignment in ordering across rank through the host. W/ shared communicator, we reproduce the deadlock issue. W/ separate pg, all ranks can complete. Simple repro: zpcore#1 |
|
Superseded by #5663, opened under |
Bug
DeviceMesh._init_one_process_groupreuses the default (WORLD) process group -- instead of creating a dedicated communicator -- for any mesh dimension (including one produced byDeviceMesh._flatten) whose ranks span every rank, as long as no explicitbackend_overrideis given.FSDP shards parameters on
dp_shard * cp. Whendp_shard == 1(a pure-CP configuration, e.g.cp == world_size), that flattened axis spans every rank -- and so does CP's owncpaxis. Both silently collapse onto the same WORLD process group / NCCL communicator.dp_replicate(pure DDP spanning the world) andedp_shard(EP with no other sparse-region parallelism) have the same failure mode on their own single axis.FSDP issues its all-gather/reduce-scatter from its own dedicated CUDA streams, while CP's collectives run on the default/compute stream. Nothing orders those two streams against each other, so the two collectives can be enqueued in different host-side orders across ranks. Two collectives sharing one communicator must be posted in the same order by every rank, so a mismatched order deadlocks NCCL instead of merely serializing. Whether the groups collide is config-deterministic, but the deadlock itself is a scheduling race -- which is why it does not reproduce on every run.
Fix
Give FSDP's shard/replicate axes a dedicated
backend_overrideso they never alias the default group:dp_replicateandedp_shardare built directly byParallelismContext.build_mesh'sunflatten_meshclosure; give them an explicit override there.dp_shard * cpis flattened later, insideresolve_fsdp_mesh, when passed tofully_shardviaDataParallelMeshDims. Pre-flatten it eagerly there with an explicit override so FSDP2's own (unoverridden) internal flatten just hits the cache we already populated.The override passed is the mesh's own already-configured backend (
dist.get_backend_config), so this only changes communicator identity, never which backend is used -- real NCCL/Gloo meshes and "fake"-backed test meshes behave the same as before, just with a dedicated communicator.Tests
Added
TestFsdpCpCommunicatorIsolationtotests/unit_tests/cpu/distributed/test_parallelism_context.py(CPU/fake-mesh, no GPU needed):test_pure_cp_fsdp_group_is_not_shared_with_cp_group:dp_shard=1, cp=4-- the historically-buggy configuration -- asserts FSDP's shard group and CP's group have differentgroup_names. Fails onmainwithAssertionError: AssertionError not raised, confirming the two groups collide today.test_pure_ddp_dp_replicate_group_is_dedicated:dp_replicate=4(pure DDP spanning the world) asserts its group differs from the default group.Ran the full existing
tests/unit_tests/cpu/distributed/suite (163 tests) to confirm no regressions.