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

Upgrade TensorRT to 8.5.3 #7006

Merged
merged 16 commits into from Jul 6, 2023
Merged

Conversation

NateMeyer
Copy link
Contributor

This pull request updates the TensorRT libraries to 8.5.3 in order to support the latest GPUs from Nvidia. Should address Issue #6666

This update also is able to do the model conversion from within the frigate image, which allows us to integrate it into the startup scripts.

Tasks:

  • Update Libraries
  • Update scripts to convert models locally
  • Setup scripts to convert models automatically
  • Update documentation
  • Testing

@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for frigate-docs canceled.

Name Link
🔨 Latest commit 3b21f86
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/64a6425907f0ef00097e39cf

@NateMeyer NateMeyer mentioned this pull request Jul 3, 2023
5 tasks
@NateMeyer
Copy link
Contributor Author

I have a test image pushed if anyone wants to help verify this works on new (4000 series) and old (900 series) GPUs. This change also streamlines the model generation process, and no pre-conversion steps are necessary, just add the model you want to use as an environment variable in your docker-compose.yml.

Using image ghcr.io/natemeyer/frigate:trt-8.5-7761a1a-tensorrt, add the following to your docker-compose file:

services:
  frigate:
    image: ghcr.io/natemeyer/frigate:trt-8.5-7761a1a-tensorrt
    environment:
      - USE_FP16=false
      - YOLO_MODELS=yolov7-tiny-416

The trt-models folder no longer needs to be mapped as a volume into the container. The model in the YOLO_MODELS variable will be downloaded, converted, and saved into the path /config/model_cache/tensorrt when the container starts up.

You will also need to add this new path into the config.yml to point to the converted model.

model:
  path: /config/model_cache/tensorrt/yolov7-tiny-416.trt

Note: I had issues using the latest driver on my 1080ti, the system would crash when running object detection. I rolled back to the 531.68 driver and it is working fine. Not sure if this issue extends to any other cards or setups, or if I'm the lucky one.

@doctorttt
Copy link

doctorttt commented Jul 4, 2023

Hi Nate. I followed your instructions above and ghcr.io/natemeyer/frigate:trt-8.5-7761a1a-tensorrt works on my 4060ti with yolov7-tiny-416. The whole installation process was smooth and flawless; also no errors in log. Please see the screenshots pasted here for your reference. By the way, are the other yolo7 models available for testing: yolov7x-320, yolov7x-640, yolov7-640, yolov7-320. Also, are yolo8 models available for testing? Thanks

image

image

image

detectors:
  tensorrt:
    type: tensorrt
    device: 0 

model:
  path: /config/model_cache/tensorrt/yolov7-tiny-416.trt 
  input_tensor: nchw
  input_pixel_format: rgb
  width: 416
  height: 416

@NateMeyer
Copy link
Contributor Author

Yes, all the same models should be available as before. Just set them in the YOLO_MODELS variable and point to the model in the config file. You can use a comma-separated list to convert multiple models just like the previous process. The yolo example repo from yeahme49 didn't include any yolov8 models to my knowledge.

@doctorttt
Copy link

doctorttt commented Jul 4, 2023

Yes, all the same models should be available as before. Just set them in the YOLO_MODELS variable and point to the model in the config file. You can use a comma-separated list to convert multiple models just like the previous process. The yolo example repo from yeahme49 didn't include any yolov8 models to my knowledge.

I tried the other yolo7 models yolov7x-320, yolov7x-640, yolov7-640, yolov7-320 but couldn't get them to work. I'm stuck with unable to start service trt-model-prepare error message. Please advise. Thanks Nate

image

@NateMeyer
Copy link
Contributor Author

@doctorttt Thanks for the heads up. I think the conversion script was too verbose, so I redirected the stdout to /dev/null. Give it a try with the latest update. Pushing a new image, ghcr.io/natemeyer/frigate:trt-8.5-3b21f86-tensorrt. If you see this issue again, I'll need more of the log to see what it's complaining about.

@doctorttt
Copy link

doctorttt commented Jul 6, 2023

ghcr.io/natemeyer/frigate:trt-8.5-3b21f86-tensorrt

@NateMeyer ghcr.io/natemeyer/frigate:trt-8.5-3b21f86-tensorrt works! I was able to get yolov7x-320, yolov7x-640, yolov7-640, yolov7-320 to work on my 4060ti. The conversion for each went smoothly and no complaints in frigate.

image

@NateMeyer
Copy link
Contributor Author

@doctorttt One last note, you should be able to set the USE_FP16 flag to true. I believe that is primarily for older generation cards that don't have FP16 support like Pascal and Maxwell. If you change that and want to regenerate the models, just clear out that model_cache folder.

@blakeblackshear blakeblackshear merged commit dd02958 into blakeblackshear:dev Jul 6, 2023
11 checks passed
@doctorttt
Copy link

@doctorttt One last note, you should be able to set the USE_FP16 flag to true. I believe that is primarily for older generation cards that don't have FP16 support like Pascal and Maxwell. If you change that and want to regenerate the models, just clear out that model_cache folder.

@NateMeyer Thanks - I flipped USE_FP16 to true and regenerated all yolo7 models - no issue. :)

madsciencetist added a commit to madsciencetist/frigate that referenced this pull request Jul 7, 2023
Latest rebase on dev brought in blakeblackshear#7006, which replaced the model
generation image with a trt-model-prepare service in the regular
frigate-tensorrt image. Follow the same paradigm for Jetsons.
madsciencetist added a commit to madsciencetist/frigate that referenced this pull request Jul 7, 2023
Latest rebase on dev brought in blakeblackshear#7006, which replaced the model
generation image with a trt-model-prepare service in the regular
frigate-tensorrt image. Follow the same paradigm for Jetsons.
@trixor
Copy link

trixor commented Jul 12, 2023

Can confirm this works on a NVIDIA GeForce RTX 2060. One thing that isn't clear, if I want to provide a custom or fine tuned YOLO model, would I be able to provide it somehow through the external env as PT or ONNX. and get Frigate on startup to do the conversion or does this need to happen manually outside of the container and do we need to store the model and map it like this without an env variable like this:

model:
  path: /config/model_cache/tensorrt/yolov7-tiny-custom-generated.trt

Thanks again for the hard work!

@madsciencetist
Copy link
Contributor

@trixor you'll need to do the conversion yourself and supply the .trt file. However, it would be straightforward to upgrade docker/support/tensorrt_detector/rootfs/etc/s6-overlay/s6-rc.d/trt-model-prepare/run to be able to ingest a user-provided YOLO model.

@trixor
Copy link

trixor commented Jul 12, 2023

@madsciencetist thanks! Great, that's how I understood it after reading the code but wanted to verify. I'll see if I can get that to work and submit a PR if able.

madsciencetist added a commit to madsciencetist/frigate that referenced this pull request Jul 13, 2023
Latest rebase on dev brought in blakeblackshear#7006, which replaced the model
generation image with a trt-model-prepare service in the regular
frigate-tensorrt image. Follow the same paradigm for Jetsons.
madsciencetist added a commit to madsciencetist/frigate that referenced this pull request Jul 21, 2023
Latest rebase on dev brought in blakeblackshear#7006, which replaced the model
generation image with a trt-model-prepare service in the regular
frigate-tensorrt image. Follow the same paradigm for Jetsons.
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.

None yet

6 participants