Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom (MCORE) FSDP interface #12391

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nemo/collections/llm/recipes/CONFIGURATION-HIERARCHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
bucket_size: Optional[int] = None # Maximum number of parameters in each bucket
average_in_collective: bool = False # If true, compute average in collective directly, as opposed to dividing by the dp_size first and then computing sum in the collective
fp8_param_gather: bool = False # If true, keep the compute param in fp8 (do not use any other intermediate dtype) and perform the param all-gather in fp8
use_custom_fsdp: bool = False # If true, use MCore's custom FSDP implementation. recipe.model.config.gradient_accumulation_fusion must be False when using this
data_parallel_sharding_strategy: str = "no_shard" # Data parallel sharding strategy, choices=['no_shard', 'optim', 'optim_grads', 'optim_grads_params']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this valid only with use_custom_fsdp=True?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then, wouldn't optim_grads_params be the default option fron NeMo side? So, use_custom_fsdp=True means Zero3.

Also, need to describe this in the comment description; Custom (MCORE) FSDP Data parallel sharding strategy, choices=['no_shard', 'optim', 'optim_grads', 'optim_grads_params']

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified the comment accordingly.

```
</blockquote>
</details>
Expand Down
6 changes: 6 additions & 0 deletions nemo/lightning/megatron_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ def init_ddp(self):
) # We need to do this explicitly since this is a attr pytorch uses
model_chunk.__class__.__getattr__ = getattr_proxy # type: ignore

# Ensure that if using custom FSDP, gradient_accumulation_fusion is disabled on the model config.
Copy link
Collaborator

@erhoo82 erhoo82 Feb 26, 2025

Choose a reason for hiding this comment

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

I think this should be changed to this.

gradient_accumulation_fusion cannot be used with MCORE FSDP

Also, gradient_accumulation_fusion shouldn't work with FSDP2 eight because we need to ReduceScatter the current gradient before accumulation local grad shard partial sum.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will modify the text as that. For the Torch FSDP2, I agree, but we don't have that in the NeMo yet.

if self.ddp_config.use_custom_fsdp:
assert (
module.config.gradient_accumulation_fusion == False
), "gradient_accumulation_fusion must be False when using custom FSDP"

# param_sync_func is set in nemo.lightning.pytorch.optim.megatron
no_sync_func, grad_sync_func = extract_ddp_funcs(self.ddp_config, self)
for module in self:
Expand Down
Loading