mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 13:44:15 +08:00
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
17 lines
547 B
Python
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,
|
|
)
|