Fix FutureWarning torch.cuda.amp.autocast(args...) is deprecated#6190
Fix FutureWarning torch.cuda.amp.autocast(args...) is deprecated#6190sw005320 merged 2 commits intoespnet:masterfrom
torch.cuda.amp.autocast(args...) is deprecated#6190Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6190 +/- ##
==========================================
- Coverage 20.63% 14.52% -6.12%
==========================================
Files 95 886 +791
Lines 10347 83874 +73527
==========================================
+ Hits 2135 12180 +10045
- Misses 8212 71694 +63482
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a deprecation warning by updating the torch autocast decorator to use the new API format.
- Updates the deprecated
torch.cuda.amp.autocastdecorator to the newtorch.amp.autocast('cuda')format - Addresses a FutureWarning that was being generated when using espnet2
| return (stft.real.pow(2) + stft.imag.pow(2) + eps).sqrt() | ||
|
|
||
| @torch.cuda.amp.autocast(enabled=False) | ||
| @torch.amp.autocast("cuda", enabled=False) |
There was a problem hiding this comment.
Consider adding a version check or try/except block to maintain compatibility with older PyTorch versions that may not support the new torch.amp.autocast API. This would prevent potential ImportError or AttributeError in environments with older PyTorch installations.
| @torch.amp.autocast("cuda", enabled=False) | |
| @autocast("cuda", enabled=False) |
|
Thanks a lot!
@Fhrozen, can you check it? It should be 2025xx |
|
Got it. I will check |
What did you change?
I modified
espnet2/enh/loss/criterions/time_domain.py:446:Why did you make this change?
There is a FutureWarning when I use espnet2:
.venv/lib/python3.10/site-packages/espnet2/enh/loss/criterions/time_domain.py:446: FutureWarning:
torch.cuda.amp.autocast(args...)is deprecated. Please usetorch.amp.autocast('cuda', args...)instead.Is your PR small enough?
Yes
Additional Context
Please update the PyPI package to latest version! It is still 202412!