Skip to content

[distributed] Add fake and real-PP/fake-SPMD backends - #4652

Merged
sanketpurandare merged 1 commit into
mainfrom
gh/sanketpurandare/33/head
Sep 26, 2026
Merged

sanketpurandare merged 1 commit into
mainfrom
gh/sanketpurandare/33/head

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary:
Add two explicit debugging backends without pretending fake communication can
replace a real distributed run.

comm.backend="fake" uses one physical process and fake groups for every axis.
NGPU defines the logical world, FAKE_PP_RANK selects the represented PP
coordinate, and the logical SPMD coordinate is always zero.

comm.backend="real_pp_fake_spmd" requires exactly one physical process per PP
rank. Physical RANK selects the PP coordinate, a real NCCL PP group carries
pipeline traffic, and DP, TP, CP, and EP remain fake at SPMD coordinate zero.
FAKE_PP_RANK is rejected in this mode.

Initialization returns a DistributedTopology containing the logical world
size and an optional real_pp_group_for_fake_spmd. The explicit field name
prevents this hybrid-only group from being mistaken for the ordinary PP group
used by fully real distributed execution. ParallelDims replaces only the
outermost PP mesh. The deliberately PP-specific contract keeps the
implementation small while supporting local debugging of stage metadata,
send/receive ownership, whole-step CUDA graphs, and rank-local memory for large
logical configurations.

Test Plan:

  • python -m pytest -q tests/unit_tests/cpu/test_distributed_utils.py tests/unit_tests/cpu/test_parallel_dims.py tests/unit_tests/cpu/test_torchft_trainer.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_integration_test_definitions.py (114 passed)
  • Scoped formatting, lint, codespell, and link checks passed.
  • Targeted Pyrefly reported 0 errors for production files; the broader TorchFT file retains an unrelated existing config-override error.
  • One-process pure fake and four-process real-PP/fake-SPMD each completed 10 PP4 steps with CUDA-graph replay.
  • After the topology-field rename, one-process pure fake and two-process
    real-PP/fake-SPMD PP2 smoke runs completed successfully.

Comment thread docs/debugging.md Outdated
`NGPU / P` flattened SPMD coordinates. The selected logical global rank is:

