pytorch config_error ai_generated true

RuntimeError: torch.cuda.amp.autocast only works with CUDA

ID: pytorch/amp-autocast-error

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

AMP autocast used without CUDA or with wrong device.

generic

Workarounds

  1. 92% success Use torch.amp.autocast(device_type="cuda") for GPU, "cpu" for CPU
  2. 88% success Check torch.cuda.is_available() before enabling AMP

Dead Ends

Common approaches that don't work:

  1. Disable AMP entirely 68% fail

    Slower training

  2. Force CUDA context on CPU 90% fail

    Crash