Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix FutureWarning torch.cuda.amp.autocast(args...) is deprecated#6190

Merged
sw005320 merged 2 commits intoespnet:masterfrom
KanTakahiro:kan_PR_250724
Jul 25, 2025
Merged

Fix FutureWarning torch.cuda.amp.autocast(args...) is deprecated#6190
sw005320 merged 2 commits intoespnet:masterfrom
KanTakahiro:kan_PR_250724

Conversation

@KanTakahiro
Copy link
Contributor

@KanTakahiro KanTakahiro commented Jul 24, 2025

What did you change?

I modified espnet2/enh/loss/criterions/time_domain.py:446:

-    @torch.cuda.amp.autocast(enabled=False)
+    @torch.amp.autocast('cuda', enabled=False)

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 use torch.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!

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 24, 2025
@mergify mergify bot added the ESPnet2 label Jul 24, 2025
@dosubot dosubot bot added the Bugfix label Jul 24, 2025
@codecov
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 14.52%. Comparing base (412aa11) to head (6bdc625).
⚠️ Report is 6 commits behind head on master.

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     
Flag Coverage Δ
test_python_espnetez 12.79% <100.00%> (?)
test_utils 20.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sw005320 sw005320 requested a review from Copilot July 25, 2025 21:53
@sw005320 sw005320 added this to the v.202506 milestone Jul 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.autocast decorator to the new torch.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)
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
@torch.amp.autocast("cuda", enabled=False)
@autocast("cuda", enabled=False)

Copilot uses AI. Check for mistakes.
@sw005320 sw005320 merged commit 900308a into espnet:master Jul 25, 2025
40 checks passed
@sw005320
Copy link
Contributor

Thanks a lot!

Please update the PyPI package to latest version! It is still 202412!

@Fhrozen, can you check it? It should be 2025xx

@Fhrozen
Copy link
Member

Fhrozen commented Jul 25, 2025

Got it. I will check

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

Labels

Bugfix ESPnet2 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants