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

Cuda illegal memory access when running inference on *.engine #6311

Closed
1 task done
Lick opened this issue Jan 16, 2022 · 4 comments · Fixed by #7560
Closed
1 task done

Cuda illegal memory access when running inference on *.engine #6311

Lick opened this issue Jan 16, 2022 · 4 comments · Fixed by #7560
Labels
duplicate This issue or pull request already exists question Further information is requested Stale

Comments

@Lick
Copy link

Lick commented Jan 16, 2022

Search before asking

Question

When performing inference with *.engine I receive this error

Loading model.engine for TensorRT inference...
[01/16/2022-04:18:26] [TRT] [I] [MemUsageChange] Init CUDA: CPU +426, GPU +0, now: CPU 520, GPU 3258 (MiB)
[01/16/2022-04:18:26] [TRT] [I] Loaded engine size: 28 MiB
[01/16/2022-04:18:26] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.3 but loaded cuBLAS/cuBLAS LT 11.3.0
[01/16/2022-04:18:26] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +634, GPU +266, now: CPU 1193, GPU 3552 (MiB)
[01/16/2022-04:18:27] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +126, GPU +58, now: CPU 1319, GPU 3610 (MiB)
[01/16/2022-04:18:27] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in engine deserialization: CPU +0, GPU +26, now: CPU 0, GPU 26 (MiB)
[01/16/2022-04:18:31] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.3 but loaded cuBLAS/cuBLAS LT 11.3.0
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +1, GPU +10, now: CPU 5022, GPU 5368 (MiB)
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 5022, GPU 5376 (MiB)
[01/16/2022-04:18:31] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +0, GPU +36, now: CPU 0, GPU 62 (MiB)
Adding AutoShape...
[01/16/2022-04:18:32] [TRT] [E] 1: [convolutionRunner.cpp::executeConv::511] Error Code 1: Cudnn (CUDNN_STATUS_EXECUTION_FAILED)
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 539, in forward
t.append(time_sync())
File "/root/.cache/torch/hub/ultralytics_yolov5_master/utils/torch_utils.py", line 91, in time_sync
torch.cuda.synchronize()
File "/usr/local/lib/python3.8/dist-packages/torch/cuda/init.py", line 493, in synchronize
return torch._C._cuda_synchronize()
RuntimeError: CUDA error: an illegal memory access was encountered
[01/16/2022-04:18:32] [TRT] [E] 1: [defaultAllocator.cpp::deallocate::35] Error Code 1: Cuda Runtime (an illegal memory access was encountered)

Code:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

torch.backends.cudnn.benchmark = True
torch.backends.cudnn.enabled= False
model = torch.hub.load('ultralytics/yolov5', 'custom', 'model.engine', force_reload=True)
model.to(device)
model.half()

image = open("find.png", 'rb').read()
original_image = cv2.imdecode(np.frombuffer(image, np.uint8), cv2.IMREAD_COLOR)
resized_image = cv2.resize(original_image, (320, 320))
with torch.inference_mode():
    results = model(resized_image, size=320)

Additional

Name: torch
Version: 1.10.1+cu113

Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0

@Lick Lick added the question Further information is requested label Jan 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2022

👋 Hello @Lick, 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 Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.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

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If 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.

@glenn-jocher
Copy link
Member

@Lick thanks for the bug report! Yes we reproduced this recently and have an open issue on it in #6260. It's confusing because the *.engine exports work correctly with detect.py, but encounter this error with PyTorch Hub. If you have any insights into the problem please let us know.

@glenn-jocher glenn-jocher added the duplicate This issue or pull request already exists label Jan 16, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

@glenn-jocher
Copy link
Member

@Lick good news 😃! Your original issue may now be fixed ✅ in PR #7560 implementing a TRT PyTorch Hub inference fix by @youngjae-avikus.

Screen Shot 2022-04-24 at 12 44 49 PM

To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

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 🚀!

@glenn-jocher glenn-jocher linked a pull request Apr 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested Stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants