Skip to content

Accept gradient iterators in global norm helpers - #8518

Open
vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix-global-norm-iterables-20260914
Open

vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix-global-norm-iterables-20260914

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

Global norm calculation consumes a gradient iterator during validation and then raises; clipping a generator cannot complete a training step.

Cause: The helper advertises Iterable input but traverses it repeatedly and assumes len and indexing. The clipping wrapper needs the tensors again after norm calculation.

Fix: Materialize the input iterable once in each public helper before it is reused.

Test: DS_ACCELERATOR=cpu python -m pytest tests/unit/runtime/test_runtime_utils.py -k 'global_norm_accepts_iterables or clip_tensor_generator or test_call_to_str' -q. Five iterator regressions fail before. Fourteen targeted tests pass after: list/tuple/iterator norms for p=1,2,3,infinity, two SGD steps compared with PyTorch clipping, and an existing utility control. Validated on Apple Silicon CPU with PyTorch 2.10.0. No GPU or distributed run. Changed-file pre-commit passes.

Materialize the input iterable once in each public helper before it is reused.

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7127b87d3b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Total norm of the tensors (viewed as a single vector).
"""
assert isinstance(input_tensors, Iterable), f'expected Iterable type not {type(input_tensors)}'
input_tensors = list(input_tensors)

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 the required Signed-off-by trailer

This non-merge commit has no Signed-off-by: trailer in its commit message, so it violates the repository’s mandatory commit-signoff requirement and will not meet the project’s DCO/CI policy. Recreate the commit with git commit --signoff.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant