FP8 AllGather Support in Fairscale - #1185
Open
levendlee wants to merge 21 commits into
Open
Conversation
Co-authored-by: Naman Goyal <naman@fb.com>
This commit works with a 4 GPU run on SMALL model with FSDP and PP enabled.
- Clean up flatten and non_flatten parameter generation logic. - Avoid checking `main_grad` attribute all equal to zeros.
- Cleans up amax and scale update logic. Amax and scale should be done for both weights and parameters. So it should be done at forward of each microbatch. - Consolidate `cast_params` and `all_gather` stream.
Co-authored-by: Naman Goyal <naman@fb.com>
This commit works with a 4 GPU run on SMALL model with FSDP and PP enabled.
- Clean up flatten and non_flatten parameter generation logic. - Avoid checking `main_grad` attribute all equal to zeros.
- Cleans up amax and scale update logic. Amax and scale should be done for both weights and parameters. So it should be done at forward of each microbatch. - Consolidate `cast_params` and `all_gather` stream.
…kresearch/fairscale into shikaili_fp8_allgather_no_pp_fix
awgu
reviewed
Jun 24, 2024
awgu
left a comment
There was a problem hiding this comment.
Thanks @levendlee for the great work! I left some comments for my own learning.
| and all(_is_te_module_with_weights(info[1]) for info in p._param_infos)) | ||
| if fused_wgard_accumulation: | ||
| if getattr(p, "main_grad", None) is None: | ||
| p.main_grad = torch.empty_like(p, dtype=torch.float32) |
There was a problem hiding this comment.
For my understanding, why empty_like instead of zeros_like?
| """Update Amax and scales associated with FP8 parameters.""" | ||
| if params is None: | ||
| params = self.params | ||
| with torch.cuda.stream(self._streams["fp32_to_fp16"]): |
There was a problem hiding this comment.
Curious why did you use the "all_gather" stream instead of the "fp32_to_fp16" stream?
| self.has_full_params = False | ||
|
|
||
| if self.fp8_all_gather: | ||
| self._update_amax_and_scale_fwd(is_first_microbatch_fwd=is_first_microbatch_fwd) |
There was a problem hiding this comment.
For my understanding, is there a reason that this is not done together with _cast_params_for_all_gather? (For example, could this call be delayed a few lines to below where _cast_params_for_all_gather is called?)
|
|
||
| @torch.no_grad() | ||
| def _rebuild_full_params(self, force_full_precision: bool = False, wait_for_all_gather = True) -> Optional[List[Tuple[torch.Tensor, bool]]]: | ||
| def _rebuild_full_params( |
There was a problem hiding this comment.
For fp8_all_gather=True, what happens when this method is called without the TE autocast context?
| # All-gather full parameters. This will also transfer FP32 parameters to | ||
| # ``self.compute_dtype`` (e.g., FP16 if *mixed_precision* is ``True``). | ||
| self._rebuild_full_params() | ||
| self.module.has_unflatten_views = getattr(self.module, "has_unflatten_views", False) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes # (issue).
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.