Summary
FunASR uses the deprecated torch.cuda.amp APIs in 37 files. The
hot paths that actually call them:
| File |
Line |
funasr/models/llm_asr/model.py |
8 from torch.cuda.amp import autocast; 7 call sites (586, 621, 886, 1162, 1206, 1554 with torch.cuda.amp.autocast(...)) |
funasr/train_utils/trainer_ds.py |
9 from torch.cuda.amp import autocast, GradScaler; 35 with torch.cuda.amp.autocast(enabled=True, dtype=dtype, ...) |
funasr/models/bat/model.py |
27 from torch.cuda.amp import autocast (guard only checks torch < 1.6, not the deprecation) |
…34 more files reference torch.cuda.amp |
see below |
Verified on torch 2.11.0:
>>> with torch.cuda.amp.autocast():
FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please
use `torch.amp.autocast('cuda', args...)` instead.
autocast has been deprecated since torch 2.4 and GradScaler since
torch 2.3. Both still work but print a FutureWarning on every call —
the current import guard in bat/model.py only covers torch < 1.6 and
does not protect against this.
Suggested fix
The replacement APIs (torch.amp.autocast('cuda', ...) since 2.0,
torch.amp.GradScaler('cuda', ...) since 2.3) are available in all
current torch versions. If older torch versions must remain supported,
gate on the version — 2.3 is the boundary because the import below needs
both names, and torch < 2.3's torch.cuda.amp is not yet deprecated:
if LooseVersion(torch.__version__) >= LooseVersion("2.3"):
from torch.amp import autocast, GradScaler
else:
from torch.cuda.amp import autocast, GradScaler
Installation has no torch version constraint
FunASR is a single-package monorepo (one setup.py → funasr; runtime/
holds platform deployments). The install path does not bound torch:
setup.py install_requires does not list torch at all — pip
never installs or constrains it.
- README.md:38-44
instructs pip install torch torchaudio (latest PyPI = torch 2.11),
then pip install funasr.
So on a fresh install with current PyPI, torch 2.11 is the documented
outcome and the deprecation warnings fire on every autocast/GradScaler
use.
(Also observed: the Triton GPU deployment image
runtime/triton_gpu/Dockerfile/Dockerfile.server
pins pip3 install torch==2.4.1 torchaudio==2.4.1 — pinned to match the
prebuilt kaldifeat CUDA wheel. torch 2.4.1 is itself the first release
where torch.cuda.amp.autocast is deprecated, so even that pinned
deployment ships the deprecated API.)
Files referencing torch.cuda.amp (37 total)
funasr/bin/train.py, funasr/bin/train_ds.py, funasr/models/campplus/model.py,
funasr/models/data2vec/data2vec.py, funasr/models/llm_asr/model.py,
funasr/models/xvector/e2e_sv.py, funasr/models/sanm_kws/model.py,
funasr/models/fsmn_kws/model.py, funasr/models/e_paraformer/pif_predictor.py,
funasr/models/lcbnet/model.py, funasr/models/scama/model.py,
funasr/models/emotion2vec/model.py, funasr/train_utils/trainer.py,
funasr/models/uniasr/model.py, funasr/models/fsmn_kws_mt/model.py,
funasr/train_utils/trainer_ds.py, funasr/models/transducer/model.py,
funasr/models/mfcca/e2e_asr_mfcca.py, funasr/models/sa_asr/e2e_sa_asr.py,
plus 18 more under funasr/models/ and funasr/train_utils/.
Summary
FunASR uses the deprecated
torch.cuda.ampAPIs in 37 files. Thehot paths that actually call them:
funasr/models/llm_asr/model.pyfrom torch.cuda.amp import autocast; 7 call sites (586, 621, 886, 1162, 1206, 1554with torch.cuda.amp.autocast(...))funasr/train_utils/trainer_ds.pyfrom torch.cuda.amp import autocast, GradScaler; 35with torch.cuda.amp.autocast(enabled=True, dtype=dtype, ...)funasr/models/bat/model.pyfrom torch.cuda.amp import autocast(guard only checks torch < 1.6, not the deprecation)torch.cuda.ampVerified on torch 2.11.0:
autocasthas been deprecated since torch 2.4 andGradScalersincetorch 2.3. Both still work but print a
FutureWarningon every call —the current import guard in
bat/model.pyonly covers torch < 1.6 anddoes not protect against this.
Suggested fix
The replacement APIs (
torch.amp.autocast('cuda', ...)since 2.0,torch.amp.GradScaler('cuda', ...)since 2.3) are available in allcurrent torch versions. If older torch versions must remain supported,
gate on the version — 2.3 is the boundary because the import below needs
both names, and torch < 2.3's
torch.cuda.ampis not yet deprecated:Installation has no torch version constraint
FunASR is a single-package monorepo (one
setup.py→funasr;runtime/holds platform deployments). The install path does not bound torch:
setup.pyinstall_requiresdoes not list torch at all — pipnever installs or constrains it.
instructs
pip install torch torchaudio(latest PyPI = torch 2.11),then
pip install funasr.So on a fresh install with current PyPI, torch 2.11 is the documented
outcome and the deprecation warnings fire on every autocast/GradScaler
use.
(Also observed: the Triton GPU deployment image
runtime/triton_gpu/Dockerfile/Dockerfile.serverpins
pip3 install torch==2.4.1 torchaudio==2.4.1— pinned to match theprebuilt kaldifeat CUDA wheel. torch 2.4.1 is itself the first release
where
torch.cuda.amp.autocastis deprecated, so even that pinneddeployment ships the deprecated API.)
Files referencing torch.cuda.amp (37 total)
funasr/bin/train.py,funasr/bin/train_ds.py,funasr/models/campplus/model.py,funasr/models/data2vec/data2vec.py,funasr/models/llm_asr/model.py,funasr/models/xvector/e2e_sv.py,funasr/models/sanm_kws/model.py,funasr/models/fsmn_kws/model.py,funasr/models/e_paraformer/pif_predictor.py,funasr/models/lcbnet/model.py,funasr/models/scama/model.py,funasr/models/emotion2vec/model.py,funasr/train_utils/trainer.py,funasr/models/uniasr/model.py,funasr/models/fsmn_kws_mt/model.py,funasr/train_utils/trainer_ds.py,funasr/models/transducer/model.py,funasr/models/mfcca/e2e_asr_mfcca.py,funasr/models/sa_asr/e2e_sa_asr.py,plus 18 more under
funasr/models/andfunasr/train_utils/.