Skip to content

Commit 5d20f47

Browse files
authored
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
1 parent ccf8a46 commit 5d20f47

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

docker-build/env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ volumename=${VOLUMENAME:-${project_name}_data}
55
arch=${ARCH:-x86_64}
66
platform=${PLATFORM:-Linux/${arch}}
77
invokeai_tag=${INVOKEAI_TAG:-${project_name}:${arch}}
8+
gpus=${GPU_FLAGS:+--gpus=${GPU_FLAGS}}
89

910
export project_name
1011
export volumename
1112
export arch
1213
export platform
1314
export invokeai_tag
15+
export gpus

docker-build/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ docker run \
1717
--mount="source=$volumename,target=/data" \
1818
--publish=9090:9090 \
1919
--cap-add=sys_nice \
20+
$gpus \
2021
"$invokeai_tag" ${1:+$@}

docs/installation/INSTALL_DOCKER.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ also do so.
127127

128128
---
129129

130+
## Running the container on your GPU
131+
132+
If you have an Nvidia GPU, you can enable InvokeAI to run on the GPU by running the container with an extra
133+
environment variable to enable GPU usage and have the process run much faster:
134+
135+
```bash
136+
GPU_FLAGS=all ./docker-build/run.sh
137+
```
138+
139+
This passes the `--gpus all` to docker and uses the GPU.
140+
141+
If you don't have a GPU (or your host is not yet setup to use it) you will see a message like this:
142+
143+
`docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].`
144+
145+
You can use the full set of GPU combinations documented here:
146+
147+
https://docs.docker.com/config/containers/resource_constraints/#gpu
148+
149+
For example, use `GPU_FLAGS=device=GPU-3a23c669-1f69-c64e-cf85-44e9b07e7a2a` to choose a specific device identified by a UUID.
150+
130151
## Running InvokeAI in the cloud with Docker
131152

132153
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).

0 commit comments

Comments
 (0)