SDXL - text to image

Stable Diffusion

reference

history

VersionRelease DateNotes

SD 1.4

August 2022

Released as open source

SD 1.5

October 2022

Became the standard for many custom models

SD 2.0

November 2022

Updated to V2.1 in December 2022

SDXL 1.0

July 2023

Latest version of Stable Diffusion

ModelNative Resolution

SD 1.5

512x512, 768x768, 512x768, 768x512, 640x832, 832x640

SDXL 1.0

1024x1024, 896x1152, 1152x896, 832x1216, 1216x832, 768x1344, 1344x768, 640x1536, 1526x640

๋ชฉํ‘œ

API๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ…์ŠคํŠธ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค์–ด๋ณด๋Š” ๋ถ€๋ถ„์„ ๋จผ์ € ์‚ดํŽด๋ณด๊ณ  ์ดํ›„์—๋Š” ๋กœ์ปฌ์—์„œ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด๋ณด์ž.

stability.ai API ์‚ฌ์šฉ

https://platform.stability.ai/account/keys ์—ฌ๊ธฐ์—์„œ api์ƒ์„ฑ. api๋ฅผ ๋งŒ๋“ค์–ด์„œ curl๋กœ ์ด์šฉํ•˜๋ฉด๋œ๋‹ค.

https://clipdrop.co/stable-diffusion-turbo ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

https://playground.com ์ด๋Ÿฐ๊ฒƒ๋„ ์ž‡๋Š”๋ฐ ์ด๋Ÿฐ๊ฑด dreamstudio์˜ api๋ฅผ ์“ฐ๋Š”๊ฑฐ๊ฐ™์€๋ฐ? apiํ‚ค๋ฅผ ์ œ๊ณตํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. email๋กœ ๋งŒ ํ•˜๋ผ๊ณ  ํ•˜๋Š”๋ฐ ์•„๋ฌด๋ž˜๋„ ๋น„์šฉ์ด ๋“ค์–ด๊ฐ€๋Š”๋“ฏ. 500์žฅ ๋ฌด๋ฃŒ๋ผ๊ณ  ํ•ด์„œ ์จ๋ณผ๋ ค๊ณ  ํ–‡๋Š”๋ฐ ์•ˆ๋ ๋“ฏ.

billing

https://platform.stability.ai/docs/getting-started/credits-and-billing

https://platform.stability.ai/pricing

ํฌ๋ ˆ๋”ง ๊ฐ€๊ฒฉ์€ 1,000ํฌ๋ ˆ๋”ง๋‹น 10๋‹ฌ๋Ÿฌ๋กœ, ์•ฝ 5,000๊ฐœ์˜ SDXL 1.0 ์ด๋ฏธ์ง€์— ์ถฉ๋ถ„ํ•œ ํฌ๋ ˆ๋”ง์ž…๋‹ˆ๋‹ค.

10๋‹ฌ๋Ÿฌ์— 5000๊ฐœ. ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ฐ”๊ฟ”๊ฐ€๋ฉด์„œ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•œ๋‹ฌ์— 100๋‹ฌ๋Ÿฌ ์ •๋„ ์ƒ๊ฐํ•˜๋ฉด๋ ๊ฑฐ๊ฐ™๋‹ค.

ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž˜์จ์„œ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ์ค„์ด๋ฉด ์ข€ ๋ ๋“ฏ.

prompt guide

https://dreamstudio.ai/prompt-guide ๊ฐ€์ด๋“œ๋„ ๋ด๋„ ๋ ๊ฑฐ๊ฐ™๋‹ค.

https://platform.stability.ai/docs/api-reference#tag/v1generation/operation/textToImage

api๋ฅผ ์“ฐ๋ฉด ๋˜๋Š”๊ฑฐ๊ฐ™์€๋ฐ curl๋กœ ๊ทธ๋ƒฅ ๋‚ ๋ ค๋„ ๋˜๊ณ 

sdxl on local server

๋กœ์ปฌ์—์„œ ์‹คํ–‰ํ•ด๋ณด์ž.

pytorch๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

Dockerfile ์ƒ์„ฑ

vi Dockerfile
```

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

WORKDIR /app

RUN apt update

RUN python -m pip install diffusers[torch] transformers accelerate --upgrade

docker-compose.yaml ์ƒ์„ฑ

vi docker-compose.yaml
version: '3.8'
services:
  sdxl:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: sdxl
    command: ['sleep', '6000']
    restart: unless-stopped
    ports:
      - 8000:8000
    volumes:
      - ./app:/app/
    deploy:
      resources:
        reservations:
          devices:
            - driver: 'nvidia'
              capabilities: [gpu]
              count: all
docker-compose up -d --build
docker exec -it sdxl bash

ํ™•์ธ

์ด์ œ docker์—์„œ pytorch๊ฐ€ ๋˜๋Š”๊ฑฐ ํ™•์ธํ•ด๋ณด์ž.

import torch
print(torch.__version__)

๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋ฉด ์„ฑ๊ณต์ด๋‹ค.

huggingface์—์„œ ์˜คํ”ˆ์†Œ์Šค๋กœ ์ œ๊ณตํ•˜๋Š” ๋‹ค์Œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰ํ•ด๋ณด์ž. https://github.com/huggingface/diffusers

์‚ฌ์šฉ๋ฒ•์€ ๋‹ค์Œ ์ฐธ์กฐ : https://huggingface.co/docs/diffusers/tutorials/tutorial_overview

https://huggingface.co/stabilityai

๋งŽ์€ ๋ชจ๋ธ์ด ์ž‡๊ณ  ๋‚˜๋Š” stabilityai/sdxl-turbo ์ด๊ฑธ ์ด์šฉํ•˜๋ ค๊ณ ํ•จ.

A pipeline is a quick and easy way to run a model for inference, requiring no more than four lines of code to generate an image:

ํŒŒ์ดํ”„๋ผ์ธ์€ ์ถ”๋ก ์„ ์œ„ํ•ด ๋ชจ๋ธ์„ ์‹คํ–‰ํ•˜๋Š” ๋น ๋ฅด๊ณ  ์‰ฌ์šด ๋ฐฉ๋ฒ•์œผ๋กœ, ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ์ฝ”๋“œ๊ฐ€ 4์ค„ ์ด์ƒ ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค:

from diffusers import DiffusionPipeline
import torch

pipeline = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16)
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]
image.save("test.png")

๊ทธ๋ฆผ์ด ์ด์ œ ์ƒ์„ฑ์ด ๋œ๋‹ค.

์‰ฝ๋‹ค.

sd-turbo ๋ชจ๋ธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ์ด๋‹ค

from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained(
	"stabilityai/sd-turbo", torch_dtype=torch.float16, variant="fp16"
).to("cuda")
generator = torch.Generator("cuda").manual_seed(31)
image = pipeline("cat riding elephant", generator=generator).images[0]
image.save("test.png")

Last updated