Skip to content

Move FullAC to torch_remat - #5101

Merged
anijain2305 merged 14 commits into
mainfrom
gh/anijain2305/60/head
Oct 10, 2026
Merged

anijain2305 merged 14 commits into
mainfrom
gh/anijain2305/60/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):


  • FullAC is now a fixed RegionAC preset with save_regions=[], so every
    activation-checkpointing policy runs on torch_remat and the
    torch.utils.checkpoint path is removed. Measured on Qwen3 MoE and
    DeepSeek 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.
  • Replay no longer re-runs forward side effects under FullAC: the aux-loss
    metric and the expert token counts are counted once. The // 2
    correction for FullAC token counts is removed.
  • Flux checkpoints its blocks with torch_remat instead of checkpoint_wrapper.
  • The dynamo LRU-cache workaround for PyTorch checkpointing with PP and Flex
    is removed.
  • FullAC now requires preserve_rng_state=False and rejects debug=True,
    like the other policies.

[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added the ciflow/rl label Oct 6, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label 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):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
anijain2305 marked this pull request as ready for review October 6, 2026 21:49
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 6, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Comment thread docs/debugging.md Outdated
@@ -225,15 +225,12 @@ must not be used for numerical validation.

### Activation Checkpointing Debugging ###

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we added remat.md -- prefer to move this section over there

[ghstack-poisoned]
[ghstack-poisoned]
[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]
@anijain2305
anijain2305 changed the base branch from gh/anijain2305/60/base to main October 10, 2026 04:58
@anijain2305
anijain2305 merged commit 448b9c8 into main Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants