Skip to content

Sort pipeline layer checkpoint shards by numeric model rank - #9146

Draft
adarshsm wants to merge 1 commit into
deepspeedai:masterfrom
adarshsm:fix/1381-pipe-ckpt-numeric-rank-sort
Draft

adarshsm wants to merge 1 commit into
deepspeedai:masterfrom
adarshsm:fix/1381-pipe-ckpt-numeric-rank-sort

Conversation

@adarshsm

Copy link
Copy Markdown

Fixes #1381

Problem

PipelineModule.ckpt_layer_path_list() returns the layer's checkpoint shards with ckpt_files.sort(), a plain string sort. The shard names embed rank_repr, which zero-pads each rank to two digits (model_00 … model_99). Once a layer is sharded across 100 or more model-parallel ranks, the string order is model_10, model_100, model_101, model_11, ….

load_state_dir() passes that list to SDLoaderFactory.get_sd_loader(), and the loader gives shard i to model-parallel rank i. So rank 11 loads the weights saved by rank 100, silently.

Fix

Sort the shard paths with a natural (numeric-aware) key, reusing the same re.split(r'(\d+)', …) idea as natural_keys in zero_to_fp32.py / ds_to_universal.py. Those helpers live in standalone scripts, so I kept the key inline instead of importing from them.

Test

TestPipeModuleCheckpointShardOrder creates shard files for ranks 0, 1, 9, 10, 11, 99, 100, 101 and asserts ckpt_layer_path_list() returns them in numeric order. Without the fix it fails (the model_100 / model_101 shards land before model_11); with it, it passes.

Run on CPU only (macOS, DS_ACCELERATOR=cpu, gloo, world_size 1). The change is a pure file-ordering fix and needs no GPU. yapf is clean on both changed files.

An earlier PR for this issue (#8452) was closed by its author without being merged, so there is no open PR for it.

🤖 Generated with Claude Code

ckpt_layer_path_list() sorted shard paths as plain strings. rank_repr
zero-pads ranks to two digits, so with 100+ model-parallel ranks the
order became model_10, model_100, model_11, ... and SDLoader handed
rank 11 the shard written by rank 100. Sort by the numeric rank instead.

Fixes deepspeedai#1381

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: adarshsm <24850536+adarshsm@users.noreply.github.com>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 22, 2026

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.

[BUG] String sort based on rank_repr may lead to problems?

1 participant