Skip to content

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

Open
wikilsh wants to merge 4 commits intoPaddlePaddle:release/2.5from
wikilsh:release/2.5
Open

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

Conversation

@wikilsh
Copy link

@wikilsh wikilsh commented Mar 18, 2026

Motivation

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

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

wikilsh and others added 3 commits March 12, 2026 22:02
## Motivation
Loading full model snapshot files in one shot causes large memory spikes
during elastic recovery. This change introduces chunked part-file loading
to reduce peak memory usage.

## Modifications
Refactor `_update_ipc_snapshot` to load weights in priority order:
1. Chunked part files (`model_state.tpR{id}.part{N}.pdparams`): load and
   apply weights incrementally, calling `gc.collect()` after each part to
   release memory promptly.
2. Single full pdparams file (legacy path).
3. Shared fallback directory (`/shared_ipc_meta/...`) as last resort.

Additional fixes:
- Use `paddle.distributed.get_rank()` instead of hardcoded `tp0` for
  proper rank awareness in multi-process scenarios.
- Raise explicit `FileNotFoundError` with a descriptive message when no
  snapshot file is found under any of the three paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…IPC snapshot

Add dot separator in snapshot file name (tp{rank}.{id}) to fix naming
ambiguity, and add legacy format (tp0{id}) as Priority 3 fallback for
backward compatibility with existing checkpoints.

Add unit tests covering all 4 loading priority branches and error path.

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

CLAassistant commented Mar 18, 2026

CLA assistant check
All committers have signed the CLA.

@paddle-bot
Copy link

paddle-bot bot commented Mar 18, 2026

Thanks for your contribution!

@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.45455% with 8 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.5@5dc898d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/rl/dynamic_weight_manager.py 85.45% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #6910   +/-   ##
==============================================
  Coverage               ?   68.97%           
==============================================
  Files                  ?      389           
  Lines                  ?    53175           
  Branches               ?     8344           
==============================================
  Hits                   ?    36679           
  Misses                 ?    13844           
  Partials               ?     2652           
Flag Coverage Δ
GPU 68.97% <85.45%> (?)

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