Skip to content

torch.empty() for speed improvements#9025

Merged
glenn-jocher merged 2 commits intomasterfrom
update/empty
Aug 18, 2022
Merged

torch.empty() for speed improvements#9025
glenn-jocher merged 2 commits intomasterfrom
update/empty

Conversation

@glenn-jocher
Copy link
Copy Markdown
Member

@glenn-jocher glenn-jocher commented Aug 18, 2022

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Optimization of tensor initialization in YOLOv5 by using torch.empty instead of torch.zeros.

📊 Key Changes

  • Replaced torch.zeros with torch.empty for initializing tensors in various files including models/common.py, models/yolo.py, utils/autobatch.py, utils/loggers/__init__.py, and utils/torch_utils.py.
  • This change affects the model warmup process, forward pass, autobatch functionality, TensorBoard logging, and model information functions.

🎯 Purpose & Impact

  • 🚀 Purpose: To optimize memory allocation during tensor initialization. torch.empty allocates memory without initializing it, which can be slightly faster than initializing to zero with torch.zeros.
  • Potential Impact: May result in a minor performance improvement during model initialization and inference, as less time is spent on initializing tensors.
  • 👩‍💻 Users: Could benefit from reduced latency in model operations, especially when repeatedly initializing large numbers of tensors.

@glenn-jocher glenn-jocher self-assigned this Aug 18, 2022
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@glenn-jocher glenn-jocher merged commit 61adf01 into master Aug 18, 2022
@glenn-jocher glenn-jocher deleted the update/empty branch August 18, 2022 18:12
glenn-jocher added a commit that referenced this pull request Aug 21, 2022
ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
`torch.empty()` for speed improvement

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
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