[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exception
Summary
In deepspeed/runtime/pipe/engine.py:287-295,658-667,1212-1220 (commit a695f646974c6c92da2a9028bbafde8bb28bad1e), both PipelineEngine._exec_reduce_grads() and PipelineEngine._exec_optimizer_step() bracket fallible collective/optimizer calls with:
self._force_grad_boundary = True
self._take_model_step(lr_kwargs) # or allreduce_gradients / _bf16_reduce_grads
self._force_grad_boundary = False
Neither method uses try ... finally: self._force_grad_boundary = False. If a transient communication failure, OOM, or step error occurs (and is caught by a caller / elastic recovery loop), self._force_grad_boundary remains permanently True. Because is_gradient_accumulation_boundary() returns self._force_grad_boundary, every subsequent micro-batch across all later steps is falsely treated as an accumulation boundary, corrupting pipeline gradient accumulation scheduling.
Affected Location
- Repository:
deepspeedai/DeepSpeed(a695f646974c6c92da2a9028bbafde8bb28bad1e, present atHEAD) - File & lines:
deepspeed/runtime/pipe/engine.py:287-295(_exec_reduce_grads),658-667(is_gradient_accumulation_boundary),1212-1220(_exec_optimizer_step)
Minimal Standalone Reproduction
eng = PipelineEngine.__new__(PipelineEngine)
eng._force_grad_boundary = False
eng.wall_clock_breakdown = lambda: False
def fail_step(lr_kwargs=None):
raise RuntimeError("transient OOM in _take_model_step")
eng._take_model_step = fail_step
try:
eng._exec_optimizer_step()
except RuntimeError:
pass
assert eng.is_gradient_accumulation_boundary() is True # Permanently stuck True!
The same sticky state tear occurs when allreduce_gradients() / _bf16_reduce_grads() raises inside _exec_reduce_grads().
Suggested Fix
Reset self._force_grad_boundary = False inside try ... finally: blocks in both _exec_reduce_grads() and _exec_optimizer_step().