-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
fix tensor mismatch error in multithread inference #9425
fix tensor mismatch error in multithread inference #9425
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Hello @CanKorkut, thank you for submitting a YOLOv5 π PR! To allow your work to be integrated as seamlessly as possible, we advise you to:
- β
Verify your PR is up-to-date with
ultralytics/yolov5
master
branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by runninggit pull
andgit merge master
locally. - β Verify all YOLOv5 Continuous Integration (CI) checks are passing.
- β Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." β Bruce Lee
@CanKorkut thanks for the PR! Grid construction is a resource intensive task that should only occur if required, i.e. if an image with a new size is passed for inference. Your code would reconstruct a new grid for every image, which is not desire-able from a FLOPs/speed/export perspective. |
@CanKorkut are there solutions that only reconstruct the grid when needed, i.e. when it's the wrong shape? |
@glenn-jocher I'm working on that. What do you think about using parameter like "multithread_safe"? Reconstruct grid only when its true. |
@CanKorkut well we already have an attribute that forces grid reconstruction called Lines 64 to 66 in f038ad7
|
@CanKorkut is it the Lines 50 to 51 in f038ad7
EDIT: or maybe its the way they are initialized? Maybe we should initialize them with a for loop instead of a multiplication? |
@CanKorkut maybe we should use nn.ParameterList: https://pytorch.org/docs/1.10.0/generated/torch.nn.ParameterList.html#torch.nn.ParameterList EDIT: Opened PR #9492 with proposed solution. Can you try it out and see if it resolves your issue? |
May resolve threaded inference issue in #9425 (comment) Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@glenn-jocher Yeah, I think nn.ParameterList looks like good idea. I will try it for the issue. |
May resolve threaded inference issue in #9425 (comment) by avoiding memory sharing on init. Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@CanKorkut opened up a second PR #9494 which might have a simpler solution. ParameterList turns out to be complicated, initializes with requires_grad=True by default and modifying the parameter list is unsupported in torch 1.7 Can you test #9494? |
May resolve threaded inference issue in #9425 (comment) by avoiding memory sharing on init. Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@CanKorkut any updates on this? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions YOLOv5 π and Vision AI β. |
π 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:
Thank you for your contributions to YOLO π and Vision AI β |
May resolve threaded inference issue in ultralytics/yolov5#9425 (comment) Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Refactored grid and anchor grid initialization during YOLO model inference.
π Key Changes
self.grid
andself.anchor_grid
with local variablesgrid
andanchor_grid
.grid
andanchor_grid
are recalculated each time during inference, avoiding the use of potentially outdated attributes.π― Purpose & Impact