Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detectron2/engine/train_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def run_step(self):
"""
assert self.model.training, "[AMPTrainer] model was changed to eval mode!"
assert torch.cuda.is_available(), "[AMPTrainer] CUDA is required for AMP training!"
from torch.cuda.amp import autocast
from detectron2.utils.torch_amp import autocast

start = time.perf_counter()
data = next(self._data_loader_iter)
Expand Down
8 changes: 8 additions & 0 deletions detectron2/utils/torch_amp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try:
from torch.amp import autocast as _autocast

def autocast(dtype=None):
return _autocast("cuda", dtype=dtype)

except ImportError:
from torch.cuda.amp import autocast # torch < 2.0