Repository navigation
Migrate selective AC to torch_remat - #4893
Merged
Merged
Conversation
[ghstack-poisoned]
This was referenced Sep 25, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
anijain2305
marked this pull request as ready for review
October 5, 2026 18:39
anijain2305
requested review from
SherlockNoMad,
aditvenk and
sanketpurandare
as code owners
October 5, 2026 18:39
tianyu-l
reviewed
Oct 6, 2026
| return save_ops | ||
|
|
||
|
|
||
| def _disable_dynamo_lru_cache() -> None: |
| def _wrap_block( | ||
| self, module: nn.Module, *, base_fqn: str | None = None | ||
| ) -> nn.Module: | ||
| return ptd_checkpoint_wrapper( |
Contributor
There was a problem hiding this comment.
So here's my wish, please see if it makes sense
- original
utils.checkpointingAPIs 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 aConfigurableowner for it)- this config is similar to current
ActivationCheckpointingand has all the options likepreserve_rng_stateetc., but most importantlysave_regions
- this config is similar to current
- It can have subclasses
FullActivationRematConfigandDefaultActivationRematConfigas syntactic sugars.FullActivationRematConfigfreezessave_regionsto be empty; those hardcoded torecompute=Falsestill gets saved, e.g. select experts.DefaultActivationRematConfigfreezessave_regionsto be exclude routed experts w13. I also wonder if, instead of introducing new fields like_remat_save_all_exceptin 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.
Contributor
Author
There was a problem hiding this comment.
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]
This was referenced Oct 6, 2026
tianyu-l
approved these changes
Oct 6, 2026
| 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 |
Contributor
There was a problem hiding this comment.
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]
This was referenced Oct 8, 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.
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
SelectiveACname because its used at many places and there is some future work to remove it entirely.region except the routed-expert
w13/w2grouped matmuls, and recomputeseverything else. It shares the
_RematACbase with RegionAC, which staysthe way to choose a different policy; SelectiveAC can no longer be
subclassed.
force_recompute_mm_shapes_by_fqnsareremoved. The graph trainer keeps its own copy of the operator save set.
configure_remat_regionsgainssave_all_except, which SelectiveAC uses: itsuits starting from no AC and recomputing only a few regions.