FlagAI icon indicating copy to clipboard operation
FlagAI copied to clipboard

Core `flagai/` package uses deprecated `torch.cuda.amp.autocast` (7 sites)

Open xyf5432 opened this issue 3 months ago • 0 comments

Summary

Seven uses of the deprecated torch.cuda.amp.autocast in the core flagai/ package (not examples):

  1. flagai/model/predictor/predictor.py:21 — import, used at :459 (with autocast():) — this is the public Predictor API
  2. flagai/model/mm/AltDiffusion.py:17
  3. flagai/model/mm/AltDiffusionM18.py:17,19
  4. flagai/model/mm/Unets/Unet.py:19
  5. flagai/model/mm/modules/diffusionmodules/openaimodel.py:10
  6. flagai/model/mm/modules/diffusionmodules/util.py:136 (torch.cuda.amp.autocast(**ctx.gpu_autocast_kwargs))

torch.cuda.amp.autocast has been deprecated since torch 2.4 (and GradScaler since 2.3), scheduled for removal. On torch 2.4+ every call to these code paths (any Predictor-based inference, AltDiffusion inference/training) emits a FutureWarning; after removal it raises AttributeError/ModuleNotFoundError at import.

How to reproduce

pip install torch>=2.4
python -c "
import warnings; warnings.simplefilter('error', FutureWarning)
from torch.cuda.amp import autocast
"
FutureWarning: torch.cuda.amp.autocast is deprecated. Please use torch.amp.autocast('cuda', ...)

(Verified on torch 2.11; from torch.cuda.amp import autocast itself warns.)

Request

Migrate the seven core sites to torch.amp.autocast:

-from torch.cuda.amp import autocast as autocast
+from torch.amp import autocast

and for the kwargs form at util.py:136:

-                torch.cuda.amp.autocast(**ctx.gpu_autocast_kwargs):
+                torch.amp.autocast("cuda", **ctx.gpu_autocast_kwargs):

torch.amp.autocast("cuda") is available since torch 2.0; requirements.txt declares no torch floor, so no compatibility concern. Note: the same deprecation also applies to the vendored examples/ca-lora/src/section-4.1/opendelta/ copy, but that is third-party embedded code and best fixed upstream.

References

xyf5432 avatar Aug 21 '26 09:08 xyf5432