8000 Add deprecated autocast comments for doc · pytorch/pytorch@4009f21 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4009f21

Browse files
committed
Add deprecated autocast comments for doc
ghstack-source-id: 81d22fb Pull Request resolved: #126062
1 parent afda668 commit 4009f21

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

torch/cpu/amp/autocast_mode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Any
23

34
import torch
@@ -8,7 +9,7 @@
89
class autocast(torch.amp.autocast_mode.autocast):
910
r"""
1011
See :class:`torch.autocast`.
11-
``torch.cpu.amp.autocast(args...)`` is equivalent to ``torch.autocast("cpu", args...)``
12+
``torch.cpu.amp.autocast(args...)`` is deprecated. Please use ``torch.amp.autocast("cpu", args...)`` instead.
1213
"""
1314

1415
def __init__(
@@ -22,6 +23,9 @@ def __init__(
2223
self.device = "cpu"
2324
self.fast_dtype = dtype
2425
return
26+
warnings.warn(
27+
"torch.cpu.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead."
28+
)
2529
super().__init__(
2630
"cpu", enabled=enabled, dtype=dtype, cache_enabled=cache_enabled
2731
)

torch/cuda/amp/autocast_mode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22
import functools
3+
import warnings
34

45
import torch
56

@@ -17,7 +18,7 @@
1718
class autocast(torch.amp.autocast_mode.autocast):
1819
r"""See :class:`torch.autocast`.
1920
20-
``torch.cuda.amp.autocast(args...)`` is equivalent to ``torch.autocast("cuda", args...)``
21+
``torch.cuda.amp.autocast(args...)`` is deprecated. Please use ``torch.amp.autocast("cuda", args...)`` instead.
2122
"""
2223

2324
def __init__(
@@ -31,6 +32,9 @@ def __init__(
3132
self.device = "cuda"
3233
self.fast_dtype = dtype
3334
return
35+
warnings.warn(
36+
"torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead."
37+
)
3438
super().__init__(
3539
"cuda", enabled=enabled, dtype=dtype, cache_enabled=cache_enabled
3640
)

0 commit comments

Comments
 (0)
0