diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f92863d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.cache/ +cudnn_windows/ +bitsandbytes_windows/ +dataset/ +__pycache__/ +venv/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54435f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM nvcr.io/nvidia/pytorch:23.04-py3 as base +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=Europe/London + +RUN apt-get update && \ + apt-get install -y git curl python3-venv python3-tk libgl1 libglib2.0-0 libgoogle-perftools-dev && \ + rm -rf /var/lib/apt/lists/* + +RUN useradd -m -s /bin/bash appuser +USER appuser + +WORKDIR /app + +RUN python3 -m venv ./venv && . ./venv/bin/activate && \ + python3 -m pip install wheel + +COPY requirements.txt setup.py . +RUN . ./venv/bin/activate && \ + python3 -m pip install --use-pep517 -U -r requirements.txt triton torch>=2.0.0+cu121 xformers \ + --extra-index-url https://download.pytorch.org/whl/cu121 + +USER appuser +COPY --chown=appuser . . + +STOPSIGNAL SIGINT +ENV LD_PRELOAD=libtcmalloc.so +CMD . ./venv/bin/activate && ./gui.sh --listen 0.0.0.0 --server_port 7860 diff --git a/README.md b/README.md index b7a35cd..4eaa2ec 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,30 @@ These dependencies are taken care of via `setup.sh` in the installation section. ### Runpod Follow the instructions found in this discussion: https://github.com/bmaltais/kohya_ss/discussions/379 +### Docker +Docker is supported on Windows, Linux and macOS distributions. However this method currently only supports Nvidia GPUs. +Run the following commands in your OS shell after installing [git](https://git-scm.com/download/) and [docker](https://www.docker.com/products/docker-desktop/): +```bash +git clone https://github.com/bmaltais/kohya_ss.git +cd kohya_ss +docker compose up --build +``` + +This will take a while (up to 20 minutes) on the first run. + +The following limitations apply: +* All training data must be added to the `dataset` subdirectory, the docker container cannot access any other files +* The file picker does not work + * Cannot select folders, folder path must be set manually like e.g. /dataset/my_lora/img + * Cannot select config file, it must be loaded via path instead like e.g. /dataset/my_config.json +* Dialogs do not work + * Make sure your file names are unique as this happens when asking if an existing file should be overridden +* No auto-update support. Must run update scripts outside docker manually and then rebuild with `docker compose build`. + ### Linux and macOS In the terminal, run -``` +```bash git clone https://github.com/bmaltais/kohya_ss.git cd kohya_ss # May need to chmod +x ./setup.sh if you're on a machine with stricter security. diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..28c210a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,32 @@ +version: "3.8" +services: + kohya-ss-gui: + container_name: kohya-ss-gui + image: kohya-ss-gui:latest + build: + context: . + ports: + - 127.0.0.1:7860:7860 + stdin_open: true + tty: true + ipc: host + environment: + CLI_ARGS: "" + SAFETENSORS_FAST_GPU: 1 + tmpfs: + - /tmp + volumes: + - ./dataset:/dataset + - ./.cache/cache.json:/app/cache.json + - ./.cache/user:/home/appuser/.cache + - ./.cache/triton:/home/appuser/.triton + - ./.cache/__pycache__:/app/__pycache__ + - ./.cache/nv:/home/appuser/.nv + - ./.cache/keras:/home/appuser/.keras + deploy: + resources: + reservations: + devices: + - driver: nvidia + device_ids: ['0'] + capabilities: [gpu]