Skip to content

Fix ZeRO-3 checkpoint conversion with --debug - #8530

Open
vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix-debug-zero3-export-20260915
Open

vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix-debug-zero3-export-20260915

Conversation

@vineethsaivs

@vineethsaivs vineethsaivs commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

The checkpoint converter crashes with --debug on ZeRO-3 checkpoints.

_zero3_merge_trainable_params receives each rank's optimizer groups as a list and the debug block treats it as a tensor, reading .shape and .numel() off the list. Print the per-group shapes instead, the way the ZeRO-2 debug block above it already does, and drop the avail_numel reassignment: it recomputed, wrongly, a value the top of the function already has.

Tests: DS_ACCELERATOR=cpu python -m pytest tests/unit/checkpoint/test_convert_checkpoint.py -k 'not TestCheckpointConvert' -q. Debug export fails before. Five converter tests pass after. A separate real ZeRO-3 Adam step with two parameter groups, checkpoint save and debug export produces matching weights. Changed-file pre-commit passes. Apple M2 Pro CPU, PyTorch 2.10, one-rank Gloo; no GPU run.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve CI for this PR? The focused regression tests and repository lint checks pass locally.

@alanhuangyoo alanhuangyoo left a comment

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.

Ran your test on CPU both ways: master dies at the same AttributeError: 'list' object has no attribute 'shape', passes on this branch.

One thing worth adding to the description: the avail_numel line you removed wasn't only crashing. It replaced the correct group sum from the top of the function with fp32_flat_groups[0].numel(), and avail_numel is what the offset != avail_numel check at the end compares against, so with --debug that check was looking at the wrong number too.

The zero-2 debug block at :317 already prints shapes per group, so this just brings stage 3 in line.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Good catch, added to the description: the shadowed avail_numel also fed the offset != avail_numel sanity check at the end, so under --debug that check was comparing against the wrong number. Thanks for running it.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Correcting myself: that reassignment never actually ran. The .shape print above it is the first statement in the debug block and raises the same AttributeError, so the final offset != avail_numel check always used the correct sum from the top of the function. It was a stale line, not a wrong comparison. I have taken that claim back out of the description.

@alanhuangyoo

Copy link
Copy Markdown
Contributor

You're right, the print dies first so that line never ran. My mistake, thanks for checking.

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The focused fix matches ZeRO-3 data structures and is covered by an end-to-end converter test.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes ZeRO-3 checkpoint conversion crashes when debug logging handles optimizer groups.

Changes:

  • Log each rank’s optimizer-group shapes correctly.
  • Preserve the existing valid avail_numel calculation.
  • Add a CLI regression test for debug export.
File Description
deepspeed/​utils/​zero_to_fp32.py Corrects ZeRO-3 debug handling.
tests/​unit/​checkpoint/​test_convert_checkpoint.py Adds debug-export regression coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@alanhuangyoo

Copy link
Copy Markdown
Contributor

This looks right to me. avail_numel is already defined at the top of the function and the check at the end uses it, so dropping the reassignment is safe.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Thanks for checking it.

Print individual group shapes and reuse the existing total element count.

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

This branch has not been deployed

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

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants