Skip to content

[SimpleFSDP] Add support for hsdp+tp - #1343

Merged
tianyu-l merged 1 commit into
mainfrom
ruisi/simplefsdp_hsdp_and_tp
Jul 10, 2025
Merged

tianyu-l merged 1 commit into
mainfrom
ruisi/simplefsdp_hsdp_and_tp

Conversation

@ruisizhang123

@ruisizhang123 ruisizhang123 commented Jun 26, 2025 •

Copy link
Copy Markdown
Collaborator

As titled, this pr adds support for SimpleFSDP's HSDP + TP

The profile trace below shows the three streams for FSDP's All-gather/Reduce-scatter; DDP's All-reduce; and TP's communications.

Screenshot 2025-06-25 at 8 13 39 PM

The loss below shows SimpleFSDP & FSDP2's losses matches under HSDP + TP mode (seed=42).

Screenshot 2025-06-25 at 8 27 11 PM

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 26, 2025
@ruisizhang123
ruisizhang123 force-pushed the ruisi/simplefsdp_hsdp_and_tp branch from dc82ddf to cbd4fd1 Compare June 26, 2025 04:25
@ruisizhang123
ruisizhang123 requested a review from tianyu-l June 26, 2025 04:26
target_spec=target_spec,
)

for placement in placements:

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.

Instead of doing this for loop over placements (which tries to be generic but actually hard to make every possible case correct), let's be more explicit about the 3 types DP / FSDP / HSDP, where there is at most 1 replicate dim, and at most 1 shard dim.

I think we can just have three if-else conditions (instead of DP / FSDP before), and one redistribute_local_tensor outside, just like before.

The FSDP2 code for dealing with HSDP is also here, for your reference
https://github.com/pytorch/pytorch/blob/dfef1e44085bb156abc4aff0f34a0b82a4a337b8/torch/distributed/fsdp/_fully_shard/_fsdp_param.py#L324

@ruisizhang123
ruisizhang123 force-pushed the ruisi/simplefsdp_hsdp_and_tp branch from cbd4fd1 to fe081b9 Compare June 29, 2025 00:03
@ruisizhang123
ruisizhang123 requested a review from tianyu-l June 29, 2025 03:26

@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.

There are two high level things this function does:

  1. do the actual sharding Replicate -> placements[-1] (index is 1 if 2D, 0 if 1D)
  2. figure out what the DTensorSpec should be for the returned DTensor.

I suggest we don't mix up the two, as in the previous implementation you are first doing 2 and then 1.

@ruisizhang123
ruisizhang123 force-pushed the ruisi/simplefsdp_hsdp_and_tp branch from fe081b9 to de47d6c Compare July 10, 2025 05:28
@ruisizhang123
ruisizhang123 requested a review from tianyu-l July 10, 2025 06:05
@ruisizhang123
ruisizhang123 force-pushed the ruisi/simplefsdp_hsdp_and_tp branch from de47d6c to e174cbb Compare July 10, 2025 06:11

@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.

LGTM!

Recently I modified FSDP2 code to support FSDP + EP + TP. pytorch/pytorch#157216
I think for _distributed_tensor we can do the same thing. However, for ReplicateComputation there needs to be bigger change.

We can discuss how to support them in later.

@tianyu-l
tianyu-l merged commit f0ce21b into main Jul 10, 2025
@tianyu-l
tianyu-l deleted the ruisi/simplefsdp_hsdp_and_tp branch July 10, 2025 06:49
@ruisizhang123

Copy link
Copy Markdown
Collaborator Author

LGTM!

Recently I modified FSDP2 code to support FSDP + EP + TP. pytorch/pytorch#157216 I think for _distributed_tensor we can do the same thing. However, for ReplicateComputation there needs to be bigger change.

We can discuss how to support them in later.

Sounds good! Excited to have EP in simplefsdp!

idoh pushed a commit to idoh/torchtitan that referenced this pull request Jul 28, 2025
As titled, this pr adds support for SimpleFSDP's HSDP + TP

The profile trace below shows the three streams for FSDP's
All-gather/Reduce-scatter; DDP's All-reduce; and TP's communications.

<img width="1499" alt="Screenshot 2025-06-25 at 8 13 39 PM"
src="https://github.com/user-attachments/assets/4d9a7561-8895-48e6-b728-bcc1f95d8f2c"
/>

The loss below shows SimpleFSDP & FSDP2's losses matches under HSDP + TP
mode (seed=42).

<img width="1521" alt="Screenshot 2025-06-25 at 8 27 11 PM"
src="https://github.com/user-attachments/assets/b497c1f9-a766-4a00-9e42-cbc8ce1ca1b8"
/>
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
As titled, this pr adds support for SimpleFSDP's HSDP + TP

The profile trace below shows the three streams for FSDP's
All-gather/Reduce-scatter; DDP's All-reduce; and TP's communications.

<img width="1499" alt="Screenshot 2025-06-25 at 8 13 39 PM"
src="https://github.com/user-attachments/assets/4d9a7561-8895-48e6-b728-bcc1f95d8f2c"
/>

The loss below shows SimpleFSDP & FSDP2's losses matches under HSDP + TP
mode (seed=42).

<img width="1521" alt="Screenshot 2025-06-25 at 8 27 11 PM"
src="https://github.com/user-attachments/assets/b497c1f9-a766-4a00-9e42-cbc8ce1ca1b8"
/>
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
As titled, this pr adds support for SimpleFSDP's HSDP + TP

The profile trace below shows the three streams for FSDP's
All-gather/Reduce-scatter; DDP's All-reduce; and TP's communications.

<img width="1499" alt="Screenshot 2025-06-25 at 8 13 39 PM"
src="https://github.com/user-attachments/assets/4d9a7561-8895-48e6-b728-bcc1f95d8f2c"
/>

The loss below shows SimpleFSDP & FSDP2's losses matches under HSDP + TP
mode (seed=42).

<img width="1521" alt="Screenshot 2025-06-25 at 8 27 11 PM"
src="https://github.com/user-attachments/assets/b497c1f9-a766-4a00-9e42-cbc8ce1ca1b8"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants