Repository navigation
Refactor activation checkpointing into a policy class hierarchy - #3674
Merged
Merged
Conversation
tianyu-l
requested review from
IvanKobzarev,
SherlockNoMad,
aditvenk,
fegin,
felipemello1,
sanketpurandare,
wconstab,
wwwjn and
xmfan
as code owners
June 15, 2026 07:12
Replace the flat `ActivationCheckpointConfig` (with a `mode` string) with a
`Configurable` policy hierarchy living next to its logic in
`torchtitan/distributed/activation_checkpoint.py`:
- `ActivationCheckpointing` (base) + `FullAC` / `SelectiveAC` /
`MemoryBudgetAC`, each a `Configurable` with a nested `Config` and an
`apply(model)` method. The old `apply_ac` free function and its helpers
are removed; callsites now do `ac_config.build(...).apply(model)`.
- The Trainer field becomes a tyro subcommand union
`ActivationCheckpointingConfig` (`selective` / `full` / `memory-budget` /
`none`), where `None` disables AC (replacing `mode="none"`).
- Users customize the per-op SAC save set by subclassing `SelectiveAC` and
overriding `get_save_ops()`, then assigning their `Config` in a Python
config function -- no registry, no string indirection.
Why: AC policy is a hardware/memory-budget knob (like `ParallelismConfig`),
not a model property, so it stays in the Trainer config and composes freely
with parallelism. The hierarchy gives each policy exactly its relevant
fields and a clean, typed extension point for tuning `save_ops`.
Other changes:
- Remove `model_compile_enabled` from the AC path; the
memory-budget-requires-compile check moves to `Trainer.Config.__post_init__`
(and forge engine).
- Drop the `early_stop` config field (universally `False`); hardcode
`early_stop=False` at the `ptd_checkpoint_wrapper` calls.
- RL trainer now defaults to `SelectiveAC.Config`.
- Rename `per_op_sac_force_recompute_mm_shapes_by_fqns` ->
`force_recompute_mm_shapes_by_fqns` and `_get_save_ops` ->
`_get_default_save_ops`.
CLI note: switching/disabling is now `activation-checkpoint:{full,none,
memory-budget}`; overriding an AC scalar requires naming the subcommand
first (e.g. `activation-checkpoint:selective
--activation-checkpoint.determinism-check none`). Policy selection in Python
config functions is unaffected.
Validation: pre-commit passes; AC unit tests pass; llama3 debugmodel with
`--debug.seed 42 --debug.deterministic` produces bitwise-identical loss and
grad_norm before vs. after (pure refactor).
wwwjn
approved these changes
Jun 15, 2026
| Annotated[SelectiveAC.Config, tyro.conf.subcommand("selective")] | ||
| | Annotated[FullAC.Config, tyro.conf.subcommand("full")] | ||
| | Annotated[MemoryBudgetAC.Config, tyro.conf.subcommand("memory-budget")] | ||
| | Annotated[None, tyro.conf.subcommand("none")] |
Contributor
There was a problem hiding this comment.
So we can also override it to be None via CLI activation-checkpointing:none?
Contributor
Author
There was a problem hiding this comment.
Yes -- activation-checkpoint:none.
That's the benefit of this code snippet.
aditvenk
approved these changes
Jun 15, 2026
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Jun 24, 2026
… sync) Upstream c5d93d1 replaced the flat ActivationCheckpointConfig with a Configurable policy hierarchy: FullAC / SelectiveAC / MemoryBudgetAC / None (None disables AC, replacing mode="none"). Callsites change from apply_ac(model, cfg, ...) to cfg.build(...).apply(model). The old ActivationCheckpointConfig symbol is gone from torchtitan.config, so ezpz could not import until replayed. Replayed: - agpt/parallelize.py + moe/parallelize.py: ac_config type -> ActivationCheckpointingConfig; the "if ac_config.mode != none: apply_ac(...)" guard becomes "if ac_config is not None: ac_config.build(dump_folder=...).apply(model)". - agpt/config_registry.py: ActivationCheckpointConfig(mode=full) -> FullAC.Config(); the agpt() wrapper's activation_checkpoint_mode knob now maps none->None, full->FullAC.Config(). - moe/config_registry.py: the moe() wrapper maps none->None, full->FullAC.Config(), selective->MoeSelectiveAC.Config(). - moe/activation_checkpoint.py: rewrote the _get_save_ops monkey-patch (broken by the refactor's _get_save_ops -> _get_default_save_ops rename and apply_ac removal) as MoeSelectiveAC, a clean SelectiveAC subclass overriding get_save_ops() to drop _c10d_functional.all_to_all_single -- the extension point the new API was designed for. Same effect: forces recompute of the EP a2a on backward, avoiding PR14's dangling AsyncCollectiveTensor save. Smoke (job 12469466): agpt_debugmodel with FullAC and moe_debugmodel with MoeSelectiveAC both ran 2 deterministic steps rc=0 (see prior commit for losses).
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Jun 24, 2026
…ytorch#3674) PR pytorch#3674 made activation_checkpoint a tyro subcommand union, so the old `--activation_checkpoint.mode=full` flag no longer parses (tyro errors with 'Unrecognized options'). The replacement is the positional token `activation-checkpoint:full`, which must come AFTER every --flag. Updated 7 scripts: - benchmark_80b, bitwise_sync_check, _smoke_agpt_2b_hf_n2, smoke_agpt_tp2: drop the --activation_checkpoint.mode=full flag, append activation-checkpoint:full as the last launch arg. - run_scaling_study_aurora: map the ac_mode var (none/full/selective) to an activation-checkpoint:<policy> token, appended last. - submit_agpt_80b_aurora_venv_failover: map ACKPT_MODE the same way, append after "$@". - submit_agpt_20b: comment-only example updated. These are launcher scripts (separate from the model-code replay in fa6f068 / bb38b95). bash -n clean on all 7.
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.
What
Replace the flat
ActivationCheckpointConfig(with amodestring) with aConfigurablepolicy hierarchy intorchtitan/distributed/activation_checkpoint.py:ActivationCheckpointing(base) +FullAC/SelectiveAC/MemoryBudgetAC, each aConfigurablewith a nestedConfigand anapply(model)method. The oldapply_acfree function (and_apply_full_ac/_apply_op_sac/_apply_ac_to_transformer_block) are removed; callsites now doac_config.build(...).apply(model).ActivationCheckpointingConfig(selective/full/memory-budget/none), whereNonedisables AC (replacingmode="none").SelectiveACand overridingget_save_ops(), then assigning theirConfigin a Python config function — no registry, no string indirection.Why
Activation checkpointing is a hardware / memory-budget knob (like
ParallelismConfig), not a model property. Keeping it in the Trainer config lets users mix-and-match AC policies with parallelism per hardware setup, while the class hierarchy gives each policy exactly its relevant fields and a clean, typed extension point for customizingsave_ops— the original motivation (the per-op SAC save set was previously hardcoded and identical for all models).Other changes
model_compile_enabledfrom the AC path; the memory-budget-requires-compile check moves toTrainer.Config.__post_init__(and the forge engine).early_stopconfig field (universallyFalse); hardcodeearly_stop=Falseat theptd_checkpoint_wrappercalls.SelectiveAC.Config.per_op_sac_force_recompute_mm_shapes_by_fqns→force_recompute_mm_shapes_by_fqnsand_get_save_ops→_get_default_save_ops.CLI behavior change
Switching/disabling AC from the CLI is now a tyro subcommand:
Overriding an AC scalar requires naming the subcommand first (top-level flags must precede the subcommand token). Policy selection in Python
config_registryfunctions is unaffected. Integration tests updated accordingly.Validation
pre-commit run --all-filespasses (flake8, ufmt, pyrefly, pydoclint, codespell, …).tests/unit_tests/test_activation_checkpoint.py).--debug.seed 42 --debug.deterministic— loss and grad_norm are bitwise-identical before vs. after (pure refactor).