Repository navigation
Fix BF16 AutoEP folding: avoid BF16 round-trip in FP32 accumulation #8989
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -509,18 +509,22 @@ def _update_hp_grad(self, lp, group_idx, param_idx, clear_lp_grads): | |
| if lp.grad is None: | ||
| return | ||
|
|
||
| hp_grad = self.fp32_groups_gradients[group_idx][param_idx] | ||
| assert hp_grad is not None, \ | ||
| f'high precision param has no gradient, lp param_id = {id(lp)} group_info = [{group_idx}][{param_idx}]' | ||
|
|
||
| if self.autoep_folding_tp_group is not None and getattr(lp, "ds_grad_is_ready", True): | ||
| # Promote to FP32 before folding so the TP reduction result is | ||
| # accumulated directly without a BF16 round-trip (#8913). | ||
| fp32_grad = lp.grad.float() | ||
| apply_folding_correction_to_grad_buffer(self.autoep_folding_spec, | ||
| lp, | ||
| lp.grad, | ||
| fp32_grad, | ||
| tp_group=self.autoep_folding_tp_group, | ||
| param_name=self.param_names.get(lp)) | ||
|
|
||
| hp_grad = self.fp32_groups_gradients[group_idx][param_idx] | ||
| assert hp_grad is not None, \ | ||
| f'high precision param has no gradient, lp param_id = {id(lp)} group_info = [{group_idx}][{param_idx}]' | ||
|
|
||
| hp_grad.data.add_(lp.grad.data.to(hp_grad.dtype).view(hp_grad.shape)) | ||
| hp_grad.data.add_(fp32_grad.data.view(hp_grad.shape)) | ||
|
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 corrected value goes only into |
||
| else: | ||
| hp_grad.data.add_(lp.grad.data.to(hp_grad.dtype).view(hp_grad.shape)) | ||
| lp._hp_grad = hp_grad | ||
| self.fp32_groups_has_gradients[group_idx][param_idx] = True | ||
|
|
||
|
|
||
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.
With BF16 parameters and FP32 accumulation under TP folding, this changes the gradients used by training, but no regression test is added and the commit provides only a test plan, not an on-device result. Existing tests in
test_autoep_autotp_bf16_folding_parity.pyuse mocks or exactly BF16-representable corrections, so they also pass with the old round-trip. Extend that suite with a TP2 training comparison whose reduction result is not BF16-representable, verify accumulated gradients and optimizer updates against an independent FP32 reference, and execute it on actual devices with hardware/results recorded. RootAGENTS.mdexplicitly requires this integration validation.AGENTS.md reference: AGENTS.md:L81-L82
Useful? React with 👍 / 👎.