-
Notifications
You must be signed in to change notification settings - Fork 570
[BE][3/n] wrap fp8 logic using Float8Handler #496
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,7 @@ | |
|
|
||
| from torchtitan.config_manager import JobConfig | ||
| from torchtitan.datasets import build_tokenizer | ||
| from torchtitan.float8_linear import ( | ||
| maybe_build_fp8_linear, | ||
| maybe_precompute_fp8_dynamic_scale_for_fsdp, | ||
| ) | ||
| from torchtitan.float8_linear import Float8Handler | ||
| from torchtitan.logging import init_logger, logger | ||
| from torchtitan.models import model_name_to_cls, model_name_to_tokenizer, models_config | ||
| from torchtitan.optimizer import build_lr_schedulers, build_optimizers | ||
|
|
@@ -127,8 +124,10 @@ def loss_fn(pred, labels): | |
| with torch.device("meta"): | ||
| whole_model = model_cls.from_model_args(model_config) | ||
|
|
||
| # a no-op hander if fp8 is not enabled | ||
| float8_handler = Float8Handler(job_config, parallel_dims) | ||
| # swap to Float8Linear base on fp8 config | ||
| maybe_build_fp8_linear(whole_model, job_config, parallel_dims.dp_enabled) | ||
| float8_handler.convert_to_float8_training(whole_model) | ||
|
|
||
| # apply PT-D DP/TP parallelisms and activation checkpointing | ||
| model_parts = [whole_model] | ||
|
|
@@ -184,13 +183,14 @@ def loss_fn(pred, labels): | |
| torch.nn.utils.clip_grad_norm_( | ||
| model.parameters(), job_config.training.max_norm, foreach=True | ||
| ) | ||
| # sync float8 amaxes and scales | ||
| float8_handler.sync_float8_amax_and_scale_history(model) | ||
|
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. because train.py has it but estimation.py is outdated? 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. I think so. @sanketpurandare to double check. |
||
| # optimizer step | ||
| optimizers.step() | ||
| lr_schedulers.step() | ||
| # when fp8 config is on, | ||
| # calculate float8 dynamic amax/scale for all-parameter for FSDP2 | ||
| # it issues a single all-reduce for all parameters at once for better performance | ||
| maybe_precompute_fp8_dynamic_scale_for_fsdp(whole_model, job_config) | ||
| float8_handler.precompute_fp8_dynamic_scale_for_fsdp(model) | ||
| optimizers.zero_grad() | ||
| print(f"Peak Memory at iter: {iter_idx}") | ||
| fsdp_memtracker.display_snapshot("peak", units="MiB", tabulate=True) | ||
|
|
||
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
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.
not directly related to this PR: is there a way to share code between
estimation.pyandtrain.py? it's quite painful to manually keep them in syncThere 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 agree. People are aware of this -- some context here: #425 (comment)
Another step I'm going to do is to have a separate training script for PP, which could make it worse.