yolov5 icon indicating copy to clipboard operation
yolov5 copied to clipboard

Update torch.cuda.amp to torch.amp

Open jacobdbrown4 opened this issue 1 year ago β€’ 27 comments

torch.cuda.amp is deprecated as of Pytorch 2.4. This PR updates use to torch.amp. This gets rid of the

FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead.
  with torch.cuda.amp.autocast(amp):

warning as mentioned in #13226.

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Update to use latest CUDA AMP (Automatic Mixed Precision) API across various files for better compatibility and performance.

πŸ“Š Key Changes

  • Replaced torch.cuda.amp.autocast with torch.amp.autocast("cuda") in multiple files.
  • Replaced torch.cuda.amp.GradScaler with torch.amp.GradScaler("cuda").

🎯 Purpose & Impact

  • Improved Compatibility: Ensures that the code remains compatible with the latest PyTorch changes, reducing the risk of future issues.
  • Performance: Leverages CUDA's improved automatic mixed precision to potentially enhance computational efficiency.
  • Maintenance: Simplifies code adjustments related to AMP, making future updates easier to manage.

jacobdbrown4 avatar Aug 05 '24 19:08 jacobdbrown4

All Contributors have signed the CLA. βœ…
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Aug 05 '24 19:08 github-actions[bot]

I have read the CLA Document and I sign the CLA

jacobdbrown4 avatar Aug 05 '24 19:08 jacobdbrown4

recheck

jacobdbrown4 avatar Aug 05 '24 19:08 jacobdbrown4

@jacobdbrown4 thank you for your comment! To ensure we address your issue effectively, could you please verify that you are using the latest versions of YOLOv5 and all related dependencies? This helps us confirm whether the problem persists with the most recent updates.

If the issue is still reproducible, please provide additional details such as error messages, steps to reproduce, and any relevant code snippets. This information will help us diagnose and resolve the issue more efficiently.

Looking forward to your response! 😊

glenn-jocher avatar Aug 05 '24 22:08 glenn-jocher

This pull request needs to be merged, inference times are slower due to this error constantly popping up with the newest versions of pytorch.

ijnrghjkdsmigywneig203 avatar Sep 13 '24 02:09 ijnrghjkdsmigywneig203

@glenn-jocher

ijnrghjkdsmigywneig203 avatar Sep 13 '24 02:09 ijnrghjkdsmigywneig203

Thank you for your input. Please ensure you're using the latest YOLOv5 version to see if the issue persists. If the problem continues, provide additional details so we can assist further.

glenn-jocher avatar Sep 13 '24 06:09 glenn-jocher

Reproducible with this commit 907bef2f63771a352346d0b4f068946d7f961f0c Enough to run python3 train.py and it will spam this warning on every iteration

mezotaken avatar Oct 02 '24 15:10 mezotaken

Please ensure you're using the latest YOLOv5 version, as updates may resolve this issue. If it persists, let us know with more details.

pderrenger avatar Oct 02 '24 19:10 pderrenger

Are you guys just bots designed to repeat the same thing when a real issue is present within the code? The latest version of yolov5 is literally fetched every single time I initialize my script. The issue is with your code being outdated.

ijnrghjkdsmigywneig203 avatar Oct 13 '24 20:10 ijnrghjkdsmigywneig203

@ijnrghjkdsmigywneig203 thank you for your feedback. We recommend ensuring all dependencies are up-to-date. If the issue persists, please provide more details so we can investigate further.

pderrenger avatar Oct 14 '24 01:10 pderrenger

Everything is up to date and the error for your outdated code still occurs. What can I do to solve it?

torch.cuda.amp is deprecated as of Pytorch 2.4. This PR updates use to torch.amp. This gets rid of the

FutureWarning: torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cuda', args...) instead. with torch.cuda.amp.autocast(amp):

ijnrghjkdsmigywneig203 avatar Oct 14 '24 06:10 ijnrghjkdsmigywneig203

Thank you for bringing this to our attention. Please check if there's an open pull request addressing this update. If not, consider submitting one to help resolve the issue.

pderrenger avatar Oct 14 '24 09:10 pderrenger

There is an open pull request regarding this issue that will solve it. It is this one. Please merge this PR.

beltoforion avatar Oct 23 '24 09:10 beltoforion

Thank you for pointing this out. Please follow the pull request for updates, as it will be reviewed and merged if it meets the requirements.

pderrenger avatar Oct 23 '24 18:10 pderrenger

@glenn-jocher

ijnrghjkdsmigywneig203 avatar Oct 31 '24 16:10 ijnrghjkdsmigywneig203

will this be merged anytime soon?

sakgoyal avatar Nov 17 '24 00:11 sakgoyal

Thank you for following up. The PR appears to address the deprecation warning for torch.cuda.amp in PyTorch 2.4. I'll let the maintainers review and make a decision on merging. In the meantime, you can track the PR status for updates.

pderrenger avatar Nov 17 '24 13:11 pderrenger

Why isn't the update merged as of yet? Is something blocking it making it impossible? Because I still get the same warning on every update.

SamDaaLamb avatar Jan 24 '25 03:01 SamDaaLamb

The PR addressing this issue is likely under review by the maintainers. You can monitor its progress directly on the pull request page. Merging depends on thorough testing and alignment with the repository's standards. Thank you for your patience!

pderrenger avatar Jan 25 '25 06:01 pderrenger

Is there any more news on this?

essair avatar Feb 03 '25 10:02 essair

We appreciate your patience. PRs undergo thorough review and testing to ensure compatibility across all supported environments. For updates on this specific PR, please monitor its status directly on GitHub. Thank you for helping improve YOLOv5! πŸš€

pderrenger avatar Feb 03 '25 23:02 pderrenger

Code changes made by this PR are minimal, so I hope a review should not take long.

In the meantime, YOLOv5 training output printed to the terminal is cluttered with the torch warning being printed repeatedly. This makes monitoring training progress difficult. It would be great if we could get this merged.

jacobdbrown4 avatar Feb 04 '25 00:02 jacobdbrown4

Thank you for your PR and patience. Our team reviews all contributions thoroughly to ensure compatibility across environments and use cases. We'll prioritize testing this PyTorch 2.4 AMP update and merge it once verified. You can track progress directly on the PR page. We appreciate your help keeping YOLOv5 up-to-date! πŸš€

pderrenger avatar Feb 04 '25 17:02 pderrenger

πŸ‘‹ Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap.

We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved.

For additional resources and information, please see the links below:

  • Docs: https://docs.ultralytics.com
  • HUB: https://hub.ultralytics.com
  • Community: https://community.ultralytics.com

Thank you for your contributions to YOLO πŸš€ and Vision AI ⭐

github-actions[bot] avatar Oct 29 '25 00:10 github-actions[bot]

Still no progress for this trivial PR???

blackliner avatar Nov 03 '25 21:11 blackliner

Thanks for the nudgeβ€”this PR is waiting on a small compatibility shim so YOLOv5 still runs on older PyTorch; once that’s in and CI passes we’ll merge. If you need an immediate workaround, update your local AMP calls to torch.amp with a torch.cuda.amp fallback; see the Mixed Precision overview for context in the Ultralytics Docs. See the Mixed Precision overview for context in the Ultralytics Docs.

pderrenger avatar Nov 04 '25 11:11 pderrenger