Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions deepspeed/runtime/bf16_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Comment on lines +519 to +522

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add and run a regression for FP32 folding accumulation

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.py use 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. Root AGENTS.md explicitly requires this integration validation.

AGENTS.md reference: AGENTS.md:L81-L82

Useful? React with 👍 / 👎.

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corrected value goes only into hp_grad, but apply_folding_correction_to_grad_buffer has already marked lp as corrected. With the default clear_lp_grads=False, lp.grad keeps the pre-reduction gradient under that marker. Copying fp32_grad back into lp.grad, as #8920 does, keeps the two consistent.

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

Expand Down
Loading