Skip to content

[Cherry-Pick][RL][BugFix][Optimization] Support chunked part files loading and fix model path format in IPC snapshot strategy(#6852)#6909

Open
wikilsh wants to merge 5 commits intoPaddlePaddle:release/2.4from
wikilsh:release/2.4
Open

[Cherry-Pick][RL][BugFix][Optimization] Support chunked part files loading and fix model path format in IPC snapshot strategy(#6852)#6909
wikilsh wants to merge 5 commits intoPaddlePaddle:release/2.4from
wikilsh:release/2.4

Conversation

@wikilsh
Copy link

@wikilsh wikilsh commented Mar 18, 2026

Motivation

Cherry-pick from develop branch PR #6852 to release/2.4.

In RL training elastic recovery via IPC snapshot, two issues existed in _update_ipc_snapshot:

  1. Memory spike: Loading a single large .pdparams file in one shot causes a significant memory spike, risking OOM during recovery.
  2. Ambiguous file naming: The snapshot path used model_state.tp{rank}{id} without a separator between rank and id, causing naming ambiguity (e.g., rank=1, id=234 and rank=12, id=34 both produce tp1234). Additionally, the rank was previously hardcoded as tp0, causing all ranks to load rank-0's shard in multi-process scenarios.

Modifications

Refactored _update_ipc_snapshot in fastdeploy/rl/dynamic_weight_manager.py with a four-level loading priority:

  1. Chunked part files (model_state.tp{rank}.{id}.part{N}.pdparams): Load multiple smaller shards sequentially in ascending numeric order, releasing memory between each chunk via gc.collect() to avoid memory spike.
  2. Single full file (model_state.tp{rank}.{id}.pdparams): Standard single-file loading with corrected naming format (dot separator added).
  3. Legacy format fallback (model_state.tp0{id}.pdparams): Backward-compatible fallback for checkpoints saved in the old format, ensuring smooth rolling upgrades.
  4. Shared directory fallback (/shared_ipc_meta/...): Oldest legacy fallback path preserved for compatibility.

Key fixes:

  • Add dot separator in snapshot file name: tp{rank}{id}tp{rank}.{id} to eliminate naming ambiguity
  • Replace hardcoded tp0 with paddle.distributed.get_rank() so each rank loads its own shard correctly
  • Add legacy format (Priority 3) as a transitional fallback to avoid load failures on existing checkpoints
  • Raise FileNotFoundError with clear message when no snapshot is found in any candidate path

Usage or Command

During RL elastic recovery, the trainer will automatically select the appropriate loading strategy based on available snapshot files. No additional configuration is needed.

To generate chunked part files on the trainer side, split the full state dict and save as:
model_state.tp{rank}.{id}.part0.pdparams
model_state.tp{rank}.{id}.part1.pdparams
...

Accuracy Tests

This PR only modifies the weight loading path and chunking strategy in _update_ipc_snapshot. It does not affect model forward computation or kernel logic. No accuracy regression is expected.

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.

    Added tests/rl/test_update_ipc_snapshot.py covering all 4 loading priority branches and the error path.

  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

    Original PR: [RL][BugFix][Optimization] Support chunked part files loading and fix model path format in IPC snapshot strategy #6852

zhangjie83 and others added 4 commits March 12, 2026 22:11
## Motivation
During elastic recovery, each rank should load its own model shard.
The hardcoded `tp0` caused all ranks to load rank-0's shard, leading
to incorrect weight initialization in multi-process scenarios.

## Modifications
- Replace hardcoded `tp0` with `paddle.distributed.get_rank()` in both
  the primary model path and the fallback `/shared_ipc_meta/` path
  inside `_update_ipc_snapshot`, so each rank correctly loads its own
  shard during elastic recovery.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
## Motivation
During elastic recovery, each rank should load its own model shard.
The hardcoded `tp0` caused all ranks to load rank-0's shard, leading
to incorrect weight initialization in multi-process scenarios.

## Modifications
- Replace hardcoded `tp0` with `paddle.distributed.get_rank()` in both
  the primary model path and the fallback `/shared_ipc_meta/` path
  inside `_update_ipc_snapshot`, so each rank correctly loads its own
  shard during elastic recovery.

Co-Authored-By: lishuaihui <lishuaihui@baidu.com>
…ry spike

Refactor _update_ipc_snapshot with 4-level loading priority:
1. Chunked part files (with gc.collect per part to reduce peak memory)
2. Single full pdparams file (new naming: tp{rank}.{id})
3. Legacy format (tp0{id})
4. Shared fallback directory (/shared_ipc_meta/)

Add unit tests covering all priority branches and error path.

Co-Authored-By: lishuaihui <lishuaihui@baidu.com>
@paddle-bot
Copy link

paddle-bot bot commented Mar 18, 2026

Thanks for your contribution!

@CLAassistant
Copy link

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

@paddle-bot paddle-bot bot added the contributor External developers label Mar 18, 2026
@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 85.18519% with 8 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.4@7f5f211). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/rl/dynamic_weight_manager.py 85.18% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.4    #6909   +/-   ##
==============================================
  Coverage               ?   56.39%           
==============================================
  Files                  ?      333           
  Lines                  ?    42553           
  Branches               ?     6481           
==============================================
  Hits                   ?    23997           
  Misses                 ?    16673           
  Partials               ?     1883           
Flag Coverage Δ
GPU 56.39% <85.18%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Parse part index from filename instead of using enumerate index,
  keeping logs and src_type consistent with actual file naming.
- Add validation for part file naming pattern; skip and warn on
  files that do not match the expected .partN. convention.

Co-Authored-By: wikilsh <wiki_hui@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants