-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Fix FSDP2 defaulting to version 1 in TrainingArguments; add dynamic plugin param passthrough #42521
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
Open
amanzoni1
wants to merge
5
commits into
huggingface:main
Choose a base branch
from
amanzoni1:fix-fsdp2-default-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+45
−3
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
139cb6b
Fix FSDP v2 defaulting to version 1 in TrainingArguments
amanzoni1 f14bd4f
Fix FSDP2 params and add test
amanzoni1 1140f69
Fix FSDP2 params and add test
amanzoni1 ff47d0d
Better FSDP2 test
amanzoni1 7a0a30e
Merge branch 'main' into fix-fsdp2-default-version
SunMarc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2678,7 +2678,7 @@ def _process_fsdp_args(self): | |
|
|
||
| if self.fsdp_config is not None and isinstance(self.fsdp_config, dict): | ||
| for k in list(self.fsdp_config.keys()): | ||
| if k.startswith("fsdp_"): | ||
| if k.startswith("fsdp_") and k != "fsdp_version": | ||
| v = self.fsdp_config.pop(k) | ||
| self.fsdp_config[k[5:]] = v | ||
|
|
||
|
|
@@ -2722,6 +2722,7 @@ def _process_fsdp_args(self): | |
| # accelerate integration for FSDP | ||
| fsdp_plugin_args = None | ||
| if len(self.fsdp) > 0 and not self.fsdp_config["xla"]: | ||
| from accelerate.utils import FullyShardedDataParallelPlugin | ||
| from accelerate.utils.constants import ( | ||
| FSDP_AUTO_WRAP_POLICY, | ||
| FSDP_SHARDING_STRATEGY, | ||
|
|
@@ -2730,7 +2731,10 @@ def _process_fsdp_args(self): | |
| fsdp_plugin_args = {} | ||
| for fsdp_option in self.fsdp: | ||
| if fsdp_option.upper() in FSDP_SHARDING_STRATEGY: | ||
| fsdp_plugin_args["sharding_strategy"] = fsdp_option | ||
| # Set deprecated sharding_strategy from CLI (plugin maps to reshard_after_forward) | ||
| # Skip if config has explicit reshard_after_forward (prioritize config) | ||
| if "reshard_after_forward" not in self.fsdp_config: | ||
| fsdp_plugin_args["sharding_strategy"] = fsdp_option | ||
|
Comment on lines
+2734
to
+2737
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks ! |
||
| elif fsdp_option == FSDPOption.OFFLOAD: | ||
| fsdp_plugin_args["cpu_offload"] = True | ||
| elif fsdp_option == FSDPOption.AUTO_WRAP: | ||
|
|
@@ -2742,7 +2746,8 @@ def _process_fsdp_args(self): | |
| fsdp_plugin_args["transformer_cls_names_to_wrap"] = ",".join( | ||
| self.fsdp_config["transformer_layer_cls_to_wrap"] | ||
| ) | ||
| fsdp_version = int(self.fsdp_config.get("version", 1)) | ||
|
|
||
| fsdp_version = int(self.fsdp_config.get("fsdp_version", 1)) | ||
| fsdp_plugin_args["fsdp_version"] = fsdp_version | ||
| prefetch_policy = self.fsdp_config.get("backward_prefetch", "NO_PREFETCH") | ||
| if fsdp_version == 2: | ||
|
|
@@ -2774,6 +2779,12 @@ def _process_fsdp_args(self): | |
|
|
||
| fsdp_plugin_args["sync_module_states"] = str_to_bool(sync_module_states) | ||
|
|
||
| # Pull allowed parameters from fsdp_config | ||
| ALLOWED_FSDP_PARAMS = {f.name for f in fields(FullyShardedDataParallelPlugin)} | ||
| for key in ALLOWED_FSDP_PARAMS: | ||
| if key in self.fsdp_config and key not in fsdp_plugin_args: | ||
| fsdp_plugin_args[key] = self.fsdp_config[key] | ||
|
|
||
| return fsdp_plugin_args | ||
|
|
||
|
|
||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed thanks !