Permit usage of GPUs in docker script (#1985)

* Add gpu support to docker

Enable GPUs within docker

* Use gpus flag

* Add GPU information to readme

* Fix env var name for GPU
This commit is contained in:
Chris Dawson 2022-12-14 00:21:33 -05:00 committed by GitHub
parent ccf8a46320
commit 5d20f47993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -5,9 +5,11 @@ volumename=${VOLUMENAME:-${project_name}_data}
arch=${ARCH:-x86_64}
platform=${PLATFORM:-Linux/${arch}}
invokeai_tag=${INVOKEAI_TAG:-${project_name}:${arch}}
gpus=${GPU_FLAGS:+--gpus=${GPU_FLAGS}}
export project_name
export volumename
export arch
export platform
export invokeai_tag
export gpus

View File

@ -17,4 +17,5 @@ docker run \
--mount="source=$volumename,target=/data" \
--publish=9090:9090 \
--cap-add=sys_nice \
$gpus \
"$invokeai_tag" ${1:+$@}

View File

@ -127,6 +127,27 @@ also do so.
---
## Running the container on your GPU
If you have an Nvidia GPU, you can enable InvokeAI to run on the GPU by running the container with an extra
environment variable to enable GPU usage and have the process run much faster:
```bash
GPU_FLAGS=all ./docker-build/run.sh
```
This passes the `--gpus all` to docker and uses the GPU.
If you don't have a GPU (or your host is not yet setup to use it) you will see a message like this:
`docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].`
You can use the full set of GPU combinations documented here:
https://docs.docker.com/config/containers/resource_constraints/#gpu
For example, use `GPU_FLAGS=device=GPU-3a23c669-1f69-c64e-cf85-44e9b07e7a2a` to choose a specific device identified by a UUID.
## Running InvokeAI in the cloud with Docker
We offer an optimized Ubuntu-based image that has been well-tested in cloud deployments. Note: it also works well locally on Linux x86_64 systems with an Nvidia GPU. It *may* also work on Windows under WSL2 and on Intel Mac (not tested).