Skip to content

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

Description

@xyf5432

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions