Skip to content

Conversation

glenn-jocher
Copy link
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
@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 <[email protected]>
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