-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Fix DeepSpeed mixed precision precedence over Accelerate defaults #39856
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
Merged
ArthurZucker
merged 2 commits into
huggingface:main
from
notkisk:fix-deepspeed-mixed-precision
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
|---|---|---|
|
|
@@ -1431,3 +1431,50 @@ def test_clm_from_config_zero3_fp16(self): | |
| with CaptureStderr() as cs: | ||
| execute_subprocess_async(cmd, env=self.get_env()) | ||
| self.assertIn("Detected DeepSpeed ZeRO-3", cs.err) | ||
|
|
||
|
|
||
| @require_deepspeed | ||
| class TestDeepSpeedMixedPrecisionPrecedence(TestCasePlus): | ||
| """Test DeepSpeed mixed precision precedence over Accelerate defaults.""" | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| unset_hf_deepspeed_config() | ||
|
|
||
| def tearDown(self): | ||
| super().tearDown() | ||
| unset_hf_deepspeed_config() | ||
|
|
||
| def test_deepspeed_fp16_overrides_defaults(self): | ||
| """Test that DeepSpeed fp16 config overrides TrainingArguments defaults""" | ||
| from transformers.integrations.deepspeed import HfTrainerDeepSpeedConfig | ||
|
|
||
| args = TrainingArguments(output_dir="./test_output", fp16=False, bf16=False) | ||
| ds_config = {"fp16": {"enabled": True}, "bf16": {"enabled": False}, "zero_optimization": {"stage": 2}} | ||
| hf_ds_config = HfTrainerDeepSpeedConfig(ds_config) | ||
| hf_ds_config.trainer_config_process(args) | ||
| self.assertTrue(args.fp16) | ||
| self.assertFalse(args.bf16) | ||
|
|
||
|
Comment on lines
+1436
to
+1458
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. it would be nice to add a test that reproduce the initial error |
||
| def test_deepspeed_bf16_overrides_defaults(self): | ||
| """Test that DeepSpeed bf16 config overrides TrainingArguments defaults""" | ||
| from transformers.integrations.deepspeed import HfTrainerDeepSpeedConfig | ||
|
|
||
| args = TrainingArguments(output_dir="./test_output", fp16=False, bf16=False) | ||
| ds_config = {"fp16": {"enabled": False}, "bf16": {"enabled": True}, "zero_optimization": {"stage": 2}} | ||
| hf_ds_config = HfTrainerDeepSpeedConfig(ds_config) | ||
| hf_ds_config.trainer_config_process(args) | ||
| self.assertTrue(args.bf16) | ||
| self.assertFalse(args.fp16) | ||
|
|
||
| def test_user_explicit_settings_preserved(self): | ||
| """Test that explicit user settings are preserved over DeepSpeed config""" | ||
| from transformers.integrations.deepspeed import HfTrainerDeepSpeedConfig | ||
|
|
||
| args = TrainingArguments(output_dir="./test_output", fp16=True, bf16=False) # User explicit | ||
| ds_config = {"fp16": {"enabled": False}, "bf16": {"enabled": True}, "zero_optimization": {"stage": 2}} | ||
| hf_ds_config = HfTrainerDeepSpeedConfig(ds_config) | ||
| hf_ds_config.trainer_config_process(args) | ||
| # User's explicit choice should be preserved | ||
| self.assertTrue(args.fp16) | ||
| self.assertFalse(args.bf16) | ||
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.
I feel like this could have been simpler