Repository navigation
add support for simplefsdp+ep - #1529
Conversation
058cf25 to
407f5f8
Compare
407f5f8 to
63eec2d
Compare
97bb837 to
273e7b4
Compare
b1d2def to
f194b2c
Compare
Yes, it's turned on here: ; The only problem now is with AC+SimpleFSDP+EP, which has some HOP mutation errors. |
|
AC HOP doesn't allow mutations in it, what are you wrapping in AC for this configuration? if you apply ac to attention and moe experts separately, we can rewrite the buffer mutation to happen outside of moe |
|
I tried SAC in the default torchtitan wrapping setting. I'm working on a refactor of this PR. I can try wrapping AC separately later and hand to you to check the mutation errors? |
|
The log for AC mutation error is: Note: |
8696988 to
6e37735
Compare
|
I was able to address most of @tianyu-l's comment, except for |
7513799 to
ae8cee7
Compare
tianyu-l
left a comment
There was a problem hiding this comment.
As discussed offline, I would recommend:
- supporting nested
data_parallelcall but relies on altered FSDP module name instead of device mesh name, which is not reliable. - supporting gradient divisor via a custom subclass of
Partial. This can be done in a separate PR.
ae8cee7 to
4605581
Compare
4605581 to
f14a8a7
Compare
There was a problem hiding this comment.
let's
- not change the name of this function
- include SimpleFSDP + EP composability tests for deepseek v3, e.g. you can consider these two https://github.com/pytorch/torchtitan/blob/main/tests/integration_tests/models.py#L47-L79
There was a problem hiding this comment.
sounds good. added new test for FSDP+EP/FSDP+EP+TP/FSDP+EP+ETP.
I skipped PP since I found both 1F1B and Interleaved1F1B doesn't compose well with EP+TP. The following PP enablement all work in eager mode. However, after adding compile, I hit some errors.
Here are some explorations (I will also add to PR summary). I didn't do a in-depth debugging, but most of them seems to be related to dynamic shapes lolll.
- SimpleFSDP + PP (1F1B) + TP + compile: works
- SimpleFSDP + PP (1F1B) + EP + compile: failed with error below (Tlparse Link)
Details
[rank0]:[titan] 2025-09-29 21:51:23,835 - root - INFO - Training starts at step 1
[rank0]:/home/ruisizhang123/pytorch/torch/distributed/device_mesh.py:321: UserWarning: You are attempting to slice a submesh from another submesh. While we support this operation, it is users' responsibility to ensure that the submesh is consistently sliced across all ranks. If not, this may result in some ranks receiving the submesh while others encounter errors.
[rank0]: warnings.warn(
[rank0]:/home/ruisizhang123/pytorch/torch/distributed/device_mesh.py:321: UserWarning: You are attempting to slice a submesh from another submesh. While we support this operation, it is users' responsibility to ensure that the submesh is consistently sliced across all ranks. If not, this may result in some ranks receiving the submesh while others encounter errors.
[rank0]: warnings.warn(
[rank0]:[rank0]:W0929 21:51:27.582000 1518045 torch/_logging/_internal.py:1199] [0/0]
[rank0]:[rank0]:W0929 21:51:27.582000 1518045 torch/_logging/_internal.py:1199] [0/0] Detected that context_fn is passed to torch.utils.checkpoint under torch.compile.
[rank0]:[rank0]:W0929 21:51:27.582000 1518045 torch/_logging/internal.py:1199] [0/0] Please make sure the checkpointed region does not contain in-place ops (e.g. torch.relu).
[rank0]:[rank0]:W0929 21:51:27.582000 1518045 torch/_logging/_internal.py:1199] [0/0]
[rank0]:/home/ruisizhang123/pytorch/torch/_inductor/lowering.py:2004: UserWarning: Torchinductor does not support code generation for complex operators. Performance may be worse than eager.
[rank0]: warnings.warn(
[rank0]:[rank0]: Traceback (most recent call last):
[rank0]:[rank0]: File "", line 198, in _run_module_as_main
[rank0]:[rank0]: File "", line 88, in _run_code
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/train.py", line 671, in
[rank0]:[rank0]: trainer.train()
[rank0]:[rank0]: ~~~~~~~~~~~~~^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/elastic/multiprocessing/errors/init.py", line 357, in wrapper
[rank0]:[rank0]: return f(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/train.py", line 596, in train
[rank0]:[rank0]: self.train_step(data_iterator)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/train.py", line 496, in train_step
[rank0]:[rank0]: loss = self.forward_backward_step(input_dict, labels)
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/train.py", line 445, in forward_backward_step
[rank0]:[rank0]: self.pp_schedule.step(
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~~~~~~^
[rank0]:[rank0]: inputs,
[rank0]:[rank0]: ^^^^^^^
[rank0]:[rank0]: ...<3 lines>...
[rank0]:[rank0]: input_batch=inputs,
[rank0]:[rank0]: ^^^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: )
[rank0]:[rank0]: ^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/pipelining/schedules.py", line 624, in step
[rank0]:[rank0]: self._step_microbatches(args_split, kwargs_split, targets_split, losses)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/pipelining/schedules.py", line 839, in _step_microbatches
[rank0]:[rank0]: self._initialize_stage(arg_mbs[0], kwarg_mbs[0])
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/pipelining/schedules.py", line 583, in _initialize_stage
[rank0]:[rank0]: self._stage._prepare_forward_infra(self._n_microbatches, args, kwargs)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/pipelining/stage.py", line 1510, in _prepare_forward_infra
[rank0]:[rank0]: outputs = self._shape_inference(args, kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/distributed/pipelining/stage.py", line 1441, in _shape_inference
[rank0]:[rank0]: outputs = self.submod(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_dynamo/eval_frame.py", line 418, in call
[rank0]:[rank0]: return super().call(*args, **kwargs)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/nn/modules/module.py", line 1777, in _wrapped_call_impl
[rank0]:[rank0]: return self._call_impl(*args, **kwargs)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/nn/modules/module.py", line 1788, in _call_impl
[rank0]:[rank0]: return forward_call(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_dynamo/eval_frame.py", line 886, in compile_wrapper
[rank0]:[rank0]: return fn(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/nn/modules/module.py", line 1777, in _wrapped_call_impl
[rank0]:[rank0]: return self._call_impl(*args, **kwargs)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/nn/modules/module.py", line 1788, in _call_impl
[rank0]:[rank0]: return forward_call(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/models/deepseek_v3/model/model.py", line 363, in forward
[rank0]:[rank0]: def forward(
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_dynamo/eval_frame.py", line 1098, in _fn
[rank0]:[rank0]: return fn(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/aot_autograd.py", line 1134, in forward
[rank0]:[rank0]: return compiled_fn(full_args)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 355, in runtime_wrapper
[rank0]:[rank0]: all_outs = call_func_at_runtime_with_args(
[rank0]:[rank0]: compiled_fn, args, disable_amp=disable_amp, steal_args=True
[rank0]:[rank0]: )
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/_aot_autograd/utils.py", line 130, in call_func_at_runtime_with_args
[rank0]:[rank0]: out = normalize_as_list(f(args))
[rank0]:[rank0]: ~^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 693, in inner_fn
[rank0]:[rank0]: unwrapped_outs = compiled_fn(unwrapped_args)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 727, in inner_fn
[rank0]:[rank0]: outs = compiled_fn(args)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 529, in wrapper
[rank0]:[rank0]: return compiled_fn(runtime_args)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_inductor/output_code.py", line 617, in call
[rank0]:[rank0]: return self.current_callable(inputs)
[rank0]:[rank0]: ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/_inductor/utils.py", line 3018, in run
[rank0]:[rank0]: out = model(new_inputs)
[rank0]:[rank0]: File "/tmp/torchinductor_ruisizhang123/sk/csk3kend5qh55mkvyqnaqg7tj7zhubsaoiewgglmofcgbpn6me4y.py", line 2926, in call
[rank0]:[rank0]: raise RuntimeError('Eq(u0 + u1, 6144)')
[rank0]:[rank0]: RuntimeError: Eq(u0 + u1, 6144)
- SimpleFSDP + PP (Interleaved1F1B) + TP + compile: failed with error below (full log Link Tlparse (Link))
Details
File "/home/ruisizhang123/pytorch/torch/fx/experimental/proxy_tensor.py", line 571, in thunkify
[rank0]:[rank0]: r = f(*args, **kwargs)
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/fx/experimental/proxy_tensor.py", line 1584, in _compute_proxy
[rank0]:[rank0]: n_args = tuple(
[rank0]:[rank0]: (
[rank0]:[rank0]: ...<4 lines>...
[rank0]:[rank0]: for a in args
[rank0]:[rank0]: )
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/fx/experimental/proxy_tensor.py", line 1586, in
[rank0]:[rank0]: get_proxy_slot(a, self.tracer).force().node
[rank0]:[rank0]: ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
[rank0]:[rank0]: File "/home/ruisizhang123/pytorch/torch/fx/experimental/proxy_tensor.py", line 411, in get_proxy_slot
[rank0]:[rank0]: raise RuntimeError(
[rank0]:[rank0]: f"{obj} ({id(obj)})is not tracked with proxy for {tracer}"
[rank0]:[rank0]: )
[rank0]:[rank0]: torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
[rank0]:[rank0]: RuntimeError: 256*s27 (140036273922896)is not tracked with proxy for <torch.fx.experimental.proxy_tensor.PythonKeyTracer object at 0x7f5c29750fc0>
[rank0]:
[rank0]:[rank0]: While executing %embedding : [num_users=1] = call_function[target=torch.nn.functional.embedding](args = (%input_tensor, %output, None, None, 2.0, False, False), kwargs = {})
[rank0]:[rank0]: Original traceback:
[rank0]:[rank0]: File "/home/ruisizhang123/torchtitan/torchtitan/models/deepseek_v3/model/model.py", line 385, in forward
[rank0]:[rank0]: h = self.tok_embeddings(tokens) if self.tok_embeddings is not None else tokens
[rank0]:
[rank0]:[rank0]: Use tlparse to see full graph. (https://github.com/pytorch/tlparse?tab=readme-ov-file#tlparse-parse-structured-pt2-logs)
[rank0]:
- SimpleFSDP + PP (Interleaved1F1B) + EP + compile: went through, but not sure if it's really working (Tlpase Link)
I checked the Tlparse for 4, and found it has the same Eq(u0 + u1, 6144) as 2 (SimpleFSDP + PP (1F1B) + EP + compile). It's just that the code didn't go into Eq(u0 + u1, 6144) in if-else branch.
1df12f1 to
ce849e6
Compare
Thank you for the review. Updated accordingly. |
ce67540 to
0761f4d
Compare
| ) | ||
|
|
||
| # re-wrap 1D all-gathered DTensor on dp_mesh to 1D DTensor on tp_mesh | ||
| # re-wrap 1D all-gathered DTensor on dp_mesh to 1D DTensor on tp_mesh/ep_mesh |
There was a problem hiding this comment.
This comment doesn't sound right, even before this PR.
I think what it tries to say is
| # re-wrap 1D all-gathered DTensor on dp_mesh to 1D DTensor on tp_mesh/ep_mesh | |
| # re-wrap all-gathered DTensor on dp_mesh to be on non_dp_mesh |
48dd348 to
1360a85
Compare
1360a85 to
c28ddd8
Compare
this PR is a followup of SimpleFSDP+EP [PR](#1529). Here, we add a `gradient_divide_factor` following FSDP2 to ensure modules wrapped by (FSDP+EP) has the correct gradient reduction value. - The original FSDP2 implementation is in this [PR](#1551). - The `gradient_divide_factor` logic is [here](https://github.com/pytorch/pytorch/blob/main/torch/distributed/fsdp/_fully_shard/_fsdp_collectives.py#L688) We have two ways of handling `gradient_divide_factor` in `reduce_scatter`: 1. The first one is to use `ReduceOp.PREMUL_SUM` to handle the `gradient_divide_factor`. However, DTensor's `_reduce_shard_value` only accepts `reduce_op` as a str input ([here](https://github.com/pytorch/pytorch/blob/8f705d019a64b1ca882e043b3eb98559273a9e59/torch/distributed/tensor/placement_types.py#L177-L210)). To make` _reduce_shard_value` work correctly with ReduceOp.PREMUL_SUM, we need to update the DTensor `_reduce_shard_tensor` and `torch.distributed._functional_collectives.reduce_scatter_tensor` so that it can pass the factor associated with ReduceOp.PREMUL_SUM as an input. 2. Another way is to simulate `ReduceOp.PREMUL_SUM` with `ReduceOp.SUM`. The logic is in this [Diff](https://www.internalfb.com/diff/D76546536). It does a `div_` over gradient before performing `ReduceOp.SUM`. Currently I'm following 2 since it is requires less change to `_functional_collectives`. After enabling `reduction_divide_factor`, we will see FSDP(=2) + EP (=4) have identical loss: <img width="1194" height="780" alt="Screenshot 2025-10-08 at 5 27 24 PM" src="https://github.com/user-attachments/assets/aaf83109-8db8-4051-973d-c7b6950513de" />
this PR is a followup of SimpleFSDP+EP [PR](pytorch#1529). Here, we add a `gradient_divide_factor` following FSDP2 to ensure modules wrapped by (FSDP+EP) has the correct gradient reduction value. - The original FSDP2 implementation is in this [PR](pytorch#1551). - The `gradient_divide_factor` logic is [here](https://github.com/pytorch/pytorch/blob/main/torch/distributed/fsdp/_fully_shard/_fsdp_collectives.py#L688) We have two ways of handling `gradient_divide_factor` in `reduce_scatter`: 1. The first one is to use `ReduceOp.PREMUL_SUM` to handle the `gradient_divide_factor`. However, DTensor's `_reduce_shard_value` only accepts `reduce_op` as a str input ([here](https://github.com/pytorch/pytorch/blob/8f705d019a64b1ca882e043b3eb98559273a9e59/torch/distributed/tensor/placement_types.py#L177-L210)). To make` _reduce_shard_value` work correctly with ReduceOp.PREMUL_SUM, we need to update the DTensor `_reduce_shard_tensor` and `torch.distributed._functional_collectives.reduce_scatter_tensor` so that it can pass the factor associated with ReduceOp.PREMUL_SUM as an input. 2. Another way is to simulate `ReduceOp.PREMUL_SUM` with `ReduceOp.SUM`. The logic is in this [Diff](https://www.internalfb.com/diff/D76546536). It does a `div_` over gradient before performing `ReduceOp.SUM`. Currently I'm following 2 since it is requires less change to `_functional_collectives`. After enabling `reduction_divide_factor`, we will see FSDP(=2) + EP (=4) have identical loss: <img width="1194" height="780" alt="Screenshot 2025-10-08 at 5 27 24 PM" src="https://github.com/user-attachments/assets/aaf83109-8db8-4051-973d-c7b6950513de" />
As titled, this pr adds support for simplefsdp+ep. #### Profiler Trace & Correctness The following results are benchmarks on 8 H100. The correctness are validated on eager (with seed set to 42); I also added profile trace and tlparse in compile mode. 1. SimpleFSDP * Loss: <img width="1181" height="780" alt="Screenshot 2025-09-23 at 8 56 50 PM" src="https://github.com/user-attachments/assets/67e48f6a-31c6-496e-a24c-830d6597b931" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpdaDH8h/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: [Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-29-09-35-12_rank0_trace.json) there would be only fsdp comms. <img width="1061" height="107" alt="Screenshot 2025-09-29 at 9 35 37 AM" src="https://github.com/user-attachments/assets/20df9de1-9491-4636-8cdc-33a8320c8385" /> 2. SimpleFSDP + EP(degree=2) * Loss: <img width="1178" height="780" alt="Screenshot 2025-09-23 at 7 50 07 PM" src="https://github.com/user-attachments/assets/e60a7af8-9764-41b0-ae29-9237bb67175d" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpAtT9l0/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-23-19-28-52_rank0_trace.json)) <img width="947" height="280" alt="Screenshot 2025-09-23 at 7 35 36 PM" src="https://github.com/user-attachments/assets/6bac31d8-6cd6-4a18-96d7-e36aa5b9a670" /> 3. SimpleFSDP + TP(degree=2) + EP(degree=2) + ETP(degree=1) * Loss: <img width="1188" height="786" alt="Screenshot 2025-09-23 at 7 58 18 PM" src="https://github.com/user-attachments/assets/16374e93-fe0b-4583-b856-8571f26c5a9d" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpLyfHM3/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-23-20-02-47_rank0_trace.json)) <img width="1210" height="297" alt="Screenshot 2025-09-23 at 8 09 41 PM" src="https://github.com/user-attachments/assets/7703a6c2-6755-4ebc-a184-9f4358102f36" /> 4. HSDP(dp_shard=2; dp_replicate=2) + EP (degree=2) * Loss: <img width="1160" height="719" alt="Screenshot 2025-09-24 at 9 44 48 PM" src="https://github.com/user-attachments/assets/aa3662e5-dbbd-4415-871c-03a8af9cab35" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmp2WSuG3/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-24-21-10-23_rank0_trace.json)) <img width="865" height="270" alt="Screenshot 2025-09-24 at 9 16 44 PM" src="https://github.com/user-attachments/assets/4607d5ee-6d73-4438-8d52-a9268e10aa90" /> 5. HSDP(dp_shard=2; dp_replicate=2) + EP (degree=2) + EP(degree=2) + ETP(degree=1) * Loss: <img width="1168" height="729" alt="Screenshot 2025-09-24 at 9 41 20 PM" src="https://github.com/user-attachments/assets/f4f74825-e942-43af-96cc-8f1ac918651c" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpZcSbS5/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-24-21-21-41_rank0_trace.json)) <img width="885" height="187" alt="Screenshot 2025-09-24 at 9 30 04 PM" src="https://github.com/user-attachments/assets/e19dd212-79e1-41c5-9f08-9c97b302793e" /> #### Status 1. Currently, SimpleFSDP+EP+AC doesn't work because of graph breaks in HOP mutation. (see the [comment message ](pytorch#1529 (comment))) 2. @ezyang also points out that numerical issues in Float8 training may be related to this, since quantization calibration involves mutation, which might not compose well with AC. 3. There are some minor numerical differences after EP is added. @tianyu-l suggests that it's because the reduce-scatter is averaged over whole dp_mesh, instead of dp_mod_ep_mesh, for the EP part. We will fix this in a separate PR. 4. PP(1F1B and Interleaved1F1B)+EP+SimpleFSDP has a series of composability issues: pytorch#1529 (comment) cc. @anijain2305
this PR is a followup of SimpleFSDP+EP [PR](pytorch#1529). Here, we add a `gradient_divide_factor` following FSDP2 to ensure modules wrapped by (FSDP+EP) has the correct gradient reduction value. - The original FSDP2 implementation is in this [PR](pytorch#1551). - The `gradient_divide_factor` logic is [here](https://github.com/pytorch/pytorch/blob/main/torch/distributed/fsdp/_fully_shard/_fsdp_collectives.py#L688) We have two ways of handling `gradient_divide_factor` in `reduce_scatter`: 1. The first one is to use `ReduceOp.PREMUL_SUM` to handle the `gradient_divide_factor`. However, DTensor's `_reduce_shard_value` only accepts `reduce_op` as a str input ([here](https://github.com/pytorch/pytorch/blob/8f705d019a64b1ca882e043b3eb98559273a9e59/torch/distributed/tensor/placement_types.py#L177-L210)). To make` _reduce_shard_value` work correctly with ReduceOp.PREMUL_SUM, we need to update the DTensor `_reduce_shard_tensor` and `torch.distributed._functional_collectives.reduce_scatter_tensor` so that it can pass the factor associated with ReduceOp.PREMUL_SUM as an input. 2. Another way is to simulate `ReduceOp.PREMUL_SUM` with `ReduceOp.SUM`. The logic is in this [Diff](https://www.internalfb.com/diff/D76546536). It does a `div_` over gradient before performing `ReduceOp.SUM`. Currently I'm following 2 since it is requires less change to `_functional_collectives`. After enabling `reduction_divide_factor`, we will see FSDP(=2) + EP (=4) have identical loss: <img width="1194" height="780" alt="Screenshot 2025-10-08 at 5 27 24 PM" src="https://github.com/user-attachments/assets/aaf83109-8db8-4051-973d-c7b6950513de" />
As titled, this pr adds support for simplefsdp+ep. #### Profiler Trace & Correctness The following results are benchmarks on 8 H100. The correctness are validated on eager (with seed set to 42); I also added profile trace and tlparse in compile mode. 1. SimpleFSDP * Loss: <img width="1181" height="780" alt="Screenshot 2025-09-23 at 8 56 50 PM" src="https://github.com/user-attachments/assets/67e48f6a-31c6-496e-a24c-830d6597b931" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpdaDH8h/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: [Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-29-09-35-12_rank0_trace.json) there would be only fsdp comms. <img width="1061" height="107" alt="Screenshot 2025-09-29 at 9 35 37 AM" src="https://github.com/user-attachments/assets/20df9de1-9491-4636-8cdc-33a8320c8385" /> 2. SimpleFSDP + EP(degree=2) * Loss: <img width="1178" height="780" alt="Screenshot 2025-09-23 at 7 50 07 PM" src="https://github.com/user-attachments/assets/e60a7af8-9764-41b0-ae29-9237bb67175d" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpAtT9l0/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-23-19-28-52_rank0_trace.json)) <img width="947" height="280" alt="Screenshot 2025-09-23 at 7 35 36 PM" src="https://github.com/user-attachments/assets/6bac31d8-6cd6-4a18-96d7-e36aa5b9a670" /> 3. SimpleFSDP + TP(degree=2) + EP(degree=2) + ETP(degree=1) * Loss: <img width="1188" height="786" alt="Screenshot 2025-09-23 at 7 58 18 PM" src="https://github.com/user-attachments/assets/16374e93-fe0b-4583-b856-8571f26c5a9d" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpLyfHM3/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-23-20-02-47_rank0_trace.json)) <img width="1210" height="297" alt="Screenshot 2025-09-23 at 8 09 41 PM" src="https://github.com/user-attachments/assets/7703a6c2-6755-4ebc-a184-9f4358102f36" /> 4. HSDP(dp_shard=2; dp_replicate=2) + EP (degree=2) * Loss: <img width="1160" height="719" alt="Screenshot 2025-09-24 at 9 44 48 PM" src="https://github.com/user-attachments/assets/aa3662e5-dbbd-4415-871c-03a8af9cab35" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmp2WSuG3/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-24-21-10-23_rank0_trace.json)) <img width="865" height="270" alt="Screenshot 2025-09-24 at 9 16 44 PM" src="https://github.com/user-attachments/assets/4607d5ee-6d73-4438-8d52-a9268e10aa90" /> 5. HSDP(dp_shard=2; dp_replicate=2) + EP (degree=2) + EP(degree=2) + ETP(degree=1) * Loss: <img width="1168" height="729" alt="Screenshot 2025-09-24 at 9 41 20 PM" src="https://github.com/user-attachments/assets/f4f74825-e942-43af-96cc-8f1ac918651c" /> * Tlparse: [Link](https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/.tmpZcSbS5/rank_0/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000) * Profile Trace: ([Link](https://interncache-all.fbcdn.net/manifold/perfetto-artifacts/tree/ui/index.html#!/?url=https://interncache-all.fbcdn.net/manifold/perfetto_internal_traces/tree/shared_trace/ruisizhang123_2025-09-24-21-21-41_rank0_trace.json)) <img width="885" height="187" alt="Screenshot 2025-09-24 at 9 30 04 PM" src="https://github.com/user-attachments/assets/e19dd212-79e1-41c5-9f08-9c97b302793e" /> #### Status 1. Currently, SimpleFSDP+EP+AC doesn't work because of graph breaks in HOP mutation. (see the [comment message ](pytorch#1529 (comment))) 2. @ezyang also points out that numerical issues in Float8 training may be related to this, since quantization calibration involves mutation, which might not compose well with AC. 3. There are some minor numerical differences after EP is added. @tianyu-l suggests that it's because the reduce-scatter is averaged over whole dp_mesh, instead of dp_mod_ep_mesh, for the EP part. We will fix this in a separate PR. 4. PP(1F1B and Interleaved1F1B)+EP+SimpleFSDP has a series of composability issues: pytorch#1529 (comment) cc. @anijain2305
this PR is a followup of SimpleFSDP+EP [PR](pytorch#1529). Here, we add a `gradient_divide_factor` following FSDP2 to ensure modules wrapped by (FSDP+EP) has the correct gradient reduction value. - The original FSDP2 implementation is in this [PR](pytorch#1551). - The `gradient_divide_factor` logic is [here](https://github.com/pytorch/pytorch/blob/main/torch/distributed/fsdp/_fully_shard/_fsdp_collectives.py#L688) We have two ways of handling `gradient_divide_factor` in `reduce_scatter`: 1. The first one is to use `ReduceOp.PREMUL_SUM` to handle the `gradient_divide_factor`. However, DTensor's `_reduce_shard_value` only accepts `reduce_op` as a str input ([here](https://github.com/pytorch/pytorch/blob/8f705d019a64b1ca882e043b3eb98559273a9e59/torch/distributed/tensor/placement_types.py#L177-L210)). To make` _reduce_shard_value` work correctly with ReduceOp.PREMUL_SUM, we need to update the DTensor `_reduce_shard_tensor` and `torch.distributed._functional_collectives.reduce_scatter_tensor` so that it can pass the factor associated with ReduceOp.PREMUL_SUM as an input. 2. Another way is to simulate `ReduceOp.PREMUL_SUM` with `ReduceOp.SUM`. The logic is in this [Diff](https://www.internalfb.com/diff/D76546536). It does a `div_` over gradient before performing `ReduceOp.SUM`. Currently I'm following 2 since it is requires less change to `_functional_collectives`. After enabling `reduction_divide_factor`, we will see FSDP(=2) + EP (=4) have identical loss: <img width="1194" height="780" alt="Screenshot 2025-10-08 at 5 27 24 PM" src="https://github.com/user-attachments/assets/aaf83109-8db8-4051-973d-c7b6950513de" />
As titled, this pr adds support for simplefsdp+ep.
Profiler Trace & Correctness
The following results are benchmarks on 8 H100. The correctness are validated on eager (with seed set to 42); I also added profile trace and tlparse in compile mode.
Tlparse: Link
Profile Trace: Link there would be only fsdp comms.
Tlparse: Link
Profile Trace: (Link)
Tlparse: Link
Profile Trace: (Link)
Tlparse: Link
Profile Trace: (Link)
Status
Currently, SimpleFSDP+EP+AC doesn't work because of graph breaks in HOP mutation. (see the comment message )
@ezyang also points out that numerical issues in Float8 training may be related to this, since quantization calibration involves mutation, which might not compose well with AC.
There are some minor numerical differences after EP is added. @tianyu-l suggests that it's because the reduce-scatter is averaged over whole dp_mesh, instead of dp_mod_ep_mesh, for the EP part. We will fix this in a separate PR.
PP(1F1B and Interleaved1F1B)+EP+SimpleFSDP has a series of composability issues: add support for simplefsdp+ep #1529 (comment)
cc. @anijain2305