```text
logical_rank = FAKE_PP_RANK * (NGPU / P) + FAKE_SPMD_RANK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is assuming PP is always the outermost mesh -- is it always true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the asumption

Comment thread torchtitan/config/configs.py Outdated
mode: Literal["default", "fake_backend"] = "default"
"""
Communication mode for distributed training.
mode: Literal["default", "fake_backend", "real_pp_fake_spmd_backend"] = "default"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mode: Literal["default", "fake_backend", "real_pp_fake_spmd_backend"] = "default"
backend: Literal["default", "fake", "real_pp_fake_spmd"] = "default"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread docs/debugging.md Outdated
NGPU=32 COMM_MODE="fake_backend" ./run_train.sh
| Mode | Physical processes | Real communication | Use it to validate |
| --- | --- | --- | --- |
| `fake_backend` | One | None | Configuration, logical mesh construction, rank-local model ownership, tensor shapes, and PyTorch-managed memory for one selected logical rank. |

@tianyu-l tianyu-l Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work with PP, couldn't find any documentation.

If it doesn't, I don't see a reason to keep two different backends for them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consolidated the backend

Comment thread torchtitan/distributed/parallel_dims.py Outdated
Comment on lines +282 to +283
for axis, group in self._real_axis_groups
if axis == MeshAxisName.PP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusing -- is this PP specific? What if I specify DP in _real_axis_groups what happens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it is restricted to PP

Comment thread docs/debugging.md
# Validate a 128-GPU configuration on a single GPU
NGPU=128 COMM_MODE="fake_backend" MODULE=llama3 CONFIG=llama3_70b ./run_train.sh
NGPU=4 \
FAKE_PP_RANK=1 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we set different FAKE_PP_RANK on different device? How?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For pure fake mode there is one physical process, and FAKE_PP_RANK selects the single logical PP coordinate that process represents. For real_pp_fake_spmd, do not set FAKE_PP_RANK: torchrun launches exactly pp_degree processes and each physical RANK is its PP coordinate. The implementation now rejects FAKE_PP_RANK in hybrid mode, fixes the SPMD coordinate at zero, and documents both launch forms explicitly.

@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Sep 23, 2026
sanketpurandare added a commit that referenced this pull request Sep 24, 2026
…ecution"

TorchTitan's eager pipeline runtime needs deterministic, precomputed contracts
before warmup: stage-boundary metadata, receive-buffer ownership, P2P topology,
and the maximum number of simultaneously unsharded local stages. Dynamic
metadata exchange or runtime buffer allocation prevents FakePG execution and
makes whole-step CUDA-graph capture difficult to reason about.

Wire the existing PyTorch pipelining facilities into TorchTitan:

- enable schedule-derived directed-edge P2P groups whenever pipeline
  parallelism is active;
- enable deterministic receive-buffer recycling for looped schedules;
- construct complete static decoder stage I/O metadata when the PP group is
  fake, failing clearly when a custom split cannot be represented;
- pass the configurable local-stage parameter-residency bound to the schedule;
- carry a fixed upper bound for varlen document metadata.

Directed P2P groups, receive-buffer reuse, and metadata selection are runtime
invariants, not user policy knobs. Their groups and assignments are finalized
before warmup; execution does not poll, recolor storage, or mutate the
schedule. The only public memory-policy knob added here is
`pipeline_parallel_max_param_unsharded_stages`.

This PR consumes a fake PP group when distributed initialization supplies one;
it does not define the fake or real-PP/fake-SPMD launch modes. Those topology
and launch contracts are introduced independently in #4652. Looped-schedule
CUDA-graph enablement is isolated in #4591.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_varlen_attention.py`
- Stack-level one-GPU pure-FakePG PP and four-GPU real-PP/fake-SPMD execution
  with repeated full CUDA-graph replay.

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Sep 24, 2026
TorchTitan's eager pipeline runtime needs deterministic, precomputed contracts
before warmup: stage-boundary metadata, receive-buffer ownership, P2P topology,
and the maximum number of simultaneously unsharded local stages. Dynamic
metadata exchange or runtime buffer allocation prevents FakePG execution and
makes whole-step CUDA-graph capture difficult to reason about.

Wire the existing PyTorch pipelining facilities into TorchTitan:

- enable schedule-derived directed-edge P2P groups whenever pipeline
  parallelism is active;
- enable deterministic receive-buffer recycling for looped schedules;
- construct complete static decoder stage I/O metadata when the PP group is
  fake, failing clearly when a custom split cannot be represented;
- pass the configurable local-stage parameter-residency bound to the schedule;
- carry a fixed upper bound for varlen document metadata.

Directed P2P groups, receive-buffer reuse, and metadata selection are runtime
invariants, not user policy knobs. Their groups and assignments are finalized
before warmup; execution does not poll, recolor storage, or mutate the
schedule. The only public memory-policy knob added here is
`pipeline_parallel_max_param_unsharded_stages`.

This PR consumes a fake PP group when distributed initialization supplies one;
it does not define the fake or real-PP/fake-SPMD launch modes. Those topology
and launch contracts are introduced independently in #4652. Looped-schedule
CUDA-graph enablement is isolated in #4591.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_varlen_attention.py`
- Stack-level one-GPU pure-FakePG PP and four-GPU real-PP/fake-SPMD execution
  with repeated full CUDA-graph replay.

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Sep 25, 2026
TorchTitan's eager pipeline runtime needs deterministic, precomputed contracts
before warmup: stage-boundary metadata, receive-buffer ownership, P2P topology,
and the maximum number of simultaneously unsharded local stages. Dynamic
metadata exchange or runtime buffer allocation prevents FakePG execution and
makes whole-step CUDA-graph capture difficult to reason about.

Wire the existing PyTorch pipelining facilities into TorchTitan:

- enable schedule-derived directed-edge P2P groups whenever pipeline
  parallelism is active;
- enable deterministic receive-buffer recycling for looped schedules;
- construct complete static decoder stage I/O metadata when the PP group is
  fake, failing clearly when a custom split cannot be represented;
- pass the configurable local-stage parameter-residency bound to the schedule;
- carry a fixed upper bound for varlen document metadata.

Directed P2P groups, receive-buffer reuse, and metadata selection are runtime
invariants, not user policy knobs. Their groups and assignments are finalized
before warmup; execution does not poll, recolor storage, or mutate the
schedule. The only public memory-policy knob added here is
`pipeline_parallel_max_param_unsharded_stages`.

This PR consumes a fake PP group when distributed initialization supplies one;
it does not define the fake or real-PP/fake-SPMD launch modes. Those topology
and launch contracts are introduced independently in #4652. Looped-schedule
CUDA-graph enablement is isolated in #4591.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_varlen_attention.py`
- Stack-level one-GPU pure-FakePG PP and four-GPU real-PP/fake-SPMD execution
  with repeated full CUDA-graph replay.

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Sep 25, 2026
…ecution"

TorchTitan's eager pipeline runtime needs deterministic, precomputed contracts
before warmup: stage-boundary metadata, receive-buffer ownership, P2P topology,
and the maximum number of simultaneously unsharded local stages. Dynamic
metadata exchange or runtime buffer allocation prevents FakePG execution and
makes whole-step CUDA-graph capture difficult to reason about.

Wire the existing PyTorch pipelining facilities into TorchTitan:

- enable schedule-derived directed-edge P2P groups whenever pipeline
  parallelism is active;
- enable deterministic receive-buffer recycling for looped schedules;
- construct complete static decoder stage I/O metadata when the PP group is
  fake, failing clearly when a custom split cannot be represented;
- pass the configurable local-stage parameter-residency bound to the schedule;
- carry a fixed upper bound for varlen document metadata.

Directed P2P groups, receive-buffer reuse, and metadata selection are runtime
invariants, not user policy knobs. Their groups and assignments are finalized
before warmup; execution does not poll, recolor storage, or mutate the
schedule. The only public memory-policy knob added here is
`pipeline_parallel_max_param_unsharded_stages`.

This PR consumes a fake PP group when distributed initialization supplies one;
it does not define the fake or real-PP/fake-SPMD launch modes. Those topology
and launch contracts are introduced independently in #4652. Looped-schedule
CUDA-graph enablement is isolated in #4591.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_varlen_attention.py`
- Stack-level one-GPU pure-FakePG PP and four-GPU real-PP/fake-SPMD execution
  with repeated full CUDA-graph replay.

[ghstack-poisoned]
sanketpurandare added a commit that referenced this pull request Sep 25, 2026
TorchTitan's eager pipeline runtime needs deterministic, precomputed contracts
before warmup: stage-boundary metadata, receive-buffer ownership, P2P topology,
and the maximum number of simultaneously unsharded local stages. Dynamic
metadata exchange or runtime buffer allocation prevents FakePG execution and
makes whole-step CUDA-graph capture difficult to reason about.

Wire the existing PyTorch pipelining facilities into TorchTitan:

- enable schedule-derived directed-edge P2P groups whenever pipeline
  parallelism is active;
- enable deterministic receive-buffer recycling for looped schedules;
- construct complete static decoder stage I/O metadata when the PP group is
  fake, failing clearly when a custom split cannot be represented;
- pass the configurable local-stage parameter-residency bound to the schedule;
- carry a fixed upper bound for varlen document metadata.

Directed P2P groups, receive-buffer reuse, and metadata selection are runtime
invariants, not user policy knobs. Their groups and assignments are finalized
before warmup; execution does not poll, recolor storage, or mutate the
schedule. The only public memory-policy knob added here is
`pipeline_parallel_max_param_unsharded_stages`.

This PR consumes a fake PP group when distributed initialization supplies one;
it does not define the fake or real-PP/fake-SPMD launch modes. Those topology
and launch contracts are introduced independently in #4652. Looped-schedule
CUDA-graph enablement is isolated in #4591.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_pipeline_parallel.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_varlen_attention.py`
- Stack-level one-GPU pure-FakePG PP and four-GPU real-PP/fake-SPMD execution
  with repeated full CUDA-graph replay.

[ghstack-poisoned]
@sanketpurandare sanketpurandare changed the title [distributed] Add fake and hybrid topologies [distributed] Add fake and real-PP/fake-SPMD backends Sep 25, 2026

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address comments

Comment thread torchtitan/training_engine.py Outdated
Comment on lines 214 to 216
@@ -216,12 +216,13 @@ def _initialize_distributed_runtime(self) -> None:
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are sending pipeline_parallel_degree to dist_utils.init_distributed, please put this code into the function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this into the lower P2P-owning PR (#4540). init_distributed() now accepts pipeline_parallel_degree and sets torch.distributed.config.pipeline_per_edge_p2p before process-group initialization; both the standard and TorchFT training engines pass their configured degree. #4652 now only reuses the existing argument to construct the real-PP/fake-SPMD topology.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this into the lower P2P-owning PR (#4540). init_distributed() now accepts pipeline_parallel_degree and sets torch.distributed.config.pipeline_per_edge_p2p before process-group initialization; both the standard and TorchFT training engines pass their configured degree. #4652 now only reuses the existing argument to construct the real-PP/fake-SPMD topology.

Comment thread torchtitan/distributed/parallel_dims.py Outdated
"""

world_size: int
real_pp_group: dist.ProcessGroup | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's only used for "real_pp_fake_spmd", we should give it a more precise name, e.g.

Suggested change
real_pp_group: dist.ProcessGroup | None = None
real_pp_group_for_fake_spmd: dist.ProcessGroup | None = None

to not confuse with real pp real spmd

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +282 to +286
pp_mesh = DeviceMesh.from_group(
pp_group,
device_type,
mesh_dim_names=(MeshAxisName.PP.value,),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this saying that

  • if backend is fake spmd (real pp or not), init_fake_mode will be used and consequently the DeviceMesh will be first created on fake groups (including PP axis)
  • and then we substitute a real PP group into this "fake" mesh

the code is a bit hacky but seems fine for now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. In hybrid mode, initialization creates the complete logical SPMD mesh on fake groups and separately creates a real one-dimensional PP group. ParallelDims then exposes that real PP DeviceMesh only for the outer PP axis; it does not mutate or substitute a group inside the fake multi-axis mesh. All DP, TP, CP, and EP meshes remain fake at SPMD coordinate zero. I renamed the field to real_pp_group_for_fake_spmd to make this restricted ownership explicit.

sanketpurandare added a commit that referenced this pull request Sep 26, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #4543
* #4542
* #4541
* #4623
* #4559
* #4652
* #4591
* #4592
* __->__ #4540

Summary:
Give eager pipeline stages complete static decoder-boundary metadata
when the
PP process group is fake. This avoids dynamic cross-rank metadata
inference
while preserving PyTorch's existing `PipelineStage` ownership and
supports
first, middle, and last decoder stages across context and tensor
parallelism.

TorchTitan also enables PyTorch's schedule-derived per-edge P2P groups
whenever
pipeline parallelism is active. Each directed physical edge receives a
deterministic communicator FIFO that PyTorch initializes before
execution and
CUDA-graph capture, avoiding dependency on NCCL first-use ordering.

Receive buffers use PyTorch's landed just-in-time allocation. A buffer
is
allocated immediately before `RECV_F` or `RECV_B`, transferred to the
owning
forward or backward computation, and released according to tensor
lifetime.
CUDA-graph capture records stable addresses, so replay does not repeat
Python
allocation. TorchTitan adds no receive-buffer policy or stage subclass.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_no_new_cli_options.py
tests/unit_tests/cpu/test_pipeline_parallel.py
tests/unit_tests/cpu/test_config_manager.py` (79 passed)
- Scoped pre-commit hooks passed for the changed files.
- Targeted Pyrefly reported 0 errors for production files.
- One-process pure-FakePG PP4 and four-process real-PP/fake-SPMD PP4
each completed 10 steps, captured at step 3, and replayed through step
10.
sanketpurandare added a commit that referenced this pull request Sep 26, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #4543
* #4542
* #4541
* #4623
* #4559
* #4652
* __->__ #4591
* #4592

Summary:
Allow TorchTitan's whole-step CUDA-graph wrapper to capture every
pipeline
schedule, including Interleaved1F1B, InterleavedZeroBubble,
ZBVZeroBubble, and
custom runtime schedules loaded from CSV.

The pipeline schedule is invoked as one captured callable. During
capture,
Python executes the complete schedule: `BACKWARD_INPUT` creates the
per-microbatch weight-backward runner and `BACKWARD_WEIGHT` consumes it
later
in that same invocation. Replay launches the resulting CUDA graph
directly;
it does not re-enter the Python scheduler and therefore does not need to
recreate or consume that Python state. The earlier split-backward
rejection
mistook state needed while constructing the captured graph for state
needed
during replay.

The PyTorch pipeline dependencies already provide the other required
runtime
contracts. Receive buffers are allocated just in time and their captured
addresses are stable on replay. Directed physical pipeline edges use
preinitialized process groups, giving NCCL operations a stable
communicator
and FIFO order during eager warmup, capture, and replay. TorchTitan
therefore
does not need schedule-specific CUDA-graph policy or another user-facing
configuration option.

This change removes the InterleavedZeroBubble and ZBVZeroBubble
validation
gate, switches all three split-backward integration recipes (including
the
custom CSV schedule) to TorchTitan's existing varlen attention backend,
and
enables their real-PP integration entries. Varlen uses tensor metadata
and
therefore composes with split backward; the recipes do not exercise
FlexAttention. The change does not alter pipeline actions,
split-backward
ownership, receive-buffer policy, or PyTorch schedule implementation.

Numerical investigation:

- A single distributed launch used the same initialized deterministic
MLP on
each rank, identical inputs, fixed parameters, and stable gradient
buffers. For
Interleaved1F1B, InterleavedZeroBubble, and ZBVZeroBubble, loss and
every
local parameter gradient were bitwise equal for all 10 comparisons: two
  eager warmups, capture at step 3, and seven replays.
- The same-state Llama 3 varlen runs produced bitwise-equal loss for all
10
comparisons on all three schedules. Small raw-gradient differences also
occurred during the eager warmups, with the Interleaved1F1B control, and
in
  non-pipeline SDC replay. The largest observed differences were
`3.8147e-06` for the PP4 runs and `7.62939e-06` for PP2 ZBV. This
isolates
the difference to varlen backward repeatability rather than random model
  initialization, split backward, or CUDA-graph replay.
- FlexAttention is not used by these split-backward recipes. Compiled
FlexAttention independently rejects split backward's
`retain_graph=True`,
while its uncompiled math path is not CUDA-graph capturable; neither
issue
  is introduced or hidden by this change.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_config_manager.py` (49
passed)
- `python -m pytest -q
tests/unit_tests/cpu/test_integration_test_definitions.py` (15 passed)
- Four-GPU same-state Interleaved1F1B deterministic MLP: exact loss and
every
  local gradient for 10/10 steps.
- Four-GPU same-state InterleavedZeroBubble deterministic MLP: exact
loss and
  every local gradient for 10/10 steps.
- Two-GPU same-state ZBVZeroBubble deterministic MLP: exact loss and
every
  local gradient for 10/10 steps.
- Four-GPU Llama 3 varlen Interleaved1F1B and InterleavedZeroBubble, and
two-GPU Llama 3 varlen ZBVZeroBubble: capture at step 3 and replay
through
  step 10; loss was bitwise equal for 10/10 same-state comparisons.
- Two-GPU Llama 3 varlen custom CSV split-backward schedule completed 10
steps,
  with capture at step 3 and replay through step 10.
- Non-pipeline Llama 3 varlen SDC replay reproduced the raw-gradient
  nondeterminism at step 1; the existing deterministic FlexAttention SDC
  control completed successfully.
Summary:
Add two explicit debugging backends without pretending fake communication can
replace a real distributed run.

`comm.backend="fake"` uses one physical process and fake groups for every axis.
`NGPU` defines the logical world, `FAKE_PP_RANK` selects the represented PP
coordinate, and the logical SPMD coordinate is always zero.

`comm.backend="real_pp_fake_spmd"` requires exactly one physical process per PP
rank. Physical `RANK` selects the PP coordinate, a real NCCL PP group carries
pipeline traffic, and DP, TP, CP, and EP remain fake at SPMD coordinate zero.
`FAKE_PP_RANK` is rejected in this mode.

Initialization returns a `DistributedTopology` containing the logical world
size and an optional `real_pp_group_for_fake_spmd`. The explicit field name
prevents this hybrid-only group from being mistaken for the ordinary PP group
used by fully real distributed execution. `ParallelDims` replaces only the
outermost PP mesh. The deliberately PP-specific contract keeps the
implementation small while supporting local debugging of stage metadata,
send/receive ownership, whole-step CUDA graphs, and rank-local memory for large
logical configurations.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_distributed_utils.py tests/unit_tests/cpu/test_parallel_dims.py tests/unit_tests/cpu/test_torchft_trainer.py tests/unit_tests/cpu/test_config_manager.py tests/unit_tests/cpu/test_no_new_cli_options.py tests/unit_tests/cpu/test_integration_test_definitions.py` (114 passed)
- Scoped formatting, lint, codespell, and link checks passed.
- Targeted Pyrefly reported 0 errors for production files; the broader TorchFT file retains an unrelated existing config-override error.
- One-process pure fake and four-process real-PP/fake-SPMD each completed 10 PP4 steps with CUDA-graph replay.
- After the topology-field rename, one-process pure fake and two-process
  real-PP/fake-SPMD PP2 smoke runs completed successfully.

ghstack-source-id: ac40597
Pull Request resolved: #4652
@sanketpurandare
sanketpurandare force-pushed the gh/sanketpurandare/33/head branch from 8faf7df to 31af556 Compare September 26, 2026 18:36
@sanketpurandare
sanketpurandare changed the base branch from gh/sanketpurandare/33/base to main September 26, 2026 18:37
@sanketpurandare
sanketpurandare merged commit 5bcf105 into main Sep 26, 2026
10 checks passed
sanketpurandare added a commit that referenced this pull request Sep 26, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #4543
* #4542
* #4541
* #4623
* __->__ #4559
* #4652
* #4591
* #4592

Summary:
Implement eager FullAC through a selective-checkpoint context whose
policy
prefers recomputation for ordinary operations. PyTorch upgrades
cacheable
registered effects to `MUST_SAVE`, so effectful model operations execute
once
while pure tensor operations retain full-recomputation behavior.

Non-selective FullAC has no per-operation preservation hook. Reusing
PyTorch's
selective-checkpoint machinery supplies that hook without duplicating
its
effect classification. GraphTrainer needs no change here: current
TorchTitan
already invokes `force_save_effectful_ops()` before graph
rematerialization.

Test Plan:
- `python -m pytest -q
tests/unit_tests/gpu/test_activation_checkpoint.py::TestApplyAC::test_full_ac_does_not_recompute_registered_effects`
(1 passed)
- `python -m pytest -q
torchtitan/experiments/graph_trainer/tests/test_passes.py -k
effectful_ops_are_saved_and_not_rematerialized` (1 passed)
- Scoped pre-commit hooks passed for the changed files.
- Targeted Pyrefly reported 0 errors for the production module.
sanketpurandare added a commit that referenced this pull request Sep 26, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0)
(oldest at bottom):
* #4543
* #4542
* #4541
* __->__ #4623
* #4559
* #4652
* #4591
* #4592

Summary:
Let `RoutedExperts.Config` own an optional `output_postprocess`
`Module.Config`
that transforms each expert output after W2 and before dispatcher
combine. The
name is unambiguous within `RoutedExperts`, while the module-based
contract
supports learned route-wise operations such as MS post-expert RMSNorm
and keeps
their parameters in the module state, checkpoint, optimizer, and FSDP
ownership
tree.

The default remains `None`, so existing models retain the same execution
path.
Communication-owning expert backends can translate supported modules to
their
native fused descriptors and reject unsupported modules during
conversion.

Test Plan:
- `python -m pytest -q tests/unit_tests/cpu/test_moe.py`
- `pre-commit run --files torchtitan/models/common/moe.py
tests/unit_tests/cpu/test_moe.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants