commit 2c65c0500cf81fd7c4b7649d0ea215b3752c92ba Author: Dmitriy Kholkin Date: Thu Oct 27 21:43:05 2022 +0300 init version diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c0c2bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/backup +/shared/** +!/shared/init.sh +!.envrc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..600f2e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM greyltc/archlinux-aur:yay + +ARG UID=1000 +ARG GID=100 +ARG UNAME=rocm +# import keys +RUN pacman-key --init && pacman -Syu --noconfirm \ + && curl -O https://mirrors.tuna.tsinghua.edu.cn/arch4edu/any/arch4edu-keyring-20200805-1-any.pkg.tar.zst \ + && pacman -U arch4edu-keyring-20200805-1-any.pkg.tar.zst --noconfirm \ + && rm -f arch4edu-keyring-20200805-1-any.pkg.tar.zst \ + && pacman-key --recv-keys 7931B6D628C8D3BA && pacman-key --finger 7931B6D628C8D3BA && pacman-key --lsign-key 7931B6D628C8D3BA \ + && printf "[arch4edu]\nServer = https://mirror.lesviallon.fr/arch4edu/\$arch" >> /etc/pacman.conf \ + && pacman -Syu --noconfirm && pacman-db-upgrade + +# install rocm, pytoch, torchvision +RUN aur-install python-pytorch-rocm python-torchvision git unzip wget nano gdown + +# create user and work directory +RUN groupadd -g $GID -o $UNAME \ + && useradd -m -u $UID -g $GID -o -G wheel,video -s /bin/bash $UNAME \ + && echo "$UNAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \ + && mkdir /shared && chown $UID:$GID /shared + +USER $UNAME +WORKDIR /shared +ENV PATH "${PATH}:/opt/rocm/bin" +ENV TRANSFORMERS_CACHE "/shared/.transformers-cache" +CMD [ "bash", "-l" ] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee715bd --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Stable-Diffusion-WebUI (AUROMATIC1111) docker image for AMD GPUs + +Contains init script (./shared/init.sh) that downloads the NAI model, hypernetworks, danbooru tag autocomplition and some sane ui-config defaults. + +1. Clone this repository (optional) +2. Run docker container. For example: + +```bash +docker run -it --rm --name stable-diffusion --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --port 80:7860 -v $(pwd)/shared:/shared ataraxiadev/rocm-pytorch /shared/init.sh --theme dark --listen --port 7860 --deepdanbooru +``` + +Nixos users can clone this repository and run: + +```bash +nix run +``` + +or + +```bash +nix develop +image-run +``` diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..37791b1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils-plus": { + "inputs": { + "flake-utils": "flake-utils" + }, + "locked": { + "lastModified": 1657226504, + "narHash": "sha256-GIYNjuq4mJlFgqKsZ+YrgzWm0IpA4axA3MCrdKYj7gs=", + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "rev": "2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a", + "type": "github" + }, + "original": { + "owner": "gytis-ivaskevicius", + "repo": "flake-utils-plus", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1666703756, + "narHash": "sha256-GwpMJ1hT+z1fMAUkaGtvbvofJQwdVFDEGVhfE82+AUk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f994293d1eb8812f032e8919e10a594567cf6ef7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils-plus": "flake-utils-plus", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bab2bc5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,34 @@ +{ + inputs = { + flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs, flake-utils-plus, ... }@inputs: + let + pkgs-unstable = self.channels.unstable; + in flake-utils-plus.lib.mkFlake { + inherit self inputs; + channels.unstable.input = nixpkgs; + + outputsBuilder = channels: let + pkgs = channels.unstable; + image-tag = "ataraxiadev/rocm-pytorch:latest"; + cmd-line-options = "/shared/init.sh --theme dark --listen --port 7860 --deepdanbooru --medvram --opt-split-attention"; + in rec { + packages = { + image-build = pkgs.writeShellScriptBin "image-build" '' + docker build --force-rm --tag ${image-tag} "$@" . + ''; + image-run = pkgs.writeShellScriptBin "image-run" '' + docker run -it --rm --name stable-diffusion --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 80:7860 -v $(pwd)/shared:/shared ${image-tag} ${cmd-line-options} "$@" + ''; + }; + defaultPackage = packages.image-run; + devShell = pkgs.mkShell { + name = "pytorch-terminal"; + packages = with packages; [ image-build image-run ]; + }; + }; + }; +} diff --git a/shared/init.sh b/shared/init.sh new file mode 100755 index 0000000..f5f3821 --- /dev/null +++ b/shared/init.sh @@ -0,0 +1,43 @@ +#!/bin/bash +cd /shared +if [ ! -d "stable-diffusion-webui" ]; then + git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git stable-diffusion-webui + cd stable-diffusion-webui + # Download NAI model + gdown --folder -O nai 1IM63Lef1lEPwUbSdVtdHn_VVT4DaKX6u + mv nai/nai.ckpt ./models/Stable-diffusion + mv nai/nai.vae.pt ./models/Stable-diffusion + mv nai/nai.yaml ./models/Stable-diffusion + mv nai/v2.pt ./ + mv nai/v2enable.py ./scripts + # Download hypernetworks + unzip nai/hypernetworks.zip -d ./models + rm -f nai/hypernetworks.zip + rmdir nai + # Install danbooru tag auto-complition and sane nai defaults + git clone https://github.com/DominikDoom/a1111-sd-webui-tagcomplete /tmp/tagcomplete + cp -r /tmp/tagcomplete/javascript /shared/stable-diffusion-webui/ + cp -r /tmp/tagcomplete/tags /shared/stable-diffusion-webui/ + cp -r /tmp/tagcomplete/scripts /shared/stable-diffusion-webui/ + rm -rf /tmp/* + wget https://gist.githubusercontent.com/AlukardBF/27c27f7982b2cdaafa3badd082d061c5/raw/eb95d63caaa1a7c108f8d5d0ed6913f47506a1d5/ui-config.js -O /shared/stable-diffusion-webui/ui-config.json + wget https://gist.githubusercontent.com/AlukardBF/66d6450047dfa8e1f53b7586152497ff/raw/830f0c5201251eb7f8164609a404e38d9c049bc0/config.json -O /shared/stable-diffusion-webui/config.json + # History tab extension + mkdir -p extensions + git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser extensions/images-browser + + python3 -m venv --system-site-packages venv + source venv/bin/activate + pip install --upgrade pip + # workaround this issue: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/2858 + sed -i -E "s#gradio.*#gradio==3.4.1#" requirements_versions.txt +else + cd /shared/stable-diffusion-webui + git restore requirements_versions.txt + git pull + sed -i -E "s#gradio.*#gradio==3.4.1#" requirements_versions.txt + source venv/bin/activate + pip install --upgrade pip +fi +export REQS_FILE=requirements_versions.txt +python3 launch.py "$@"