Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @torch.no_grad() decorator #3312

Merged
merged 2 commits into from
May 24, 2021
Merged

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented May 24, 2021

Replace with torch.no_grad(): statement with @torch.no_grad() decorator.

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Enhancement of the inference and testing code in the YOLOv5 project for better readability and performance.

πŸ“Š Key Changes

  • Applied the @torch.no_grad() decorator to the detect() and test() functions in detect.py and test.py.
  • Removed nested with torch.no_grad(): blocks inside these functions.
  • Simplified conditional logic in detect.py for updating models.

🎯 Purpose & Impact

  • πŸš€ Increases efficiency: Disabling gradient computations globally with the @torch.no_grad() decorator to avoid redundancy.
  • πŸ“– Improves code readability: By removing nested with torch.no_grad():, the code structure is simplified making it easier to read and understand.
  • πŸ› οΈ Enhances maintainability: Simplified conditionals reduce complexity, making it easier to maintain and update the code.
  • 🌍 User experience: These changes aim to streamline the inference and test processes, potentially improving execution time and lowering resource consumption, which benefits all users.

@glenn-jocher glenn-jocher changed the title @torch.no_grad() decorator Implement @torch.no_grad() decorator May 24, 2021
@glenn-jocher glenn-jocher merged commit 61ea23c into master May 24, 2021
@glenn-jocher glenn-jocher deleted the glenn-jocher-patch-1 branch May 24, 2021 11:23
Lechtr pushed a commit to Lechtr/yolov5 that referenced this pull request Jul 20, 2021
* `@torch.no_grad()` decorator

* Update detect.py

(cherry picked from commit 61ea23c)
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* `@torch.no_grad()` decorator

* Update detect.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant