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

Fixed, improved, and unified Docker environment #5474

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ wandb
/docker-compose.yaml
/docker-compose.yml
/Dockerfile
.dockerignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want to ignore a .dockerignore?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... what is with ignoring these other Docker files prior to this PR? 🤔

.env
10 changes: 6 additions & 4 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ HOST_API_PORT=5000
CONTAINER_API_PORT=5000
# Comma separated extensions to build
BUILD_EXTENSIONS=""
# Set APP_RUNTIME_GID to an appropriate host system group to enable access to mounted volumes
# You can find your current host user group id with the command `id -g`
# Set APP_RUNTIME_UID/APP_RUNTIME_GID to an appropriate host user/group to enable access to mounted volumes
# You can find your current host user/group id with the command `id -u; id -g`
APP_RUNTIME_UID=6972
APP_RUNTIME_GID=6972
# override default app build permissions (handy for deploying to cloud)
#APP_GID=6972
#APP_UID=6972
# Set cache env
TRANSFORMERS_CACHE=/home/app/text-generation-webui/cache/
HF_HOME=/home/app/text-generation-webui/cache/
TRANSFORMERS_CACHE=/home/app/text-generation-webui/cache
HF_HOME=/home/app/text-generation-webui/cache
PYTORCH_KERNEL_CACHE_PATH=/home/app/text-generation-webui/cache
13 changes: 7 additions & 6 deletions docker/amd/Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# BUILDER
FROM ubuntu:22.04
WORKDIR /builder

ARG GPU_CHOICE=${GPU_CHOICE:-A} # A: NVIDIA, B: AMD, C: APPLE, D: INTEL, N: NONE (CPU)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and other ARG should just be the value assignment.

Why are they using var assignment?

Suggested change
ARG GPU_CHOICE=${GPU_CHOICE:-A} # A: NVIDIA, B: AMD, C: APPLE, D: INTEL, N: NONE (CPU)
# A: NVIDIA, B: AMD, C: APPLE, D: INTEL, N: NONE (CPU)
ARG GPU_CHOICE=A

You can override that default with --build-arg GPU_CHOICE=B, there is no need to try interpolate anything here like ENV.

ARG TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST:-3.5;5.0;6.0;6.1;7.0;7.5;8.0;8.6+PTX}"
ARG BUILD_EXTENSIONS="${BUILD_EXTENSIONS:-}"
ARG APP_UID="${APP_UID:-6972}"
ARG APP_GID="${APP_GID:-6972}"

WORKDIR /builder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this directive? You don't use /builder in the next RUN and the next WORKDIR that follows changes the location again.

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,rw \
apt update && \
apt install --no-install-recommends -y git vim build-essential python3-dev pip bash curl && \
rm -rf /var/lib/apt/lists/*
WORKDIR /home/app/
RUN git clone https://github.com/oobabooga/text-generation-webui.git
RUN git clone https://github.com/oobabooga/text-generation-webui.git

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Dockerfile for a project it resides in should really just be sourcing the context of the repo already available.

Since this is already what the image has been doing, I'd defer changing this until a follow-up PR, but you should build from the repo with the repo root as the build context. The benefit is you can go to any tag/commit of the repo from that point onwards and build the image if needed. It's better for automation in CI too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got a WORKDIR /home/app followed by the clone and then WORKDIR /home/app/text-generation-webui to change directories.

Suggested change
RUN git clone https://github.com/oobabooga/text-generation-webui.git
WORKDIR /home/app/text-generation-webui
RUN git clone https://github.com/oobabooga/text-generation-webui.git .

Remove the other two WORKDIR surrounding that suggestion, they're redundant.

WORKDIR /home/app/text-generation-webui
RUN GPU_CHOICE=B USE_CUDA118=FALSE LAUNCH_AFTER_INSTALL=FALSE INSTALL_EXTENSIONS=TRUE ./start_linux.sh --verbose
RUN USE_CUDA118=FALSE LAUNCH_AFTER_INSTALL=FALSE INSTALL_EXTENSIONS=TRUE ./start_linux.sh --verbose
COPY CMD_FLAGS.txt /home/app/text-generation-webui/
EXPOSE ${CONTAINER_PORT:-7860} ${CONTAINER_API_PORT:-5000} ${CONTAINER_API_STREAM_PORT:-5005}
WORKDIR /home/app/text-generation-webui
ENV HOME=/home/app/text-generation-webui
# set umask to ensure group read / write at runtime
CMD umask 0002 && export HOME=/home/app/text-generation-webui && ./start_linux.sh
CMD umask 0002 && ./start_linux.sh $CLI_ARGS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CMD umask 0002 && ./start_linux.sh $CLI_ARGS
ENTRYPOINT [ "/home/app/text-generation-webui/start_linux.sh" ]

Now CLI_ARGS would just be provided as the command (CMD):

docker run --rm -it image-name $CLI_ARGS

In compose.yaml the command field can set the CLI args to use, or you can use the Docker Compose ENV interpolation from a .env file to also use ${CLI_ARGS} as a value (kinda redundant though).

46 changes: 25 additions & 21 deletions docker/amd/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@ services:
build:
context: .
args:
# Requirements file to use:
# | GPU | CPU | requirements file to use |
# |--------|---------|---------|
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
GPU_CHOICE: B # AMD

# Requirements file to use:
# | GPU | CPU | requirements file to use |
# | -------- | ------------- | ---------------------------------- |
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
# Default: requirements.txt`
# BUILD_REQUIREMENTS: requirements.txt

# Extension requirements to build:
# BUILD_EXTENSIONS:

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}

# Extension requirements to build:
BUILD_EXTENSIONS: ${BUILD_EXTENSIONS:-}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID-6972}

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID:-6972}
Comment on lines +28 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these actually used for anything? Nothing appears to reference them: https://github.com/search?q=repo%3Aoobabooga%2Ftext-generation-webui%20APP_UID&type=code

If they're only meant to change the runtime user, this should just be done with the standard user: uid:gid compose setting or docker run --user uid:gid CLI arg.

container_name: text-generation-webui
env_file: .env
hostname: text-generation-webui

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

user: "${APP_RUNTIME_UID:-6972}:${APP_RUNTIME_GID:-6972}"
ports:
- "${HOST_PORT:-7860}:${CONTAINER_PORT:-7860}"
- "${HOST_API_PORT:-5000}:${CONTAINER_API_PORT:-5000}"
restart: unless-stopped
stdin_open: true
group_add:
- video
tty: true
ipc: host
devices:
- /dev/kfd
- /dev/dri
cap_add:
- /dev/dri
cap_add:
- SYS_PTRACE
security_opt:
- seccomp=unconfined
Expand Down
25 changes: 0 additions & 25 deletions docker/cpu/Dockerfile

This file was deleted.

42 changes: 23 additions & 19 deletions docker/cpu/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ services:
build:
context: .
args:
# Requirements file to use:
# | GPU | CPU | requirements file to use |
# |--------|---------|---------|
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
GPU_CHOICE: N # NONE (CPU)

# Requirements file to use:
# | GPU | CPU | requirements file to use |
# | -------- | ------------- | ---------------------------------- |
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
# Default: requirements.txt`
# BUILD_REQUIREMENTS: requirements.txt

# Extension requirements to build:
# BUILD_EXTENSIONS:

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}

# Extension requirements to build:
BUILD_EXTENSIONS: ${BUILD_EXTENSIONS:-}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID-6972}

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID:-6972}
container_name: text-generation-webui
env_file: .env
hostname: text-generation-webui
user: "${APP_RUNTIME_UID:-6972}:${APP_RUNTIME_GID:-6972}"
ports:
- "${HOST_PORT:-7860}:${CONTAINER_PORT:-7860}"
- "${HOST_API_PORT:-5000}:${CONTAINER_API_PORT:-5000}"
restart: unless-stopped
stdin_open: true
tty: true
volumes:
Expand Down
21 changes: 0 additions & 21 deletions docker/intel/Dockerfile

This file was deleted.

48 changes: 27 additions & 21 deletions docker/intel/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,55 @@ services:
build:
context: .
args:
# Requirements file to use:
# | GPU | CPU | requirements file to use |
# |--------|---------|---------|
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
GPU_CHOICE: D # INTEL

# Requirements file to use:
# | GPU | CPU | requirements file to use |
# | -------- | ------------- | ---------------------------------- |
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
# Default: requirements.txt`
# BUILD_REQUIREMENTS: requirements.txt

# Extension requirements to build:
# BUILD_EXTENSIONS:

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}

# Extension requirements to build:
BUILD_EXTENSIONS: ${BUILD_EXTENSIONS:-}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID-6972}

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID:-6972}
container_name: text-generation-webui
env_file: .env
hostname: text-generation-webui
user: "${APP_RUNTIME_UID:-6972}:${APP_RUNTIME_GID:-6972}"
ports:
- "${HOST_PORT:-7860}:${CONTAINER_PORT:-7860}"
- "${HOST_API_PORT:-5000}:${CONTAINER_API_PORT:-5000}"
restart: unless-stopped
stdin_open: true
group_add:
- video
tty: true
ipc: host
devices:
- /dev/kfd
- /dev/dri
cap_add:
- /dev/dri
cap_add:
- SYS_PTRACE
security_opt:
- seccomp=unconfined
volumes:
- ./cache:/home/app/text-generation-webui/cache
- ./characters:/home/app/text-generation-webui/characters
- ./extensions:/home/app/text-generation-webui/extensions
- ./loras:/home/app/text-generation-webui/loras
- ./logs:/home/app/text-generation-webui/logs
- ./models:/home/app/text-generation-webui/models
- ./presets:/home/app/text-generation-webui/presets
- ./prompts:/home/app/text-generation-webui/prompts
Expand Down
21 changes: 0 additions & 21 deletions docker/nvidia/Dockerfile

This file was deleted.

42 changes: 23 additions & 19 deletions docker/nvidia/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ services:
build:
context: .
args:
# Requirements file to use:
# | GPU | CPU | requirements file to use |
# |--------|---------|---------|
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
# GPU_CHOICE: A # NVIDIA (default)

# Requirements file to use:
# | GPU | CPU | requirements file to use |
# | -------- | ------------- | ---------------------------------- |
# | NVIDIA | has AVX2 | `requirements.txt` |
# | NVIDIA | no AVX2 | `requirements_noavx2.txt` |
# | AMD | has AVX2 | `requirements_amd.txt` |
# | AMD | no AVX2 | `requirements_amd_noavx2.txt` |
# | CPU only | has AVX2 | `requirements_cpu_only.txt` |
# | CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |
# | Apple | Intel | `requirements_apple_intel.txt` |
# | Apple | Apple Silicon | `requirements_apple_silicon.txt` |
# Default: requirements.txt`
# BUILD_REQUIREMENTS: requirements.txt

# Extension requirements to build:
# BUILD_EXTENSIONS:

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}

# Extension requirements to build:
BUILD_EXTENSIONS: ${BUILD_EXTENSIONS:-}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID-6972}

# specify which cuda version your card supports: https://developer.nvidia.com/cuda-gpus
TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST:-7.5}
APP_GID: ${APP_GID:-6972}
APP_UID: ${APP_UID:-6972}
container_name: text-generation-webui
env_file: .env
hostname: text-generation-webui
user: "${APP_RUNTIME_UID:-6972}:${APP_RUNTIME_GID:-6972}"
ports:
- "${HOST_PORT:-7860}:${CONTAINER_PORT:-7860}"
- "${HOST_API_PORT:-5000}:${CONTAINER_API_PORT:-5000}"
restart: unless-stopped
stdin_open: true
tty: true
volumes:
Expand Down
6 changes: 5 additions & 1 deletion docs/09 - Docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ Use these commands to launch the image:

```
cd text-generation-webui
ln -s docker/{nvidia/Dockerfile,docker-compose.yml,.dockerignore} .
ln -s docker/{nvidia/docker-compose.yml,.dockerignore,Dockerfile} .
cp docker/.env.example .env
# Edit .env and set TORCH_CUDA_ARCH_LIST based on your GPU model

# Ensure all mounted dirs exist or they'll be created by Docker as root
mkdir -p cache cloudflared logs softprompts

docker compose up --build
```

Expand Down