Skip to content

Commit

Permalink
Update on "[Doc] Add deprecated autocast comments for doc"
Browse files Browse the repository at this point in the history
# Motivation
We generalize a device-agnostic API `torch.amp.autocast` in [#125103](#125103).  After that,
- `torch.cpu.amp.autocast(args...)` is completely equivalent to `torch.amp.autocast('cpu', args...)`, and
- `torch.cuda.amp.autocast(args...)` is completely equivalent to `torch.amp.autocast('cuda', args...)`

no matter in eager mode or JIT mode.
Base on this point, we would like to deprecate `torch.cpu.amp.autocast` and `torch.cuda.amp.autocast` to **strongly recommend** developer to use `torch.amp.autocast` that is a device-agnostic API.

cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10

[ghstack-poisoned]
  • Loading branch information
guangyey committed May 13, 2024
1 parent 61f8d61 commit e20546c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions torch/cpu/amp/autocast_mode.py
@@ -1,4 +1,5 @@
from typing import Any
import warnings

import torch

Expand All @@ -22,6 +23,7 @@ def __init__(
self.device = "cpu"
self.fast_dtype = dtype
return
warnings.warn("torch.cpu.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead.")
super().__init__(
"cpu", enabled=enabled, dtype=dtype, cache_enabled=cache_enabled
)
Expand Down
2 changes: 2 additions & 0 deletions torch/cuda/amp/autocast_mode.py
@@ -1,5 +1,6 @@
import collections
import functools
import warnings

import torch

Expand Down Expand Up @@ -31,6 +32,7 @@ def __init__(
self.device = "cuda"
self.fast_dtype = dtype
return
warnings.warn("torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cpu', args...) instead.")
super().__init__(
"cuda", enabled=enabled, dtype=dtype, cache_enabled=cache_enabled
)
Expand Down

0 comments on commit e20546c

Please sign in to comment.