-
-
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
Detect(inplace=True) multithreaded detection RuntimeError #8565
Comments
👋 Hello @mynameischaos, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution. If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you. If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available. For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com. RequirementsPython>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started: git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
@mynameischaos yes multiple models require inplace=False |
@mynameischaos I'm thinking it may make sense to make inplace=False the default. There are speed improvements in the head with inplace=True but several users have raised multithreading issues so it may be worthwhile to improve the compatibility at the expense of a bit of speed. I think the speed improvement is very slight, but I'll add a TODO to quantify this to determine the best course of action here. |
@mynameischaos good news 😃! Your original issue may now be fixed ✅ in PR #8801. This PR sets To receive this update:
Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀! |
Hi @glenn-jocher ! im still getting Runtime Error with multithread, even setting inplace=False manually. |
@fernandoTB 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. We've created a few short guidelines below to help users provide what we need in order to start investigating a possible problem. How to create a Minimal, Reproducible ExampleWhen asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
For Ultralytics to provide assistance your code should also be:
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem. Thank you! 😃 |
@glenn-jocher I was facing problems when serving Yolov5 with torch hub + FastAPI, I believe is the same problem reported @mynameischaos. When the client sends multiple requests, FastAPI handles it with multithread. Randomly some inferences crash raising runtime error on self.grid multiplication. I tried to force reload to the newest version with inplace=False, but the error just change to another line, where multiplies self.anchor_grid[i]. Apparently, I just solved my problem using threading mutex, allowing only one thread to perform inference at a time. |
@fernandoTB got it, thanks! Is there any way to reproduce this with torch hub? i.e. maybe loading two models and dispatching inference in daemon threads? If I could reproduce it it would help debug it. |
Can you describe in detail how you handled it??I need your help. Thankyou. |
@boreas-l It's great to hear that you were able to find a workaround by using threading mutex to control the inference thread execution. This approach ensures that only one thread performs the inference at a time, resolving the issue of crashes during concurrent inference. If other users encounter similar problems with concurrent inference in FastAPI, your solution could be helpful to them as well. Thank you for sharing your experience! |
Search before asking
Question
torch version: 1.9.1
I use this scripts load model:
self.model = torch.hub.load('ultralytics/yolov5', 'custom', path=self.model_path)
then, run model(image) with single thread is ok.
then, run model(image) with multithread, but report this error:
File models/yolo.py", line 67, in forward
y[..., 0:2] = (y[..., 0:2] * 2 + self.grid[i]) * self.stride[i] # xy
RuntimeError: The size of tensor a (48) must match the size of tensor b (60) at non-singleton dimension 3
I follow the similar issues by set self.inplace = False, but it does not work.
Please help me.
Additional
No response
The text was updated successfully, but these errors were encountered: