refactor(trainer): make activation checkpointing operator-based - #3419
Merged
Merged
Conversation
S1ro1
marked this pull request as ready for review
August 28, 2026 12:52
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1fe9da7. Configure here.
S1ro1
force-pushed
the
feat/selective-activation-checkpointing
branch
from
August 28, 2026 20:31
7e0ac18 to
c184918
Compare
S1ro1
force-pushed
the
feat/selective-activation-checkpointing
branch
from
August 28, 2026 23:29
c184918 to
4a08217
Compare
S1ro1
force-pushed
the
feat/selective-activation-checkpointing
branch
from
August 30, 2026 14:14
4c27bb3 to
7ab7995
Compare
samsja
reviewed
Aug 30, 2026
samsja
reviewed
Aug 30, 2026
samsja
reviewed
Aug 30, 2026
samsja
reviewed
Aug 30, 2026
samsja
reviewed
Aug 30, 2026
samsja
approved these changes
Aug 31, 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.

Summary
mode = "full"as the default. Full mode retains only mandatory non-replayable operations and recomputes everything else; selective mode additionally retains configured expensive operations through the same Prime-owned policy.forward; GLM DSA keeps only its substantivemla_latentsandmla_up_projhelpers.main, and update FlashAttention 4 to0251105with the shared TVM FFI version required by vLLM.Runtime contract
freqselects whole transformer blocks; the dispatched operator and selected target set determine whether selective AC saves or recomputes its result.mxfp8_moeinside its custom-op implementation. MXFP8 grouped compute still resolves it during runtime setup because the exported grouped GEMM is already an operator boundary.Configuration
Omitting
targetsuses the public Prime defaults. Any explicit list replaces those defaults; an empty list retains only the mandatory operations.Validation
uv lock --check, andgit diff --checkpassed.samsja/mini-glm-moetraining smoke after rebasing onto the merged MoE runtime.[heads, total_tokens]LSE layout; the ring fake and backward paths enforce that single contract.dq,dk, anddv.Hardware boundary
Note
High Risk
Touches core training memory/throughput (activation checkpointing), distributed MoE/DeepEP/ring attention autograd, and compile boundaries—incorrect replay or double-counted routing would show up as silent wrong grads or NCCL deadlocks.
Overview
Replaces layer-specific selective activation checkpointing with whole-block non-reentrant checkpointing driven by a PyTorch selective operator policy (
activation_checkpointing.py). Semantic targets likenorm/attn_projare gone;model.ac.targetsis now optional operator names or namespaces that replace Prime’s defaults, while mandatory saves still cover MoE routing/top-k, DeepEP, and CUDA→CPU copies.Registers distributed and kernel paths as
torch.librarycustom ops so checkpoint replay, autograd, and compile see the same boundaries: newprime_rl_collectivesfor EP/CP all-to-all and gather/reduce-scatter,deepep::combine, unifiedprime_rl_ringring attention (FA2/FA3/FA4),prime_rl::sparse_mla, FP8/grouped FP8 GEMMs, andrecord_moe_routing_statisticsso routing counters are not double-applied on recompute. Inlineautograd.Functionwrappers in token dispatch, Mamba CP, and ring attention are removed in favor of these ops.Simplifies trainer wiring and models:
apply_acalways wraps whole transformer blocks; the oldlayers/checkpointing.pyhook layer is deleted and attention modules no longer expose checkpoint-onlyattn_projections/output_projsplits. FSDP backward prefetch now includes the last block’s MoE experts/router. Docs, examples, and benchmarks drop legacy selective target lists; flash-attn-4 is bumped to0251105with a pinned apache-tvm-ffi override.Reviewed by Cursor Bugbot for commit 3a51c78. Bugbot is set up for automated code reviews on this repo. Configure here.