-
Notifications
You must be signed in to change notification settings - Fork 86
Bugfix - Fix DeepSpeed BF16 config validation error #796
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
polarG
wants to merge
5
commits into
main
Choose a base branch
from
dev/hongtaozhang/fix-deepspeed-bf16-config-validation
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.
+82
−11
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
367cf62
Fix DeepSpeed BF16 config validation error by removing FP16-only loss…
5233926
Merge branch 'main' into dev/hongtaozhang/fix-deepspeed-bf16-config-v…
polarG d3baec9
Address PR review: clarify deepspeed config template comment
1587335
test: add deepspeed config schema regression test for fp16/bf16/fp32
dd2b2e4
Merge branch 'main' into dev/hongtaozhang/fix-deepspeed-bf16-config-v…
polarG 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,6 +500,69 @@ def test_deepseek_v2_command(self): | |
|
|
||
| self.assertEqual(actual_units, expected_units) | ||
|
|
||
| @mock.patch('superbench.benchmarks.model_benchmarks.MegatronGPT._generate_dataset') | ||
| def test_megatron_gpt_deepspeed_config(self, mock_generate_dataset): | ||
| """Lock in the deepspeed JSON schema written for fp16 / bf16 / fp32. | ||
|
|
||
| BF16 must NOT include loss_scale / loss_scale_window / min_loss_scale / | ||
| initial_scale_power / hysteresis (DeepSpeed's BF16 config schema rejects | ||
| them); FP16 must keep them; FP32 must omit any precision section. | ||
| """ | ||
| import json | ||
| (benchmark_cls, _) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(self.benchmark_name, Platform.CUDA) | ||
| assert (benchmark_cls) | ||
| os.environ['OMPI_COMM_WORLD_SIZE'] = '1' | ||
| os.environ['OMPI_COMM_WORLD_LOCAL_SIZE'] = '1' | ||
| os.environ['OMPI_COMM_WORLD_RANK'] = '0' | ||
| os.environ['MASTER_ADDR'] = 'localhost' | ||
| os.environ['MASTER_PORT'] = '12345' | ||
| self.createMockFiles(['pretrain_gpt.py']) | ||
| # createMockFiles only cleans up at tearDownClass; remove at test end so | ||
| # we don't leak the file into other tests (e.g. test_megatron_gpt_preprocess | ||
| # which exercises the "no code_base" negative path). | ||
| pretrain_path = Path(self._tmp_dir) / 'pretrain_gpt.py' | ||
| self.addCleanup(lambda: pretrain_path.is_file() and pretrain_path.unlink()) | ||
|
|
||
| benchmark = benchmark_cls( | ||
| self.benchmark_name, | ||
| parameters=( | ||
| f'--code_base {self._tmp_dir} --data_home {self._tmp_dir} ' | ||
| f'--batch_size 2048 --deepspeed' | ||
| ), | ||
| ) | ||
| mock_generate_dataset.return_value = True | ||
| assert benchmark._preprocess() is True | ||
|
|
||
| # bf16: only {'enabled': True}, no loss-scale fields, no fp16 section | ||
| benchmark._MegatronGPT__prepare_deespeed_config('bf16') | ||
| with open(benchmark._config_json_path) as f: | ||
| cfg = json.load(f) | ||
| self.assertEqual(cfg.get('bf16'), {'enabled': True}) | ||
|
Comment on lines
+536
to
+540
|
||
| self.assertNotIn('fp16', cfg) | ||
| for forbidden in ('loss_scale', 'loss_scale_window', 'min_loss_scale', 'initial_scale_power', 'hysteresis'): | ||
| self.assertNotIn(forbidden, cfg['bf16']) | ||
|
|
||
| # fp16: keeps loss-scale fields | ||
| benchmark._MegatronGPT__prepare_deespeed_config('fp16') | ||
|
Contributor
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. The fp16 test constructs the benchmark without --hysteresis, so the |
||
| with open(benchmark._config_json_path) as f: | ||
| cfg = json.load(f) | ||
| self.assertIn('fp16', cfg) | ||
| self.assertNotIn('bf16', cfg) | ||
| self.assertTrue(cfg['fp16']['enabled']) | ||
| self.assertEqual(cfg['fp16']['loss_scale'], 0) | ||
| self.assertEqual(cfg['fp16']['loss_scale_window'], 500) | ||
| self.assertEqual(cfg['fp16']['min_loss_scale'], 1) | ||
| self.assertEqual(cfg['fp16']['initial_scale_power'], 11) | ||
|
|
||
| # empty precision (e.g., fp32 path which calls __prepare with ''): | ||
| # no precision section attached. | ||
| benchmark._MegatronGPT__prepare_deespeed_config('') | ||
| with open(benchmark._config_json_path) as f: | ||
| cfg = json.load(f) | ||
| self.assertNotIn('fp16', cfg) | ||
| self.assertNotIn('bf16', cfg) | ||
| self.assertNotIn('', cfg) | ||
|
|
||
| @decorator.load_data('tests/data/megatron_deepspeed.log') | ||
| @mock.patch('superbench.benchmarks.model_benchmarks.MegatronGPT._generate_dataset') | ||
| def test_megatron_parse_log(self, raw_output, mock_generate_dataset): | ||
|
|
||
Oops, something went wrong.
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.
typo deespeed -> deepspeed.