Skip to content

Add remat as an optional dependency - #4163

Merged
anijain2305 merged 1 commit into
mainfrom
remat-install
Aug 16, 2026
Merged

anijain2305 merged 1 commit into
mainfrom
remat-install

Conversation

@anijain2305

Copy link
Copy Markdown
Contributor

Non ghstack version of #4157

ghstack-source-id: 7c45846
Pull-Request: #4157
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 15, 2026
@anijain2305
anijain2305 merged commit 0d2438f into main Aug 16, 2026
30 checks passed
@tianyu-l
tianyu-l deleted the remat-install branch August 16, 2026 05:44
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants