Skip to content

feat: checkpoint_exclude_swap - #1348

Merged
github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
JiaqiSong-99:checkpoint_exclude_swap
Nov 7, 2026
Merged

github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
JiaqiSong-99:checkpoint_exclude_swap

Conversation

@JiaqiSong-99

@JiaqiSong-99 JiaqiSong-99 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Paired: GitHub #1348 ↔ GitCode !1882

What type of PR is this?

/kind feature

What does this PR do / why do we need it:

The existing checkpoint exclusion path keeps the outputs of recomputation-excluded regions and the activations required for backward on the device, increasing memory pressure when multiple SAVE regions are chained. This PR adds activation swapping to checkpoint_exclude_wrapper. Eligible outputs and saved tensors that cannot be reconstructed from replay inputs are offloaded to the CPU and restored on demand during backward, while ensuring that excluded regions execute only once and cached outputs are reused during replay.

  • API changes: Removes save_output and introduces swap, group_swap, and cpu_pool. Outputs are now always stored in the replay cache, so existing uses of save_output must be migrated.
  • Core implementation: CheckpointExcludeWrapper uses AsyncSaveOnCpu to handle tensors saved for backward and SwapManager to manage offloading, prefetching, and pinned-memory pools for excluded-region outputs.
  • Fallback and lifecycle: Tensors remain on the device when there is no active checkpoint or swap group, when the current group is the last group, or when they are ineligible for swapping. Replay continues to reuse the original outputs, and swap storage is released after backward completes.
  • Documentation: Updates docs/api/api_reference.md and docs/guide/activation_checkpoint.md with the new API, constraints, fallback behavior, and prefetch configuration.
  • Change statistics: 11 files changed, with +751/-198 lines, including 3 core implementation files, 2 documentation files, and 6 test files.
  • UT results: Ran the 4 affected UT files: 265 passed, 13 subtests passed, 4 warnings. Coverage includes API forwarding and argument validation, tensor offload and restoration, output registration, fallback paths, and storage cleanup.
  • NPU ST: Adds and updates scenarios under tests/torch/activation_memory/, covering chained SAVE regions, numerical and gradient parity, regular and grouped swapping, explicit pinned-memory pools, and storage cleanup. These tests were not run because the current environment has no NPU.

Which issue(s) this PR fixes:

Fixes #1328

Code review checklist [illustration]:

  • whether to verify the function's return value (It is forbidden to use void to mask the return values of security functions and self-developed functions. C++ STL functions can be masked if there is no problem)
  • Whether to comply with SOLID principle / Demeter's law
  • Whether there is UT test case && the test case is a valid (if there is no test case, please explain the reason)
  • Whether the API change is involved
  • Whether official document modification is involved

@JiaqiSong-99
JiaqiSong-99 force-pushed the checkpoint_exclude_swap branch 2 times, most recently from 30ccb8e to 75e9b60 Compare November 2, 2026 07:56
@JiaqiSong-99 JiaqiSong-99 changed the title checkpoint_exclude_swap feat: checkpoint_exclude_swap Nov 2, 2026
@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/check-pr

@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1409 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 74%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- activation_memory 202.26062s 120.0s
- shard 163.946s 300.0s
- auto_models 97.646s 150.0s
- pipeline_parallel 543.909s 600.0s
- optimizer 256.28s 300.0s
- accuracy 89.117s 120.0s
- clip_grad 75.575s 120.0s
- tensor_parallel 199.856s 300.0s
- swap_optimizer 277.442s 300.0s
- fully_shard 285.049s 600.0s
- multicore 114.88513s 120.0s
- distributed_checkpoint 74.205s 120.0s
- expert_parallel 146.63062s 200.0s
- context_parallel 70.481s 120.0s
- init_weights 68.037s 118.75s
- dtensor 67.95s 120.0s
- process_group 63.629s 90.0s
- llama3_examples 57.528s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1409
Smoke_Ascend910b_Torch FAILURE 1409

@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/retest

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1442 is running. Please wait a moment... (Link)

@mindspore-ci-bot

Copy link
Copy Markdown
Contributor

Hi @JiaqiSong-99, thanks for your contribution!

This pull request is currently waiting for the CLA Assistant check to pass before the CI process can continue.

Please follow the signing link shown by CLA Assistant on this PR. If you have already signed the CLA but the check is still failing, please make sure that all email addresses used in your commits are added to and verified on your GitHub account.

After updating your email settings or signing the CLA, please click Recheck in the CLA Assistant comment/check so the status can be refreshed.

Once the CLA Assistant check passes, CI will continue automatically.

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 74%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- auto_models 125.227s 150.0s
- pipeline_parallel 965.064s 600.0s
- shard 258.263s 300.0s
- fully_shard 482.046s 600.0s
- optimizer 387.108s 300.0s
- accuracy 138.659s 120.0s
- clip_grad 139.132s 120.0s
- tensor_parallel 314.814s 300.0s
- process_group 118.673s 90.0s
- swap_optimizer 391.444s 300.0s
- context_parallel 113.805s 120.0s
- distributed_checkpoint 152.416s 120.0s
- activation_memory 227.64225s 120.0s
- multicore 147.87338s 120.0s
- dtensor 109.461s 120.0s
- expert_parallel 204.02625s 200.0s
- llama3_examples 98.853s 120.0s
- init_weights 94.934s 118.75s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1442
coverage FAILURE 1442
UT_TEST FAILURE 1442
Smoke_Ascend910b_Torch FAILURE 1442

@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1477 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 75%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- activation_memory 240.788s 150.0s
- shard 158.929s 300.0s
- optimizer 228.544s 300.0s
- auto_models 92.508s 150.0s
- pipeline_parallel 529.795s 600.0s
- multicore 105.65187s 120.0s
- fully_shard 278.53s 600.0s
- expert_parallel 136.157s 200.0s
- tensor_parallel 202.231s 300.0s
- swap_optimizer 270.718s 300.0s
- context_parallel 71.487s 120.0s
- accuracy 68.597s 120.0s
- init_weights 65.025s 118.75s
- clip_grad 71.17s 120.0s
- distributed_checkpoint 73.162s 120.0s
- dtensor 64.699s 120.0s
- process_group 58.071s 90.0s
- llama3_examples 62.479s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1477
Smoke_Ascend910b_Torch FAILURE 1477

@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1490 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ✅ SUCCESS 75%/100% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- pipeline_parallel 666.539s 600.0s
- accuracy 114.726s 120.0s
- shard 204.983s 300.0s
- distributed_checkpoint 80.19s 120.0s
- clip_grad 109.097s 120.0s
- optimizer 302.083s 300.0s
- auto_models 103.318s 150.0s
- fully_shard 372.486s 600.0s
- activation_memory 277.157s 300.0s
- dtensor 93.604s 120.0s
- process_group 94.002s 90.0s
- context_parallel 86.208s 120.0s
- multicore 125.26425s 120.0s
- tensor_parallel 252.765s 300.0s
- llama3_examples 89.605s 120.0s
- swap_optimizer 333.142s 300.0s
- expert_parallel 163.98262s 200.0s
- init_weights 86.158s 118.75s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ✅ SUCCESS 1490

@JiaqiSong-99

Copy link
Copy Markdown
Contributor Author

/check-pr

@github-actions
github-actions Bot merged commit ec373e0 into mindspore-ai:master Nov 7, 2026
7 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: checkpoint_exclude_wrapper supports SAVE/SWAP

6 participants