Clear the gradient ZenFlow just offloaded, not param.grad - #8601
Open
vineethsaivs wants to merge 1 commit into
Open
vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
Mirror the base class: assert the gradient is present, and clear the attribute that was read. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
vineethsaivs
requested review from
loadams,
tjruwase and
tohtana
as code owners
September 20, 2026 00:10
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.
With ZenFlow, ZeRO-1 and a gradient accumulation dtype different from the parameter dtype, each window adds to the gradient the previous one already consumed, so gradients grow step after step.
ZenFlowZeroOptimizerParallel.async_inplace_copy_grad_to_fp32_buffer_from_gpuoverrides the base method only to write into the double-bufferedoverlap_grad. It reads the source throughget_param_gradient_attribute, which returnsparam.grad_accumwhenuse_grad_accum_attributeis set, but clearsparam.grad, which_fill_param_grad_accum_attributealready set to None.grad_accumsurvives, and that function adds into it when it is not None. The base clears throughclear_grad_attribute. The override also guardsgrad_accum is Nonewith two identical branches, both calling.view()on it. Mirror the base class: assert the gradient is present, and clear the attribute that was read.Test:
DS_ACCELERATOR=cpu python -m pytest tests/unit/runtime/zenflow/ -q. Two regressions fail before: the grad_accum case leaves the consumed gradient in place, and the missing-gradient case raises "'NoneType' object has no attribute 'view'". Both pass after; 15 CPU tests pass across the ZenFlow directory. They drive the real method against a minimal stand-in, so no engine is needed. yapf 0.43.0 and flake8 pass on both files. Executed on Apple M2 Pro CPU; no GPU or distributed run. The offload path needs a GPU, so upstream CI covers it end to end.