1
0
hugo/content/blog/2023-08-31-docker.md

105 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2024-04-23 13:21:26 +00:00
+++
date = "2023-08-31"
tags = ["docker"]
title = "dockerでstable diffusionを構築してみた"
slug = "docker"
+++
### stable diffusion v1.4
src : https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
sd-v1-4.ckpt : https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt
`.ckpt`はファイルが大きいのでgit cloneでdownloadされません。
```sh
$ mkdir -p {model,outputs}
$ mv sd-v1-4.ckpt ./model/model.ckpt
$ vim Dockerfile
```
```sh
FROM nvcr.io/nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo
RUN apt-get update && apt-get install -y wget git git-lfs libglib2.0-0 libsm6 libxrender1 libxext-dev
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
sh Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3 && \
rm -r Miniconda3-latest-Linux-x86_64.sh
ENV PATH /opt/miniconda3/bin:$PATH
# RUN git clone https://github.com/CompVis/stable-diffusion && \
# cd stable-diffusion && \
# conda init bash && \
# conda env create -f environment.yaml && \
# echo "conda activate ldm" >> ~/.bashrc
RUN git clone https://github.com/basujindal/stable-diffusion.git && \
cd stable-diffusion && \
conda init bash && \
conda env create -f environment.yaml && \
echo "conda activate ldm" >> ~/.bashrc
```
```yml:compose.yml
version: '3'
services:
stable_diffusion:
build: .
working_dir: /stable-diffusion
tty: true
volumes:
- ./model/:/stable-diffusion/models/ldm/stable-diffusion-v1/
- ./outputs:/stable-diffusion/outputs
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
environment:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=all
```
```sh
$ docker compose up
---
$ docker compose exec stable_diffusion bash
$ prompt="masterpiece, high quality, very_high_resolution, large_filesize, full color, little girl, simple white onepice"
$ python optimizedSD/optimized_txt2img.py --H 512 --W 512 --seed 27 --n_iter 2 --n_samples 1 --ddim_steps 5 --prompt $prompt
```
スペックがあまり良くないubuntu-serverで構築しているので、実行すると他のサーバーが止まる。
ref : https://zenn.dev/choshicure/scraps/14bca2492bf49f
## stable diffusion v1.5, webui
https://github.com/AbdBarho/stable-diffusion-webui-docker
```sh
$ git clone https://github.com/AbdBarho/stable-diffusion-webui-docker
$ cd stable-diffusion-webui-docker
$ docker compose --profile download up --build
$ ls ./data/models
# 様々なui
# https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Usage
$ docker compose --profile auto up --build
$ docker compose --profile invoke up --build
```
## mac, ipad
https://apps.apple.com/jp/app/draw-things-ai-generation/id6444050820
https://github.com/godly-devotion/MochiDiffusion