Repository navigation
Move FullAC to torch_remat - #5101
Merged
Merged
Conversation
[ghstack-poisoned]
anijain2305
commented
Oct 6, 2026
| # TODO: Currently this sync is blocking (thus exposed) and happens on the | ||
| # default compute stream. Need to assess if this is OK performance-wise. | ||
| tokens_per_expert_E_list = [] | ||
| for transformer_block, moe in _iter_moe_layers(model_parts): |
Contributor
Author
There was a problem hiding this comment.
This was only for FullAC - we already have this code
if not remat.is_recomputing():
with torch.no_grad():
self.tokens_per_expert_E.add_(masked_routing_map_TE.sum(dim=0))
anijain2305
marked this pull request as ready for review
October 6, 2026 21:49
anijain2305
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
October 6, 2026 21:49
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
approved these changes
Oct 6, 2026
| @@ -225,15 +225,12 @@ must not be used for numerical validation. | |||
|
|
|||
| ### Activation Checkpointing Debugging ### | |||
Contributor
There was a problem hiding this comment.
since we added remat.md -- prefer to move this section over there
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305
added a commit
that referenced
this pull request
Oct 7, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #5102 * #5101 * #4893 * __->__ #5131 ---- * Pin spmd_types to a main commit instead of the 0.2.5 release. It includes the fixes torch_remat activation checkpointing needs under tensor parallelism: metadata queries such as `stride()` and `storage_offset()` are no longer type checked, so saving a Partial region works, and `assert_type_like` / `assert_local_type_like` overrides keyed by a process group replace the source's entry for that axis instead of conflicting. * `_AuxLossInjection.spmd_typecheck` types its output with `rules.output` and declares `aux_loss`, which is only saved for backward, with `rules.ignore`, satisfying the new check that a hook accounts for every tensor argument. * spmd_types now ships type stubs: narrow a just-registered parameter or buffer before `assert_type`, and drop a `no_typecheck` suppression Pyrefly no longer needs.
anijain2305
added a commit
that referenced
this pull request
Oct 7, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #5102 * #5101 * __->__ #4893 * #5131 ---- Needs https://www.internalfb.com/diff/D123762808 This moves SelectiveAC to use torch remat. In future, we want to get rid of SelectiveAC as well and just have one RegionAC (or a better name) with possibly some good defaults for models. Currently, we keep the `SelectiveAC` name because its used at many places and there is some future work to remove it entirely. * SelectiveAC is now a fixed torch_remat policy: it saves every model-declared region except the routed-expert `w13`/`w2` grouped matmuls, and recomputes everything else. It shares the `_RematAC` base with RegionAC, which stays the way to choose a different policy; SelectiveAC can no longer be subclassed. * The operator-level save policy and `force_recompute_mm_shapes_by_fqns` are removed. The graph trainer keeps its own copy of the operator save set. * `configure_remat_regions` gains `save_all_except`, which SelectiveAC uses: it suits starting from no AC and recomputing only a few regions. * FullAC is unchanged and still uses PyTorch checkpointing. * The SAC + FlexInnerAttention restriction under SPMD typechecking is removed. <img width="1933" height="833" alt="image" src="https://github.com/user-attachments/assets/5937fbba-5e72-45db-acad-e6602e8b2340" /> <img width="1939" height="844" alt="image" src="https://github.com/user-attachments/assets/f8932afb-5f9c-4fc9-8c95-d0046af341f8" />
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
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.
Stack from ghstack (oldest at bottom):
save_regions=[], so everyactivation-checkpointing policy runs on torch_remat and the
torch.utils.checkpointpath is removed. Measured on Qwen3 MoE andDeepSeek V3 at EP4, activation and peak memory are unchanged, steps are
5-6 ms faster (routing decisions are retained instead of replayed), and
losses are bitwise identical.
metric and the expert token counts are counted once. The
// 2correction for FullAC token counts is removed.
checkpoint_wrapper.is removed.
preserve_rng_state=Falseand rejectsdebug=True,like the other policies.