Skip to content

Remove the legacy torchtitan.components.checkpoint_utils import path - #4241

Merged
ivy-zhou merged 1 commit into
mainfrom
pr4241
Aug 20, 2026
Merged

ivy-zhou merged 1 commit into
mainfrom
pr4241

Conversation

@ivy-zhou

Copy link
Copy Markdown
Contributor

Summary:
components/checkpoint_utils.py became a re-export shim when the optimizer and
checkpointer components were grouped into packages. Unlike the lr_scheduler
shim removed in #4172, this one forwarded to two different destinations at
once, which is what made it worth deleting rather than keeping: reading an
import of checkpoint_utils told you nothing about whether the symbol was
optimizer plumbing or checkpointer plumbing.

Route each of the four importers to the module that actually defines the
symbol. canonical_fqn lives in checkpointer/utils.py; init_optim_state,
get_flat_optim_state_dict, and load_flat_optim_state_dict live in
optimizer/utils.py. This also settles the naming objection fegin raised on
#4140, that canonical_fqn does not belong under an optimizer-shaped name --
its importer in the rl trainer now names the checkpointer package directly.

The three state-dict helpers are imported from optimizer.utils rather than
re-exported through optimizer/__init__.py. They are low-level DCP plumbing
with two callers between them, not part of the package's public surface, which
stays OptimizersContainer, LRSchedulersContainer, ParamGroupConfig, and
default_adamw.

This is an import-path change only; no runtime behavior changes.

Test Plan:
pytest tests/unit_tests/test_state_dict_keys.py tests/unit_tests/test_checkpoint.py tests/unit_tests/test_lr_scheduler.py tests/unit_tests/test_optimizer_param_groups.py tests/unit_tests/test_torch_checkpointing.py: 77 passed, 4 subtests passed.

test_legacy_checkpoint_utils_imports, which asserted the shim's symbols were
identical to the submodule's, is dropped -- it cannot outlive the shim.

test_legacy_checkpoint_utils_can_be_imported_first is kept but retargeted, as
test_state_dict_helpers_can_be_imported_first. It guards a real property
rather than the shim: the optimizer and checkpointer package __init__
files import from each other, so importing either leaf utils module first in
a fresh interpreter must not close an import cycle. It now subtests both leaf
modules instead of the single shim.

Also verified:

  • No checkpoint_utils references remain anywhere in the repo, across all file
    types, not only Python.
  • import torchtitan.components.checkpoint_utils now raises
    ModuleNotFoundError.
  • ufmt and flake8 --config=.flake8 clean on the four changed files.

Summary:
`components/checkpoint_utils.py` became a re-export shim when the optimizer and
checkpointer components were grouped into packages. Unlike the lr_scheduler
shim removed in #4172, this one forwarded to two different destinations at
once, which is what made it worth deleting rather than keeping: reading an
import of `checkpoint_utils` told you nothing about whether the symbol was
optimizer plumbing or checkpointer plumbing.

Route each of the four importers to the module that actually defines the
symbol. `canonical_fqn` lives in `checkpointer/utils.py`; `init_optim_state`,
`get_flat_optim_state_dict`, and `load_flat_optim_state_dict` live in
`optimizer/utils.py`. This also settles the naming objection fegin raised on
#4140, that `canonical_fqn` does not belong under an optimizer-shaped name --
its importer in the rl trainer now names the checkpointer package directly.

The three state-dict helpers are imported from `optimizer.utils` rather than
re-exported through `optimizer/__init__.py`. They are low-level DCP plumbing
with two callers between them, not part of the package's public surface, which
stays `OptimizersContainer`, `LRSchedulersContainer`, `ParamGroupConfig`, and
`default_adamw`.

This is an import-path change only; no runtime behavior changes.

Test Plan:
`pytest tests/unit_tests/test_state_dict_keys.py
tests/unit_tests/test_checkpoint.py tests/unit_tests/test_lr_scheduler.py
tests/unit_tests/test_optimizer_param_groups.py
tests/unit_tests/test_torch_checkpointing.py`: 77 passed, 4 subtests passed.

`test_legacy_checkpoint_utils_imports`, which asserted the shim's symbols were
identical to the submodule's, is dropped -- it cannot outlive the shim.

`test_legacy_checkpoint_utils_can_be_imported_first` is kept but retargeted, as
`test_state_dict_helpers_can_be_imported_first`. It guards a real property
rather than the shim: the `optimizer` and `checkpointer` package `__init__`
files import from each other, so importing either leaf `utils` module first in
a fresh interpreter must not close an import cycle. It now subtests both leaf
modules instead of the single shim.

Also verified:
- No `checkpoint_utils` references remain anywhere in the repo, across all file
  types, not only Python.
- `import torchtitan.components.checkpoint_utils` now raises
  `ModuleNotFoundError`.
- `ufmt` and `flake8 --config=.flake8` clean on the four changed files.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 20, 2026
@ivy-zhou
ivy-zhou merged commit d5fb6d1 into main Aug 20, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl 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