Exclude fake-backed axes from get_all_one_dimensional_meshes - #4068
Open
adityasingh2400 wants to merge 1 commit into
Open
Exclude fake-backed axes from get_all_one_dimensional_meshes#4068adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
With EP disabled, build_mesh unflattens the efsdp axis with the fake backend because _mesh_exist reports it as nonexistent, but its size is dp_shard * cp * tp, which is usually greater than 1. The size > 1 filter in get_all_one_dimensional_meshes therefore let a fake-backed axis through, so dense jobs logged efsdp as an active dimension and callers such as set_pg_timeouts received a fake process group. Filter on _mesh_exist as well, which is the same predicate get_optional_mesh already uses, so the two accessors now agree. Fixes pytorch#2447 Signed-off-by: Aditya Singh <adisin650@gmail.com>
adityasingh2400
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 5, 2026 12:03
|
|
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.
Fixes #2447.
get_all_one_dimensional_meshes()filters_single_axis_meshesonndim == 1 and size() > 1. That filter is not the same predicate the rest ofParallelDimsuses to decide whether an axis is live, and the gap is visible on every dense run.Root cause:
build_mesh()unflattens the sparse mesh as("pp", "dp_replicate", "efsdp", "ep")and passesbackend_override[name] = "fake"for any axis where_mesh_exist(name, degree)isFalse. Forefsdp,_mesh_existreturnsself.ep > 1, so with EP disabled the axis gets a fake process group. Its size, however, isdp_shard * cp * tp / ep, which for an ordinary dense job is greater than 1. Thesize() > 1filter therefore lets a fake-backed axis through.get_optional_mesh()does consult_mesh_exist, so todayget_optional_mesh("efsdp")returnsNonewhileget_all_one_dimensional_meshes()returns anefsdpentry for the sameParallelDims.Two consequences. The reported one is that the startup line prints
efsdpin "Successfully created meshes with active dimensions" for dense models. The one that matters more is thatset_pg_timeouts()intorchtitan/distributed/utils.pybuilds its group list straight from this accessor, so it callsmesh.get_group()on the fake axis and applies a timeout to a process group that cannot carry a collective.Repro on 2 CPU ranks with gloo,
dp_replicate=1, dp_shard=2, cp=1, tp=1, pp=1, ep=1, before the change:After:
Fix: add
self._mesh_exist(k, v.size())to the filter, which is exactly the predicateget_optional_meshalready applies, so the two accessors agree. The change is subtractive only for axes thatbuild_meshgave a fake backend.fsdpand, underfull_dtensororspmd_types,dp_shardare the axes_mesh_existkeeps alive at size 1, and they are still filtered out bysize() > 1exactly as before. For every other axis_mesh_existreduces todegree > 1, so the only behavior change is droppingefsdpwhen EP is off.Tests: added
TestOneDimensionalMeshesSkipFakeAxeswith two 8-rank cases. Withep=1theefsdpaxis has size 8 yet must not be reported, and every reported axis must have a non-fake backend. Withep=2theefsdpandepaxes must still be reported. Also updated the existingtest_world_size_8_mesh_operationsassertion that encoded the old behavior, and refreshed the docstring example and notes.Test evidence: I have no GPU and torchtitan main needs a torch nightly newer than 2.11.0 to import the test module (
torch.distributed.fsdp.DataParallelMeshDims), so I ran the two new cases as a standalone script over 8 real gloo ranks on CPU with the same assertions:blackis clean on both changed files.