Fix broken remove_sharded_tensors public API and re-enable its unit test - #5759
Merged
Merged
Conversation
huthvincent
marked this pull request as ready for review
July 12, 2026 17:58
huthvincent
marked this pull request as draft
July 12, 2026 17:59
6 tasks
Member
|
/ok to test 5218f35 |
Every call to megatron.core.dist_checkpointing.remove_sharded_tensors raised AttributeError: since commit 2beb593 the wrapper invokes the method unbound on TorchDistSaveShardedStrategy, while it is defined only on TorchDistLoadShardedStrategy. Restore the previous behavior by calling it on a load-strategy instance. Repair two further breakages inside the method itself: replace reads of FileSystemWriter.metadata_path, which no longer exists in current PyTorch, with the equivalent metadata_filename computed in the same function, and convert the str checkpoint_dir to Path before joining file names so removal does not raise TypeError. Re-enable the covering unit test by dropping its flaky markers (with both markers it ran in no CI environment, which is how the API broke unnoticed) and update its post-removal metadata assertion for the common_state entry introduced by commit 40b1fd3, which updated only the pre-removal assertion. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Rui Zhu <rui.zhu.rz399@yale.edu>
huthvincent
force-pushed
the
fix/remove-sharded-tensors
branch
from
July 13, 2026 22:41
5218f35 to
bb92537
Compare
Contributor
Author
|
@cspades Same situation as #5756. After your |
Member
|
/ok to test bb92537 |
dimapihtar
approved these changes
Jul 16, 2026
jiemingz
approved these changes
Jul 16, 2026
Contributor
|
/ok to test c656b65 |
Phlip79
approved these changes
Jul 17, 2026
dimapihtar
enabled auto-merge
July 17, 2026 16:56
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29677835075 |
chochowski
pushed a commit
to chochowski/Megatron-LM
that referenced
this pull request
Jul 20, 2026
…est (NVIDIA#5759) Signed-off-by: Rui Zhu <rui.zhu.rz399@yale.edu> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Dmytro Pykhtar <37850217+dimapihtar@users.noreply.github.com> Signed-off-by: mchochowski <mchochowski@nvidia.com>
terminator123
pushed a commit
to 021ai/Megatron-LM
that referenced
this pull request
Aug 3, 2026
…est (NVIDIA#5759) Signed-off-by: Rui Zhu <rui.zhu.rz399@yale.edu> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Dmytro Pykhtar <37850217+dimapihtar@users.noreply.github.com>
svcnvidia-nemo-ci
pushed a commit
to dimapihtar/Megatron-LM
that referenced
this pull request
Aug 4, 2026
…est (NVIDIA#5759) Signed-off-by: Rui Zhu <rui.zhu.rz399@yale.edu> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Dmytro Pykhtar <37850217+dimapihtar@users.noreply.github.com> Signed-off-by: Dmytro Pykhtar <dpykhtar@nvidia.com>
This was referenced Aug 17, 2026
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.
What does this PR do?
Repairs
megatron.core.dist_checkpointing.remove_sharded_tensors, which is currently broken in three independent ways, and re-enables the unit test that would have caught this.serialization.py: the wrapper called the method unbound onTorchDistSaveShardedStrategy, but it is defined only onTorchDistLoadShardedStrategy→ every call raisedAttributeError. Now instantiates the load strategy, restoring the pre-2beb593b4 behavior (sharded_strategy.remove_sharded_tensors(...)on an instance).strategies/torch.py: the method readfs_writer.metadata_path, which no longer exists onFileSystemWriterin current PyTorch. It now uses themetadata_filenamecomputed two lines above (identical path, works across torch versions).strategies/torch.py:fs_writer.fs.rm_file(checkpoint_dir / f)raisedTypeErrorfor the documentedstrargument type; nowPath(checkpoint_dir) / f.Test changes (
tests/unit_tests/dist_checkpointing/test_serialization.py::test_remove_sharded_tensors):@pytest.mark.flaky/@pytest.mark.flaky_in_devmarkers. With both markers the test runs in no CI environment, which is precisely how the API could break unnoticed (timeline in the linked issue).common_state/shard_0_1: commit 40b1fd3 ("deprecate common strategy") updated the pre-removal assertion for the new common-state entry but could not update the post-removal one, since the test no longer reached it.Issue tracking
Linked issue: Fixes #5758
Contribution process
Pre-checks
Local verification (the CI unit test needs 8 GPUs; verified end-to-end at world_size=1 on a single GPU with the same save/remove/inspect sequence as the unit test, passing
strpaths to exercise fix 3):On unpatched
mainthe same script fails withAttributeError: type object 'TorchDistSaveShardedStrategy' has no attribute 'remove_sharded_tensors'; with only fix 1 applied it fails withAttributeError: 'FileSystemWriter' object has no attribute 'metadata_path'.