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] upgrade opencv in stable diffusion demo #22470

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ docker run --rm -it --gpus all -v $PWD:/workspace nvcr.io/nvidia/pytorch:24.04-p
```

#### Build onnxruntime from source
The cuDNN in the container might not be compatible with official onnxruntime-gpu package, it is recommended to build from source instead.
This step is optional. Please look at [install onnxruntime-gpu](https://onnxruntime.ai/docs/install/#python-installs) if you do not want to build from source.

After launching the docker, you can build and install onnxruntime-gpu wheel like the following.
```
export CUDACXX=/usr/local/cuda/bin/nvcc
git config --global --add safe.directory '*'
Expand All @@ -60,6 +59,14 @@ If the GPU is not A100, change `CMAKE_CUDA_ARCHITECTURES=80` in the command line
If your machine has less than 64GB memory, replace `--parallel` by `--parallel 4 --nvcc_threads 1 ` to avoid out of memory.

#### Install required packages
First, remove older version of opencv to avoid error like `module 'cv2.dnn' has no attribute 'DictValue'`:
```
pip uninstall -y $(pip list --format=freeze | grep opencv)
rm -rf /usr/local/lib/python3.10/dist-packages/cv2/
apt-get update
DEBIAN_FRONTEND="noninteractive" apt-get install --yes python3-opencv
```

```
cd /workspace/onnxruntime/python/tools/transformers/models/stable_diffusion
python3 -m pip install -r requirements-cuda12.txt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements.txt

tianleiwu marked this conversation as resolved.
Show resolved Hide resolved
# Official onnxruntime-gpu 1.16.1 is built with CUDA 11.8.
onnxruntime-gpu>=1.16.2
# See https://onnxruntime.ai/docs/install/#python-installs for installation. The latest one in pypi is for cuda 12.
# onnxruntime-gpu>=1.16.2

py3nvml

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-r requirements.txt

# For CUDA 12.*, you will need build onnxruntime-gpu from source and install the wheel. See README.md for detail.
# onnxruntime-gpu>=1.16.2
onnxruntime-gpu>=1.19.2

py3nvml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ controlnet_aux==0.0.9
optimum==1.20.0
safetensors
invisible_watermark
# newer version of opencv-python migth encounter module 'cv2.dnn' has no attribute 'DictValue' error
opencv-python==4.8.0.74
opencv-python-headless==4.8.0.74
opencv-python-headless
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ stages:
nvcr.io/nvidia/pytorch:22.11-py3 \
bash -c ' \
set -ex; \
pip uninstall -y $(pip list --format=freeze | grep opencv); \
rm -rf /usr/local/lib/python3.8/dist-packages/cv2/; \
apt-get update; \
DEBIAN_FRONTEND="noninteractive" apt-get install --yes python3-opencv; \
python3 --version; \
python3 -m pip install --upgrade pip; \
python3 -m pip install /Release/*.whl; \
Expand Down
Loading