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

Export TensorRT engine - Device memory is insufficient to use tactic. - NX2 TX Jetson Platform. #12637

Closed
1 of 2 tasks
nicorl opened this issue Jan 16, 2024 · 5 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working Stale

Comments

@nicorl
Copy link

nicorl commented Jan 16, 2024

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

No response

Bug

I have trained a PyTorch model (.pb) and I am looking to optimize it to consume less memory. The attempts to export it to TensorRT are causing issues because the device has limited available memory, and I'm unsure how to achieve a proper export.

Trained through:

python train.py --data data/config_training.yaml --weights yolov5s.pt --img 640 --epochs 300 --device 0 --batch -1 --patience 15

Loading model on memory:
Virtual environment with: Python 3.6.9, torch-1.8.0
→ The pytorch model (best.pt) requires approximately ~1.2GB of memory
→ The model's performance is good ✓ (best.pt)

Exporting to TensorRT over Jetson TX2 NX with Python 3.6.9, torch-1.8.0, TensorRT 8.0.1.6, ONNX 1.11.0
Export command:

yolov5 export --weights best.pt --include [engine] --device 0 --imgsz [800,608] --data mydata.yaml --half --workspace 1

Errors & warning:

WARNING: ⚠️ Python 3.7.0 is required by YOLOv5, but Python 3.6.9 is currently installed
[TensorRT] ERROR: Tactic Device request: 277MB Available: 264MB. Device memory is insufficient to use tactic.
[TensorRT] WARNING: Skipping tactic 3 due to oom error on requested size of 277 detected for tactic 5.
[TensorRT] ERROR: Tactic Device request: 356MB Available: 267MB. Device memory is insufficient to use tactic.
[TensorRT] WARNING: Skipping tactic 3 due to oom error on requested size of 356 detected for tactic 4.

Full log here

The model.engine file is generated, but when i load it, the performance is not good:
badResults

On my PC with a larger amount of memory and Python v.3.10, the export process does not yield any warnings and works well. Because I can’t increase the memory of my TX2 NX, I would like to understand how relevant the warnings are and what would be the best way to avoid them. I believe upgrading to Python 3.7 is one option, but I would like to know if there are possibilities to make it works on 3.6.9
goodResults

I've also put a link in the Nvidia forums, but I think it's more appropriate here than there.

Environment

TensorRT Version: 8.0.1.6
GPU Type: NVIDIA® Jetson™ TX2 NX - 4 Core ARM A57 Complex and 2 core NVIDIA Denver2 64-bit CPU - 4GB LPDDR4 - NVIDIA Tegra X2, 3832MiB
Nvidia Driver Version: nvidia-smi not installed
CUDA Version: cuda_10.2_r440.TC440_70.29663091_0
Operating System + Version: Linux aaeon-desktop 4.9.253-tegra SMP PREEMPT Mon Jul 26 12:19:28 PDT 2021 aarch64 GNU/Linux
Python Version: 3.6.9
PyTorch Version: 1.8.0
ONNX Version: 1.11.0
yolov5 Version: 6.2.1

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@nicorl nicorl added the bug Something isn't working label Jan 16, 2024
Copy link
Contributor

👋 Hello @nicorl, 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 a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. 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

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@nicorl hello! Thanks for the detailed issue report. It seems like you're encountering out-of-memory (OOM) errors when exporting your model to TensorRT on the Jetson TX2 NX platform. Here are a few suggestions that might help:

  1. Reduce Workspace Size: Try reducing the workspace size during export. Although you've set it to 1GB, you might need to go lower due to the limited memory on the TX2 NX.

  2. Optimize Model: If possible, optimize your model further before export. This could involve pruning or quantization to reduce the model size and memory requirements.

  3. Python Version: While upgrading to Python 3.7 might not directly solve the OOM issue, it's recommended to use the Python version that YOLOv5 is tested on for best compatibility.

  4. Batch Size: If you're using a batch size greater than 1 during inference, try reducing it to 1 to save memory.

  5. Close Other Processes: Ensure that no other memory-intensive processes are running on the device when exporting the model.

  6. TensorRT Version: Check if there's a more memory-efficient version of TensorRT available for your platform.

  7. Model Precision: You're using the --half flag which uses FP16 precision. Make sure that your device supports FP16 operations efficiently.

If these suggestions don't resolve the issue, consider posting the full error log and your export command in the issue for further assistance. Remember to check the Ultralytics Docs for more information on exporting models and troubleshooting.

Keep in mind that the Jetson TX2 NX has limited memory, and some models may simply be too large to run efficiently on this platform. You might need to consider a more powerful device if memory constraints continue to be an issue.

Thanks for contributing to the YOLOv5 community, and we appreciate your efforts in making the model work on edge devices! 🚀

@nicorl
Copy link
Author

nicorl commented Jan 26, 2024

Hi again,
I've just tried to install all from the source

  • Python 3.7.12
  • Torch 1.8.0
  • Torchvision 0.9.0
  • CMake 3.21.4
  • TensorRT 8.2

But ultimately, generating the TensorRT 8.2 wheel has posed issues for which I cannot find any solution. Below, I provide all the executed commands as information for anyone reading this message. It's worth noting that the next steps will involve trying to use Python version 3.8 and the rest of the software in appropriate versions. As I make significant progress, I will leave further comments.

Nvidia forum link where someone is helping to solve this

@nicorl nicorl closed this as completed Jan 26, 2024
@nicorl nicorl reopened this Jan 26, 2024
@glenn-jocher
Copy link
Member

Hello again @nicorl,

It sounds like you're making progress, but still encountering some challenges with the TensorRT wheel installation. Here are a few general tips that might help:

  1. Dependencies: Ensure all dependencies are correctly installed and compatible with each other. Dependency conflicts can often lead to installation issues.

  2. Installation Logs: Review the installation logs carefully for any specific error messages that could point to the root cause of the issue.

  3. Virtual Environment: Consider using a virtual environment to avoid conflicts with system-wide packages and to have a clean slate for installation.

  4. Community and Forums: Continue to engage with the community on the Nvidia forums, as platform-specific issues can often be resolved with the help of users who have faced similar challenges.

  5. Documentation: Refer to the official TensorRT documentation for guidance on building from source and troubleshooting installation issues.

  6. Alternative Approaches: If building from source continues to be problematic, consider looking for pre-built wheels that are compatible with your system, if available.

  7. System Resources: Ensure your system has enough resources (e.g., memory, disk space) to complete the build process, as this can sometimes cause unexpected failures.

Remember to take it one step at a time and isolate each issue as you encounter it. Building complex software from source can be challenging, but with persistence, you'll likely find a solution. Keep up the good work, and thank you for keeping the community updated on your progress! 🛠️

Best of luck with the next steps, and we're looking forward to hearing about your successful export with the updated Python version and software stack.

Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

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 YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Feb 26, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants