Repository navigation
Add remat as an optional dependency - #4163
Merged
Merged
Conversation
anijain2305
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 15, 2026 14:35
tianyu-l
approved these changes
Aug 16, 2026
ivy-zhou
added a commit
that referenced
this pull request
Aug 17, 2026
Summary: Introduce `TorchCheckpointingManager` as an independent `Configurable` component rather than adding backend selectors and branches to the legacy DCP `CheckpointManager`. `TorchCheckpointingManager.Config` intentionally adds no fields beyond `BaseCheckpointManager.Config`, but it must still be declared: `Config._owner` is set on the class that declares it, so a subclass that inherited `Config` unchanged would build the abstract base. It remains buildable for `Trainer` construction, while `TorchCheckpointingManager` constructs its fixed `torch_checkpointing` backend internally. The backend supplies the model and optimizer DTensor resharding schema, pinned-memory async staging, and the TorchTitan TCPStore barrier without exposing backend resharders or callbacks through TorchTitan configuration or Tyro. The manager lives at `components/checkpointer/torch_checkpointing.py`, named to match its siblings `base.py` and `dcp.py`. It is not re-exported from `checkpointer/__init__.py`; it is selected by config, not by import. When checkpointing is disabled, `load`, `save`, and `maybe_wait_for_staging` are no-ops, matching the DCP manager. When it is enabled they raise `NotImplementedError`: the routing lands in later changes, and they are stubbed rather than omitted because `BaseCheckpointManager` declares them abstract, so a partial implementation could not be instantiated at all. `torch_checkpointing` moves from an optional extra to a required dependency in `pyproject.toml`, superseding the optional-dependency arrangement added in #4123. Note this makes it the only core dependency with an unconditional `torch` requirement (`torch>=2.6.0`); the others declare torch only under extras. `pip install torchtitan` will therefore pull a stable torch wheel, which users who installed a nightly first should be aware of. It is deliberately NOT added to `.ci/docker/requirements.txt`. That file is symlinked from the repo root, so one entry feeds both the Docker image build and the lint job, and it is installed with dependencies -- which would drag a stable torch into an image whose stated invariant is that it ships no torch and every job installs a nightly. The image already installs the library, from git `@main` with `--no-deps`, in `.ci/docker/common/install_conda.sh`. The lint job needs it importable too, because pyrefly type-checks `components/checkpointer/torch_checkpointing.py`, so it gets the same `--no-deps` install, ordered after the nightly torch install so it cannot displace it. Selecting `TorchCheckpointingManager.Config` selects the implementation; the legacy manager and its config remain unchanged. Rebased onto main at 0d2438f ("Add remat as an optional dependency", #4163). That change added a `remat` optional-dependency group immediately after the `torch-checkpointing` group this commit deletes, so the two collided in `pyproject.toml`; the resolution keeps `remat` and drops `torch-checkpointing`, which is this commit's intent unchanged. Test Plan: `pytest tests/unit_tests` at the top of the rebased stack: 624 passed, 18 failed. Every failure reproduces identically on unmodified `remote/main` (0d2438f) in the same environment, so none are attributable to this change. They split into missing optional dependencies (`transformers` for the flux config and dataset tests, `fla` for the qwen3.5 rope test) and environment-specific kernel/compile failures (14 helion rope tests, one inductor C++ compile error in lora). Scoped to the code this stack touches -- `test_checkpoint`, `test_state_dict_keys`, `test_lr_scheduler`, `test_torch_checkpointing`, `test_config_manager` -- 85 passed, with only the known `transformers` failure. Also verified: - `TorchCheckpointingManager` subclasses `BaseCheckpointManager` and its `Config._owner` resolves to itself. - `torchtitan.components.checkpointer.torch_checkpointing` imports standalone. - The resolved `pyproject.toml` parses under `tomllib`, with `torch_checkpointing>=0.1.0` in the core dependency list and the optional groups reduced to exactly `dev` and `remat`. - `ufmt` and `codespell` clean on the changed files; `flake8 --config=.flake8` clean apart from one `F824` in `graph_trainer/simple_fsdp.py` that is pre-existing on main and untouched here. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/pytorch/torchtitan/pull/4058). * #4173 * #4172 * __->__ #4058
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.
Non ghstack version of #4157