Skip to content

Migrate selective AC to torch_remat - #4893

Merged
anijain2305 merged 104 commits into
mainfrom
gh/anijain2305/47/head
Oct 7, 2026
Merged

anijain2305 merged 104 commits into
mainfrom
gh/anijain2305/47/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):


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.
image image

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 25, 2026
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 25, 2026
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 25, 2026
anijain2305 added a commit that referenced this pull request Sep 25, 2026
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 25, 2026
anijain2305 added a commit that referenced this pull request Sep 26, 2026
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 26, 2026
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Sep 26, 2026
[ghstack-poisoned]
@anijain2305
anijain2305 marked this pull request as ready for review October 5, 2026 18:39
[ghstack-poisoned]
return save_ops


def _disable_dynamo_lru_cache() -> None:

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.

can we delete this?

def _wrap_block(
self, module: nn.Module, *, base_fqn: str | None = None
) -> nn.Module:
return ptd_checkpoint_wrapper(

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.

So here's my wish, please see if it makes sense

  • original utils.checkpointing APIs are completely gone, in this PR
  • we have a base class which implements canonical remat, e.g. called ActivationRematConfig (I even think we don't need a Configurable owner for it)
    • this config is similar to current ActivationCheckpointing and has all the options like preserve_rng_state etc., but most importantly save_regions
  • It can have subclasses FullActivationRematConfig and DefaultActivationRematConfig as syntactic sugars.
    • FullActivationRematConfig freezes save_regions to be empty; those hardcoded to recompute=False still gets saved, e.g. select experts.
    • DefaultActivationRematConfig freezes save_regions to be exclude routed experts w13. I also wonder if, instead of introducing new fields like _remat_save_all_except in Module protocol, we would have regex to match / exclude regions (similar to what we do with MXFP8, optimizer, etc.)
      • I'm less sure about this name because "default" should be save everything for perf concern? But it doesn't sound very bad because people can just set the field to be None to mean NO REMAT.

@anijain2305 anijain2305 Oct 6, 2026 •

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.

I am doing something similar, but through multiple PRs, so that I can run a few sweeps at each intermediate stage to be safe.

This stack will be of 3 commits

  • Migrate SelectiveAC to remat
  • Migrate FullAC to remat
  • Do final renaming - this one will touch many files and we might want to bikeshed names, so keeping it separate.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
recompute_regions: list[str] = field(default_factory=list)
"""
Region glob patterns to recompute even when they match
``save_regions``. With ``save_regions=["*"]``, this lists the few

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.

in addition to this practical special case, please make explicit general comment that recompute_regions take precedence over save_regions, if both matches

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker 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