Repository navigation
Make torch_checkpointing an optional dependency (#4123) - #4123
Merged
Merged
Conversation
ivy-zhou
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 12, 2026 16:10
|
@ivy-zhou has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115459276. |
fegin
approved these changes
Aug 12, 2026
fegin
left a comment
Contributor
There was a problem hiding this comment.
Please ensure all CIs are green before landing. Please land this diff from internal system.
ivy-zhou
added a commit
to ivy-zhou/torchtitan
that referenced
this pull request
Aug 12, 2026
Summary: Declare `torch_checkpointing>=0.1.0` as a TorchTitan runtime dependency so source and wheel installations include the checkpoint backend used by the integration. Reviewed By: fegin Differential Revision: D115459276
ivy-zhou
force-pushed
the
export-D115459276
branch
from
August 12, 2026 18:45
49289ac to
b03fdf5
Compare
tianyu-l
approved these changes
Aug 12, 2026
Contributor
There was a problem hiding this comment.
maybe also modify requirements.txt?
ivy-zhou
force-pushed
the
export-D115459276
branch
from
August 12, 2026 20:57
b03fdf5 to
54749a7
Compare
ivy-zhou
added a commit
to ivy-zhou/torchtitan
that referenced
this pull request
Aug 12, 2026
Summary: Declare `torch_checkpointing>=0.1.0` under the `torch-checkpointing` optional extra so the legacy checkpoint manager remains usable without installing the alternate backend. Add an import-isolation characterization test that rejects any `torch_checkpointing` import from the legacy manager. Reviewed By: fegin Differential Revision: D115459276
ivy-zhou
force-pushed
the
export-D115459276
branch
from
August 13, 2026 18:39
54749a7 to
8b63cd6
Compare
ivy-zhou
added a commit
to ivy-zhou/torchtitan
that referenced
this pull request
Aug 13, 2026
Summary: Declare `torch_checkpointing>=0.1.0` under the `torch-checkpointing` optional extra so the legacy checkpoint manager remains usable without installing the alternate backend. Add an import-isolation characterization test that rejects any `torch_checkpointing` import from the legacy manager. Reviewed By: fegin Differential Revision: D115459276
ivy-zhou
added a commit
to ivy-zhou/torchtitan
that referenced
this pull request
Aug 13, 2026
Summary: Declare `torch_checkpointing>=0.1.0` under the `torch-checkpointing` optional extra so the legacy checkpoint manager remains usable without installing the alternate backend. Reviewed By: fegin Differential Revision: D115459276
ivy-zhou
force-pushed
the
export-D115459276
branch
2 times, most recently
from
August 13, 2026 21:10
7e160f3 to
4bebc79
Compare
This was referenced Aug 13, 2026
Summary: Declare `torch_checkpointing>=0.1.0` under the `torch-checkpointing` optional extra so the legacy checkpoint manager remains usable without installing the alternate backend. Reviewed By: fegin Differential Revision: D115459276
ivy-zhou
force-pushed
the
export-D115459276
branch
from
August 13, 2026 21:25
4bebc79 to
dda176b
Compare
ivy-zhou
added a commit
to ivy-zhou/torchtitan
that referenced
this pull request
Aug 14, 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` and `.ci/docker/requirements.txt`, so ordinary test and lint environments can import it without an extra install step. This supersedes the optional-dependency arrangement added in pytorch#4123. Selecting `TorchCheckpointingManager.Config` selects the implementation; the legacy manager and its config remain unchanged. Test Plan: `pytest tests/unit_tests` at the top of the stack, in a venv matching the CPU CI job (nightly cpu torch/torchvision, torchao, triton, and the repo and `.ci/docker` requirements): 3 failed, 612 passed, 35 skipped. The three failures (`test_chat_dataset`, `test_lora`, `test_qwen3_5_deltanet`) are the same three unmodified main fails in this venv. Also verified: - `TorchCheckpointingManager` subclasses `BaseCheckpointManager` and its `Config._owner` resolves to itself. - `torchtitan.components.checkpointer.torch_checkpointing` imports standalone. - `flake8` and `ufmt` are clean on the changed files.
ivy-zhou
added a commit
to ivy-zhou/torchtitan
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` and `.ci/docker/requirements.txt`, so ordinary test and lint environments can import it without an extra install step. This supersedes the optional-dependency arrangement added in pytorch#4123. Selecting `TorchCheckpointingManager.Config` selects the implementation; the legacy manager and its config remain unchanged. Test Plan: `pytest tests/unit_tests` at the top of the stack, in a venv matching the CPU CI job (nightly cpu torch/torchvision, torchao, triton, and the repo and `.ci/docker` requirements): 3 failed, 612 passed, 35 skipped. The three failures (`test_chat_dataset`, `test_lora`, `test_qwen3_5_deltanet`) are the same three unmodified main fails in this venv. Also verified: - `TorchCheckpointingManager` subclasses `BaseCheckpointManager` and its `Config._owner` resolves to itself. - `torchtitan.components.checkpointer.torch_checkpointing` imports standalone. - `flake8` and `ufmt` are clean on the changed files.
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.
Summary:
Declare
torch_checkpointing>=0.1.0under thetorch-checkpointingoptional extra so the legacy checkpoint manager remains usable without installing the alternate backend.Reviewed By: fegin
Differential Revision: D115459276