制作及运行 WebUI(NovelAI)Docker 镜像

制作及运行 WebUI(NovelAI)Docker 镜像

图源:《天地上等》@banishment 100412674

准备 Novel AI 模型文件

下载地址:

1
magnet:?xt=urn:btih:5bde442da86265b670a3e5ea3163afad2c6f8ecc

只需要部分下载其中的文件;

  • 必须的文件:
    • 文件 stableckpt/animevae.pt
    • 文件夹 stableckpt/animefull-final-pruned
  • 可选的文件:
    • 文件夹 stableckpt/animefull-latest (全量模型,暂时没发现有什么特殊用途)
    • 文件夹 stableckpt/modules/modules (差分模型,针对特定风格强化训练)
Novel AI 文件列表

将下载后的文件重命名,并放到同一个目录下的 models/ 子目录下

  • stableckpt/animevae.pt -> models/nai.vae.pt
  • stableckpt/animefull-final-pruned/model.ckpt -> models/nai.ckpt
  • stableckpt/animefull-final-pruned/config.yaml -> models/nai.yaml
models 文件夹

Dockerfile 示例

注:没有对镜像大小做特殊优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
FROM python:3.10-bullseye
LABEL org.opencontainers.image.authors="ObjectNotFound"
WORKDIR /root
# Prepare
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y python3-opencv && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Python environment setup
RUN pip install --upgrade --no-cache-dir pip && \
pip install --upgrade --no-cache-dir setuptools && \
pip install --upgrade --no-cache-dir opencv-python && \
pip install --no-cache-dir torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117 && \
pip install --no-cache-dir jupyterlab gfpgan open_clip_torch xformers==0.0.16rc425 && \
pip install --no-cache-dir git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 && \
rm -rf ~/.cache/pip
# Clone files
RUN git clone --depth=1 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git && \
cd stable-diffusion-webui && \
mkdir repositories && \
cd repositories && \
git clone https://github.com/Stability-AI/stablediffusion.git stable-diffusion-stability-ai && \
git clone https://github.com/CompVis/taming-transformers.git && \
git clone https://github.com/crowsonkb/k-diffusion.git && \
git clone https://github.com/sczhou/CodeFormer.git && \
git clone https://github.com/salesforce/BLIP.git && \
cd .. && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir -r repositories/CodeFormer/requirements.txt && \
rm -rf ~/.cache/pip
# Place model files under models/
# Rename to nai.yaml nai.ckpt nai.vae.pt
ADD models/ /root/stable-diffusion-webui/models/Stable-diffusion
WORKDIR /root/stable-diffusion-webui
EXPOSE 7860
ENTRYPOINT [ "python3", "./launch.py", "--xformers", "--listen", "--port", "7860" ]

以上代码保存到 Dockerfile,和 models/ 放到一起,然后 docker build 即可;

1
2
# 以localhost:5000/aipaint-novelai:latest 为 tag 示例
docker build . -t localhost:5000/aipaint-novelai:latest
Build 成功的镜像

使用 Docker Image

环境设置

  • 硬件要求
    • 需要至少 16 GB 运行内存
    • 需要 NVIDIA 独立显卡
  • 需要是以下受 NVIDIA 官方支持的Linux发行版:
    • Amazon Linux (AWS)
    • OpenSUSE / SUSE Linux Enterprise Server
    • CentOS
    • Red Hat Enterprise Linux
    • Ubuntu
    • Debian
  • 需要安装以下软件
    • 闭源的 NVIDIA 官方 Linux 驱动
    • Docker
  • 安装 nvidia-container-toolkit
  • 检查是否安装成功
    • 查看 Docker 是否接受 --gpu 参数:docker run --help | grep -i gpus
    • 尝试在 Docker 容器中运行 nvidia-smi
1
2
3
# 镜像版本建议先查看 Docker Hub 页面
# https://hub.docker.com/r/nvidia/cuda
docker run --gpus all nvidia/cuda:12.0.1-base-ubi9 nvidia-smi

若输出正常则证明 nvidia-container-toolkit 安装成功。

Docker 运行 nvidia-smi

运行镜像

1
2
# 可加 -d 让其后台运行
docker run --gpus all -p 7860:7860 localhost:5000/aipaint-novelai:latest
运行输出

多个显卡情况下,可以使用 --gpus 的参数选择使用哪些显卡:

  • 使用2块显卡:--gpus 2
  • 使用第一块和第三块显卡:--gpus device=1,3
  • 使用显卡 UUID 指定显卡:--gpus device=GPU-3a23c669-1f69-c64e-cf85-44e9b07e7a2a
    • 显卡 UUID 可从 NVIDIA X Server Settings -> (选择GPU) -> GPU UUID 查看
查看显卡 UUID

访问 http://localhost:7860 即可使用带 Novel AI 模型的 stable-diffusion-webui;

Stable Diffusion WebUI

制作及运行 WebUI(NovelAI)Docker 镜像

https://www.zhouweitong.site/2023/09/14/novelai-webui-docker-image/

作者

ObjectNotFound

发布于

2023-09-14

更新于

2023-09-14

许可协议

评论

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×