SD-webui

์ฝ”๋”ฉ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”๋ถ€๋ถ„์„ ์ดํ•ดํ–ˆ์œผ๋‹ˆ ์ด์ œ ์›น์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„์„ ์ดํ•ดํ•ด๋ณด์ž.

stable-diffusion-webui ๋ผ๋Š” ์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/master

Dockerfile ์ƒ์„ฑ

FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-runtime

RUN apt update

RUN apt install -y libgl1 wget git curl

RUN DEBIAN_FRONTEND=noninteractive  TZ="America/Los_Angeles" apt install -y libglib2.0-0

WORKDIR /app

RUN git clone --depth 1 --branch v1.7.0 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

RUN pip install -r stable-diffusion-webui/requirements.txt

# # root ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ
RUN sed -i 's/can_run_as_root=0/can_run_as_root=1/g' stable-diffusion-webui/webui.sh

EXPOSE 7860

WORKDIR /app/stable-diffusion-webui

ENTRYPOINT [ "python","launch.py","--listen"]

docker-compose.yaml ์ƒ์„ฑ

version: '3.8'
services:
  sd-webui:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: sd-webui
    restart: unless-stopped
    ports:
      - 7860:7860
    volumes:
      - ./models:/app/stable-diffusion-webui/models
      - ./repositories:/app/stable-diffusion-webui/repositories
      - ./outputs:/app/stable-diffusion-webui/outputs
      - ./embeddings:/app/stable-diffusion-webui/embeddings
    deploy:
      resources:
        reservations:
          devices:
            - driver: 'nvidia'
              capabilities: [gpu]
              count: all

์‹คํ–‰

docker-compose up -d

ํ™•์ธ

curl http://localhost:7860

![Alt text](images/2. SD-webui/image.png)

option ์„ค๋ช…

์œ ํˆฌ๋ธŒ์— ๋‚ด์šฉ์ด ๋งŽ์œผ๋ฏ€๋กœ ํ™•์ธํ•ด๋ณด๋ฉด๋ ๊ฑฐ๊ฐ™๋‹ค. ๊ธฐ๋ณธ์ ์ธ๋ถ€๋ถ„์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • prompt : ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋‹จ์–ด

  • negative prompt : ํฌํ•จ๋˜์ง€ ์•Š๊ธฐ๋ฅผ ๋ฐ”๋ผ๋Š” ๋‹จ์–ด

  • sampling step : ๊ธฐ๋ณธ 20 ๋‚ฎ์œผ๋ฉด ๋ญ‰๊ฐœ์ง ๋†’์œผ๋ฉด ๊นจ๋—ํ•ด์ง

  • sampleing method : ์กฐ๊ธˆ์”ฉ ๋‹ค๋ฆ„

  • width/height : ๊ฐ€๋กœ / ์„ธ๋กœ 512๊ฐ€ ๊ฐ€์žฅ ์ž˜๋‚˜์˜จ๋‹ค.

  • restore faces : ์–ผ๊ตด์ด ์ž˜ ๋ชป๋‚˜์˜ค๋Š”๊ฑธ ๋ณด์ •ํ•ด์ค€๋‹ค.

  • tiling : tiling์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๋Œ€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋‚˜์˜ค๊ฒŒ ํ•œ๋‹ค.

  • Highres : ์ด์ƒํ•œ ์š”์†Œ๋“ค์„ ๋ณด์ • ๋จธ๋ฆฌ๊ฐ€ ๋‘๊ฐœ ๋“ฑ๋“ฑ

  • batch count/ size => ๊ณฑํ•œ๋งŒํผ ๊ทธ๋ฆผ์ด ๋‚˜์˜จ๋‹ค.

  • cfg scale : ์–ผ๋งˆ๋‚˜ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋”ฐ๋ผ๊ฐ€๋Š”์ง€ ๋‚ฎ์œผ๋ฉด ํ”„๋กฌํ”„ํŠธ๋ž‘ ์ƒ๊ด€์—†์ด ๋†’์œผ๋ฉด ํ”„๋กฌํ”„๊ฐ’ ๊ทธ๋Œ€๋กœ

  • seed: ๊ธฐ์กด ์ƒ์„ฑํ•œ ์ด๋ฏธ์ง€์˜ seed๊ฐ’์„ ๋„ฃ์œผ๋ฉด ๊ธฐ์กด ์ด๋ฏธ์ง€์Šคํƒ€์ผ๊ณผ ๋น„์Šทํ•˜๊ฒŒ ์ƒ์„ฑ๋œ๋‹ค.

  • script :

    • prompt๋ฅผ ๋น„๊ตํ•ด์„œ ํ‘œ์˜ ํ˜•ํƒœ๋กœ ๋ณด์—ฌ์ค€๋‹ค.

    • ํ”„๋กฌํ”„ํŠธ ํŒŒ์ผ์„ ์—…๋กœ๋“œ ๋œ๋‹ค.

    • x/y plot x์ถ•๊ณผ y์ถ•์— ๋‹ค๋ฅธ ๊ฐ’์„ ๋„ฃ์–ด์„œ ํ™”๋ฉด์—์„œ ๋น„๊ตํ• ์ˆ˜ ์ž‡๊ฒŒ table๋กœ ๋‚˜์˜จ๋‹ค.

