Skip to content

Make torch_checkpointing an optional dependency (#4123) - #4123

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
ivy-zhou:export-D115459276
Aug 13, 2026
Merged

meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
ivy-zhou:export-D115459276

Conversation

@ivy-zhou

@ivy-zhou ivy-zhou commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 12, 2026
@meta-codesync

meta-codesync Bot commented Aug 12, 2026

Copy link
Copy Markdown

@ivy-zhou has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115459276.

@fegin fegin left a comment

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.

Please ensure all CIs are green before landing. Please land this diff from internal system.

@meta-codesync meta-codesync Bot changed the title Declare torch_checkpointing runtime dependency Declare torch_checkpointing runtime dependency (#4123) Aug 12, 2026
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
Comment thread pyproject.toml

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.

maybe also modify requirements.txt?

@meta-codesync meta-codesync Bot changed the title Declare torch_checkpointing runtime dependency (#4123) Make torch_checkpointing an optional dependency Aug 12, 2026
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
@meta-codesync meta-codesync Bot changed the title Make torch_checkpointing an optional dependency Make torch_checkpointing an optional dependency (#4123) Aug 13, 2026
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
ivy-zhou force-pushed the export-D115459276 branch 2 times, most recently from 7e160f3 to 4bebc79 Compare August 13, 2026 21:10
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
@meta-codesync
meta-codesync Bot merged commit 41c36ae into pytorch:main Aug 13, 2026
23 checks passed
@ivy-zhou
ivy-zhou deleted the export-D115459276 branch August 13, 2026 21:32
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants