Files
pytorch/torch/distributed/optim/_deprecation_warning.py
Yifu Wang 3d26c08dda Fix unintended deprecation warning in torch.distributed.optim (#140889)
We have a deprecation warning for scripted functional optimizer at module level in `torch/distributed/optim/__init__.py`. However, not all optimizers exposed by the module are scripted functional optimizers, causing some false deprecation warning (e.g. https://github.com/pytorch/pytorch/issues/139661).

This PR moves the deprecation warning to the `__init__` functions of the deprecated scripted functional optimizers.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/140889
Approved by: https://github.com/d4l3k, https://github.com/kwen2501, https://github.com/XilunWu
2024-11-18 02:34:51 +00:00

17 lines
547 B
Python

import warnings
import torch
@torch.jit.ignore # type: ignore[misc]
def _scripted_functional_optimizer_deprecation_warning(stacklevel: int = 0) -> None:
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.warn(
"`TorchScript` support for functional optimizers is deprecated "
"and will be removed in a future PyTorch release. "
"Consider using the `torch.compile` optimizer instead.",
DeprecationWarning,
stacklevel=stacklevel + 2,
)