![Alt text](images/2. SD-webui/image-1.png)

  1. ๋žœ๋คํ•œ ํ™”๊ฐ€์˜ ์ด๋ฆ„์„ ๋„ฃ์–ด์คŒ

  2. ๊ธฐ์กด ๊ทธ๋ฆผ์— ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ฐ€์ ธ์™€์„œ ๋ณด์—ฌ์คŒ

  3. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ €์žฅํ• ์ˆ˜ ์žˆ์Œ ๋ฐ”๋กœ ์˜†์— ๋กœ๋”ฉํ• ์ˆ˜ ์ž‡์Œ

์ถ”๊ฐ€ ์‚ฌ์šฉ๋ฒ•

checkpoint์™€ lora, vae๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์ข‹์€ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ• ์ˆ˜ ์žˆ๋‹ค.

https://civitai.com ์—ฌ๊ธฐ์—์„œ ๋ชจ๋ธ์„ ๋‹ค์šด๋ฐ›์„์ˆ˜ ์žˆ๋‹ค.

check point ์‚ฌ์šฉํ•˜๊ธฐ

์‚ฌ์ดํŠธ์—์„œ check point model์„ ๋ฐ›์•„์„œ stable-diffusion-webui/models/Stable-diffusion ํด๋”์— ๋„ฃ์–ด์ค€๋‹ค. ui์—์„œ refresh๋ฅผ ๋ˆ„๋ฅด๋ฉด ํŒŒ์ผ๋ณด์ธ๋‹ค ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

lora ์‚ฌ์šฉํ•˜๊ธฐ

์‚ฌ์ดํŠธ์—์„œ lora๋ฅผ ๋ฐ›์•„์„œ stable-diffusion-webui/models/Loraํด๋”์— ๋„ฃ์–ด์ค€๋‹ค. ui์—์„œ refresh๋ฅผ ๋ˆ„๋ฅด๋ฉด ํŒŒ์ผ๋ณด์ธ๋‹ค ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

vae ์‚ฌ์šฉํ•˜๊ธฐ

์‚ฌ์ดํŠธ์—์„œ vae๋ฅผ ๋ฐ›์•„์„œ stable-diffusion-webui/models/VAEํด๋”์— ๋„ฃ์–ด์ค€๋‹ค.

ui์—์„œ refresh๋ฅผ ๋ˆ„๋ฅด๋ฉด ํŒŒ์ผ๋ณด์ธ๋‹ค ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

launch.py ์˜ต์…˜

usage: launch.py [-h]
                 [--update-all-extensions]
                 [--skip-python-version-check]
                 [--skip-torch-cuda-test]
                 [--reinstall-xformers]
                 [--reinstall-torch]
                 [--update-check]
                 [--test-server]
                 [--log-startup]
                 [--skip-prepare-environment]
                 [--skip-install]
                 [--dump-sysinfo]
                 [--loglevel LOGLEVEL]
                 [--do-not-download-clip]
                 [--data-dir DATA_DIR]
                 [--config CONFIG]
                 [--ckpt CKPT]
                 [--ckpt-dir CKPT_DIR]
                 [--vae-dir VAE_DIR]
                 [--gfpgan-dir GFPGAN_DIR]
                 [--gfpgan-model GFPGAN_MODEL]
                 [--no-half]
                 [--no-half-vae]
                 [--no-progressbar-hiding]
                 [--max-batch-count MAX_BATCH_COUNT]
                 [--embeddings-dir EMBEDDINGS_DIR]
                 [--textual-inversion-templates-dir TEXTUAL_INVERSION_TEMPLATES_DIR]
                 [--hypernetwork-dir HYPERNETWORK_DIR]
                 [--localizations-dir LOCALIZATIONS_DIR]
                 [--allow-code]
                 [--medvram]
                 [--medvram-sdxl]
                 [--lowvram]
                 [--lowram]
                 [--always-batch-cond-uncond]
                 [--unload-gfpgan]
                 [--precision {full,autocast}]
                 [--upcast-sampling]
                 [--share]
                 [--ngrok NGROK]
                 [--ngrok-region NGROK_REGION]
                 [--ngrok-options NGROK_OPTIONS]
                 [--enable-insecure-extension-access]
                 [--codeformer-models-path CODEFORMER_MODELS_PATH]
                 [--gfpgan-models-path GFPGAN_MODELS_PATH]
                 [--esrgan-models-path ESRGAN_MODELS_PATH]
                 [--bsrgan-models-path BSRGAN_MODELS_PATH]
                 [--realesrgan-models-path REALESRGAN_MODELS_PATH]
                 [--clip-models-path CLIP_MODELS_PATH]
                 [--xformers]
                 [--force-enable-xformers]
                 [--xformers-flash-attention]
                 [--deepdanbooru]
                 [--opt-split-attention]
                 [--opt-sub-quad-attention]
                 [--sub-quad-q-chunk-size SUB_QUAD_Q_CHUNK_SIZE]
                 [--sub-quad-kv-chunk-size SUB_QUAD_KV_CHUNK_SIZE]
                 [--sub-quad-chunk-threshold SUB_QUAD_CHUNK_THRESHOLD]
                 [--opt-split-attention-invokeai]
                 [--opt-split-attention-v1]
                 [--opt-sdp-attention]
                 [--opt-sdp-no-mem-attention]
                 [--disable-opt-split-attention]
                 [--disable-nan-check]
                 [--use-cpu USE_CPU [USE_CPU ...]]
                 [--use-ipex]
                 [--disable-model-loading-ram-optimization]
                 [--listen]
                 [--port PORT]
                 [--show-negative-prompt]
                 [--ui-config-file UI_CONFIG_FILE]
                 [--hide-ui-dir-config]
                 [--freeze-settings]
                 [--ui-settings-file UI_SETTINGS_FILE]
                 [--gradio-debug]
                 [--gradio-auth GRADIO_AUTH]
                 [--gradio-auth-path GRADIO_AUTH_PATH]
                 [--gradio-img2img-tool GRADIO_IMG2IMG_TOOL]
                 [--gradio-inpaint-tool GRADIO_INPAINT_TOOL]
                 [--gradio-allowed-path GRADIO_ALLOWED_PATH]
                 [--opt-channelslast]
                 [--styles-file STYLES_FILE]
                 [--autolaunch]
                 [--theme THEME]
                 [--use-textbox-seed]
                 [--disable-console-progressbars]
                 [--enable-console-prompts]
                 [--vae-path VAE_PATH]
                 [--disable-safe-unpickle]
                 [--api]
                 [--api-auth API_AUTH]
                 [--api-log]
                 [--nowebui]
                 [--ui-debug-mode]
                 [--device-id DEVICE_ID]
                 [--administrator]
                 [--cors-allow-origins CORS_ALLOW_ORIGINS]
                 [--cors-allow-origins-regex CORS_ALLOW_ORIGINS_REGEX]
                 [--tls-keyfile TLS_KEYFILE]
                 [--tls-certfile TLS_CERTFILE]
                 [--disable-tls-verify]
                 [--server-name SERVER_NAME]
                 [--gradio-queue]
                 [--no-gradio-queue]
                 [--skip-version-check]
                 [--no-hashing]
                 [--no-download-sd-model]
                 [--subpath SUBPATH]
                 [--add-stop-route]
                 [--api-server-stop]
                 [--timeout-keep-alive TIMEOUT_KEEP_ALIVE]
                 [--disable-all-extensions]
                 [--disable-extra-extensions]
                 [--skip-load-model-at-start]
                 [--ldsr-models-path LDSR_MODELS_PATH]
                 [--lora-dir LORA_DIR]
                 [--lyco-dir-backcompat LYCO_DIR_BACKCOMPAT]
                 [--scunet-models-path SCUNET_MODELS_PATH]
                 [--swinir-models-path SWINIR_MODELS_PATH]

Last updated