svjack's picture
Upload 1392 files
43b7e92 verified
|
raw
history blame
23.4 kB

ํŒŒ์ดํ”„๋ผ์ธ, ๋ชจ๋ธ, ์Šค์ผ€์ค„๋Ÿฌ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

๊ธฐ๋ณธ์ ์œผ๋กœ diffusion ๋ชจ๋ธ์€ ๋‹ค์–‘ํ•œ ์ปดํฌ๋„ŒํŠธ๋“ค(๋ชจ๋ธ, ํ† ํฌ๋‚˜์ด์ €, ์Šค์ผ€์ค„๋Ÿฌ) ๊ฐ„์˜ ๋ณต์žกํ•œ ์ƒํ˜ธ์ž‘์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋””ํ“จ์ €์Šค(Diffusers)๋Š” ์ด๋Ÿฌํ•œ diffusion ๋ชจ๋ธ์„ ๋ณด๋‹ค ์‰ฝ๊ณ  ๊ฐ„ํŽธํ•œ API๋กœ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค. [DiffusionPipeline]์€ diffusion ๋ชจ๋ธ์ด ๊ฐ–๋Š” ๋ณต์žก์„ฑ์„ ํ•˜๋‚˜์˜ ํŒŒ์ดํ”„๋ผ์ธ API๋กœ ํ†ตํ•ฉํ•˜๊ณ , ๋™์‹œ์— ์ด๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ํƒœ์Šคํฌ์— ๋งž์ถฐ ์œ ์—ฐํ•˜๊ฒŒ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

diffusion ๋ชจ๋ธ์˜ ํ›ˆ๋ จ๊ณผ ์ถ”๋ก ์— ํ•„์š”ํ•œ ๋ชจ๋“  ๊ฒƒ์€ [DiffusionPipeline.from_pretrained] ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (์ด ๋ง์˜ ์˜๋ฏธ๋Š” ๋‹ค์Œ ๋‹จ๋ฝ์—์„œ ๋ณด๋‹ค ์ž์„ธํ•˜๊ฒŒ ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.)

์ด ๋ฌธ์„œ์—์„œ๋Š” ์„ค๋ช…ํ•  ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ํ—ˆ๋ธŒ๋ฅผ ํ†ตํ•ด ํ˜น์€ ๋กœ์ปฌ๋กœ ํŒŒ์ดํ”„๋ผ์ธ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฒ•

  • ํŒŒ์ดํ”„๋ผ์ธ์— ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ์ ์šฉํ•˜๋Š” ๋ฒ•

  • ์˜ค๋ฆฌ์ง€๋„ ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ์•„๋‹Œ variant๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฒ• (variant๋ž€ ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ •๋œ fp32๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๋ถ€๋™ ์†Œ์ˆ˜์  ํƒ€์ž…(์˜ˆ: fp16)์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ Non-EMA ๊ฐ€์ค‘์น˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฒดํฌํฌ์ธํŠธ๋“ค์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.)

  • ๋ชจ๋ธ๊ณผ ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฒ•

Diffusion ํŒŒ์ดํ”„๋ผ์ธ

๐Ÿ’ก [DiffusionPipeline] ํด๋ž˜์Šค๊ฐ€ ๋™์ž‘ํ•˜๋Š” ๋ฐฉ์‹์— ๋ณด๋‹ค ์ž์„ธํ•œ ๋‚ด์šฉ์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด, DiffusionPipeline explained ์„น์…˜์„ ํ™•์ธํ•ด๋ณด์„ธ์š”.

[DiffusionPipeline] ํด๋ž˜์Šค๋Š” diffusion ๋ชจ๋ธ์„ ํ—ˆ๋ธŒ๋กœ๋ถ€ํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฐ€์žฅ ์‹ฌํ”Œํ•˜๋ฉด์„œ ๋ณดํŽธ์ ์ธ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. [DiffusionPipeline.from_pretrained] ๋ฉ”์„œ๋“œ๋Š” ์ ํ•ฉํ•œ ํŒŒ์ดํ”„๋ผ์ธ ํด๋ž˜์Šค๋ฅผ ์ž๋™์œผ๋กœ ํƒ์ง€ํ•˜๊ณ , ํ•„์š”ํ•œ ๊ตฌ์„ฑ์š”์†Œ(configuration)์™€ ๊ฐ€์ค‘์น˜(weight) ํŒŒ์ผ๋“ค์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์บ์‹ฑํ•œ ๋‹ค์Œ, ํ•ด๋‹น ํŒŒ์ดํ”„๋ผ์ธ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
pipe = DiffusionPipeline.from_pretrained(repo_id)

๋ฌผ๋ก  [DiffusionPipeline] ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ๋ช…์‹œ์ ์œผ๋กœ ์ง์ ‘ ํ•ด๋‹น ํŒŒ์ดํ”„๋ผ์ธ ํด๋ž˜์Šค๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ์˜ˆ์‹œ ์ฝ”๋“œ๋Š” ์œ„ ์˜ˆ์‹œ์™€ ๋™์ผํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

from diffusers import StableDiffusionPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(repo_id)

CompVis/stable-diffusion-v1-4์ด๋‚˜ runwayml/stable-diffusion-v1-5 ๊ฐ™์€ ์ฒดํฌํฌ์ธํŠธ๋“ค์˜ ๊ฒฝ์šฐ, ํ•˜๋‚˜ ์ด์ƒ์˜ ๋‹ค์–‘ํ•œ ํƒœ์Šคํฌ์— ํ™œ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (์˜ˆ๋ฅผ ๋“ค์–ด ์œ„์˜ ๋‘ ์ฒดํฌํฌ์ธํŠธ์˜ ๊ฒฝ์šฐ, text-to-image์™€ image-to-image์— ๋ชจ๋‘ ํ™œ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.) ๋งŒ์•ฝ ์ด๋Ÿฌํ•œ ์ฒดํฌํฌ์ธํŠธ๋“ค์„ ๊ธฐ๋ณธ ์„ค์ • ํƒœ์Šคํฌ๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ํƒœ์Šคํฌ์— ํ™œ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, ํ•ด๋‹น ํƒœ์Šคํฌ์— ๋Œ€์‘๋˜๋Š” ํŒŒ์ดํ”„๋ผ์ธ(task-specific pipeline)์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

from diffusers import StableDiffusionImg2ImgPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(repo_id)

๋กœ์ปฌ ํŒŒ์ดํ”„๋ผ์ธ

ํŒŒ์ดํ”„๋ผ์ธ์„ ๋กœ์ปฌ๋กœ ๋ถˆ๋Ÿฌ์˜ค๊ณ ์ž ํ•œ๋‹ค๋ฉด, git-lfs๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง์ ‘ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋กœ์ปฌ ๋””์Šคํฌ์— ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ./stable-diffusion-v1-5๋ž€ ์ด๋ฆ„์œผ๋กœ ํด๋”๊ฐ€ ๋กœ์ปฌ๋””์Šคํฌ์— ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

git lfs install
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5

๊ทธ๋Ÿฐ ๋‹ค์Œ ํ•ด๋‹น ๋กœ์ปฌ ๊ฒฝ๋กœ๋ฅผ [~DiffusionPipeline.from_pretrained] ๋ฉ”์„œ๋“œ์— ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

repo_id = "./stable-diffusion-v1-5"
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id)

์œ„์˜ ์˜ˆ์‹œ์ฝ”๋“œ์ฒ˜๋Ÿผ ๋งŒ์•ฝ repo_id๊ฐ€ ๋กœ์ปฌ ํŒจ์Šค(local path)๋ผ๋ฉด, [~DiffusionPipeline.from_pretrained] ๋ฉ”์„œ๋“œ๋Š” ์ด๋ฅผ ์ž๋™์œผ๋กœ ๊ฐ์ง€ํ•˜์—ฌ ํ—ˆ๋ธŒ์—์„œ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋กœ์ปฌ ๋””์Šคํฌ์— ์ €์žฅ๋œ ํŒŒ์ดํ”„๋ผ์ธ ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ์ตœ์‹  ๋ฒ„์ „์ด ์•„๋‹ ๊ฒฝ์šฐ์—๋„, ์ตœ์‹  ๋ฒ„์ „์„ ๋‹ค์šด๋กœ๋“œํ•˜์ง€ ์•Š๊ณ  ๊ธฐ์กด ๋กœ์ปฌ ๋””์Šคํฌ์— ์ €์žฅ๋œ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

ํŒŒ์ดํ”„๋ผ์ธ ๋‚ด๋ถ€์˜ ์ปดํฌ๋„ŒํŠธ ๊ต์ฒดํ•˜๊ธฐ

ํŒŒ์ดํ”„๋ผ์ธ ๋‚ด๋ถ€์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ํ˜ธํ™˜ ๊ฐ€๋Šฅํ•œ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ๋กœ ๊ต์ฒด๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์™€ ๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ ๊ต์ฒด๊ฐ€ ์ค‘์š”ํ•œ ์ด์œ ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์–ด๋–ค ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ๊ฐ€๋Š” ์ƒ์„ฑ์†๋„์™€ ์ƒ์„ฑํ’ˆ์งˆ ๊ฐ„์˜ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„๋ฅผ ์ •์˜ํ•˜๋Š” ์ค‘์š”ํ•œ ์š”์†Œ์ž…๋‹ˆ๋‹ค.
  • diffusion ๋ชจ๋ธ ๋‚ด๋ถ€์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ฐ๊ฐ ๋…๋ฆฝ์ ์œผ๋กœ ํ›ˆ๋ จ๋˜๊ธฐ ๋•Œ๋ฌธ์—, ๋” ์ข‹์€ ์„ฑ๋Šฅ์„ ๋ณด์—ฌ์ฃผ๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ทธ๊ฑธ๋กœ ๊ต์ฒดํ•˜๋Š” ์‹์œผ๋กœ ์„ฑ๋Šฅ์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํŒŒ์ธ ํŠœ๋‹ ๋‹จ๊ณ„์—์„œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ UNet ํ˜น์€ ํ…์ŠคํŠธ ์ธ์ฝ”๋”์™€ ๊ฐ™์€ ์ผ๋ถ€ ์ปดํฌ๋„ŒํŠธ๋“ค๋งŒ ํ›ˆ๋ จํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์–ด๋–ค ์Šค์ผ€์ค„๋Ÿฌ๋“ค์ด ํ˜ธํ™˜๊ฐ€๋Šฅํ•œ์ง€๋Š” compatibles ์†์„ฑ์„ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id)
stable_diffusion.scheduler.compatibles

์ด๋ฒˆ์—๋Š” [SchedulerMixin.from_pretrained] ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ, ๊ธฐ์กด ๊ธฐ๋ณธ ์Šค์ผ€์ค„๋Ÿฌ์˜€๋˜ [PNDMScheduler]๋ฅผ ๋ณด๋‹ค ์šฐ์ˆ˜ํ•œ ์„ฑ๋Šฅ์˜ [EulerDiscreteScheduler]๋กœ ๋ฐ”๊ฟ”๋ด…์‹œ๋‹ค. ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๋กœ๋“œํ•  ๋•Œ๋Š” subfolder ์ธ์ž๋ฅผ ํ†ตํ•ด, ํ•ด๋‹น ํŒŒ์ดํ”„๋ผ์ธ์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์Šค์ผ€์ค„๋Ÿฌ์— ๊ด€ํ•œ ํ•˜์œ„ํด๋”๋ฅผ ๋ช…์‹œํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ ๋‹ค์Œ ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑํ•œ [EulerDiscreteScheduler] ์ธ์Šคํ„ด์Šค๋ฅผ [DiffusionPipeline]์˜ scheduler ์ธ์ž์— ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline, EulerDiscreteScheduler, DPMSolverMultistepScheduler

repo_id = "runwayml/stable-diffusion-v1-5"

scheduler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")

stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, scheduler=scheduler)

์„ธ์ดํ”„ํ‹ฐ ์ฒด์ปค

์Šคํ…Œ์ด๋ธ” diffusion๊ณผ ๊ฐ™์€ diffusion ๋ชจ๋ธ๋“ค์€ ์œ ํ•ดํ•œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์˜ˆ๋ฐฉํ•˜๊ธฐ ์œ„ํ•ด ๋””ํ“จ์ €์Šค๋Š” ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์˜ ์œ ํ•ด์„ฑ์„ ํŒ๋‹จํ•˜๋Š” ์„ธ์ดํ”„ํ‹ฐ ์ฒด์ปค(safety checker) ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์„ธ์ดํ”„ํ‹ฐ ์ฒด์ปค์˜ ์‚ฌ์šฉ์„ ์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, safety_checker ์ธ์ž์— None์„ ์ „๋‹ฌํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
stable_diffusion = DiffusionPipeline.from_pretrained(repo_id, safety_checker=None)

์ปดํฌ๋„ŒํŠธ ์žฌ์‚ฌ์šฉ

๋ณต์ˆ˜์˜ ํŒŒ์ดํ”„๋ผ์ธ์— ๋™์ผํ•œ ๋ชจ๋ธ์ด ๋ฐ˜๋ณต์ ์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ๊ตณ์ด ํ•ด๋‹น ๋ชจ๋ธ์˜ ๋™์ผํ•œ ๊ฐ€์ค‘์น˜๋ฅผ ์ค‘๋ณต์œผ๋กœ RAM์— ๋ถˆ๋Ÿฌ์˜ฌ ํ•„์š”๋Š” ์—†์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. [~DiffusionPipeline.components] ์†์„ฑ์„ ํ†ตํ•ด ํŒŒ์ดํ”„๋ผ์ธ ๋‚ด๋ถ€์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋ฒˆ ๋‹จ๋ฝ์—์„œ๋Š” ์ด๋ฅผ ํ†ตํ•ด ๋™์ผํ•œ ๋ชจ๋ธ ๊ฐ€์ค‘์น˜๋ฅผ RAM์— ์ค‘๋ณต์œผ๋กœ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline

model_id = "runwayml/stable-diffusion-v1-5"
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id)

components = stable_diffusion_txt2img.components

๊ทธ ๋‹ค์Œ ์œ„ ์˜ˆ์‹œ ์ฝ”๋“œ์—์„œ ์„ ์–ธํ•œ components ๋ณ€์ˆ˜๋ฅผ ๋‹ค๋ฅธ ํŒŒ์ดํ”„๋ผ์ธ์— ์ „๋‹ฌํ•จ์œผ๋กœ์จ, ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์ค‘๋ณต์œผ๋กœ RAM์— ๋กœ๋”ฉํ•˜์ง€ ์•Š๊ณ , ๋™์ผํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(**components)

๋ฌผ๋ก  ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ๋”ฐ๋กœ ๋”ฐ๋กœ ํŒŒ์ดํ”„๋ผ์ธ์— ์ „๋‹ฌํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด stable_diffusion_txt2img ํŒŒ์ดํ”„๋ผ์ธ ์•ˆ์˜ ์ปดํฌ๋„ŒํŠธ๋“ค ๊ฐ€์šด๋ฐ์„œ ์„ธ์ดํ”„ํ‹ฐ ์ฒด์ปค(safety_checker)์™€ ํ”ผ์ณ ์ต์ŠคํŠธ๋ž™ํ„ฐ(feature_extractor)๋ฅผ ์ œ์™ธํ•œ ์ปดํฌ๋„ŒํŠธ๋“ค๋งŒ stable_diffusion_img2img ํŒŒ์ดํ”„๋ผ์ธ์—์„œ ์žฌ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹ ์—ญ์‹œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline

model_id = "runwayml/stable-diffusion-v1-5"
stable_diffusion_txt2img = StableDiffusionPipeline.from_pretrained(model_id)
stable_diffusion_img2img = StableDiffusionImg2ImgPipeline(
    vae=stable_diffusion_txt2img.vae,
    text_encoder=stable_diffusion_txt2img.text_encoder,
    tokenizer=stable_diffusion_txt2img.tokenizer,
    unet=stable_diffusion_txt2img.unet,
    scheduler=stable_diffusion_txt2img.scheduler,
    safety_checker=None,
    feature_extractor=None,
    requires_safety_checker=False,
)

Checkpoint variants

Variant๋ž€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฒดํฌํฌ์ธํŠธ๋“ค์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

  • torch.float16๊ณผ ๊ฐ™์ด ์ •๋ฐ€๋„๋Š” ๋” ๋‚ฎ์ง€๋งŒ, ์šฉ๋Ÿ‰ ์—ญ์‹œ ๋” ์ž‘์€ ๋ถ€๋™์†Œ์ˆ˜์  ํƒ€์ž…์˜ ๊ฐ€์ค‘์น˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฒดํฌํฌ์ธํŠธ. (๋‹ค๋งŒ ์ด์™€ ๊ฐ™์€ variant์˜ ๊ฒฝ์šฐ, ์ถ”๊ฐ€์ ์ธ ํ›ˆ๋ จ๊ณผ CPUํ™˜๊ฒฝ์—์„œ์˜ ๊ตฌ๋™์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.)
  • Non-EMA ๊ฐ€์ค‘์น˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฒดํฌํฌ์ธํŠธ. (Non-EMA ๊ฐ€์ค‘์น˜์˜ ๊ฒฝ์šฐ, ํŒŒ์ธ ํŠœ๋‹ ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๊ถŒ์žฅ๋˜๋Š”๋ฐ, ์ถ”๋ก  ๋‹จ๊ณ„์—์„  ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ๊ถŒ์žฅ๋ฉ๋‹ˆ๋‹ค.)

๐Ÿ’ก ๋ชจ๋ธ ๊ตฌ์กฐ๋Š” ๋™์ผํ•˜์ง€๋งŒ ์„œ๋กœ ๋‹ค๋ฅธ ํ•™์Šต ํ™˜๊ฒฝ์—์„œ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ์…‹์œผ๋กœ ํ•™์Šต๋œ ์ฒดํฌํฌ์ธํŠธ๋“ค์ด ์žˆ์„ ๊ฒฝ์šฐ, ํ•ด๋‹น ์ฒดํฌํฌ์ธํŠธ๋“ค์€ variant ๋‹จ๊ณ„๊ฐ€ ์•„๋‹Œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ๋‹จ๊ณ„์—์„œ ๋ถ„๋ฆฌ๋˜์–ด ๊ด€๋ฆฌ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (์ฆ‰, ํ•ด๋‹น ์ฒดํฌํฌ์ธํŠธ๋“ค์€ ์„œ๋กœ ๋‹ค๋ฅธ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ๋”ฐ๋กœ ๊ด€๋ฆฌ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ: [stable-diffusion-v1-4], [stable-diffusion-v1-5]).

checkpoint type weight name argument for loading weights
original diffusion_pytorch_model.bin
floating point diffusion_pytorch_model.fp16.bin variant, torch_dtype
non-EMA diffusion_pytorch_model.non_ema.bin variant

variant๋ฅผ ๋กœ๋“œํ•  ๋•Œ 2๊ฐœ์˜ ์ค‘์š”ํ•œ argument๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  • torch_dtype์€ ๋ถˆ๋Ÿฌ์˜ฌ ์ฒดํฌํฌ์ธํŠธ์˜ ๋ถ€๋™์†Œ์ˆ˜์ ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด torch_dtype=torch.float16์„ ๋ช…์‹œํ•จ์œผ๋กœ์จ ๊ฐ€์ค‘์น˜์˜ ๋ถ€๋™์†Œ์ˆ˜์  ํƒ€์ž…์„ fl16์œผ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (๋งŒ์•ฝ ๋”ฐ๋กœ ์„ค์ •ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ fp32 ํƒ€์ž…์˜ ๊ฐ€์ค‘์น˜๊ฐ€ ๋กœ๋”ฉ๋ฉ๋‹ˆ๋‹ค.) ๋˜ํ•œ variant ์ธ์ž๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์€ ์ฑ„๋กœ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์˜จ ๋‹ค์Œ, ํ•ด๋‹น ์ฒดํฌํฌ์ธํŠธ๋ฅผ torch_dtype=torch.float16 ์ธ์ž๋ฅผ ํ†ตํ•ด fp16 ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ ์—ญ์‹œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ •๋œ fp32 ๊ฐ€์ค‘์น˜๊ฐ€ ๋จผ์ € ๋‹ค์šด๋กœ๋“œ๋˜๊ณ , ํ•ด๋‹น ๊ฐ€์ค‘์น˜๋“ค์„ ๋ถˆ๋Ÿฌ์˜จ ๋‹ค์Œ fp16 ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • variant ์ธ์ž๋Š” ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์–ด๋–ค variant๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๊ฒƒ์ธ๊ฐ€๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€๋ น diffusers/stable-diffusion-variants ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ๋ถ€ํ„ฐ non_ema ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ ์ž ํ•œ๋‹ค๋ฉด, variant="non_ema" ์ธ์ž๋ฅผ ์ „๋‹ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
from diffusers import DiffusionPipeline

# load fp16 variant
stable_diffusion = DiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5", variant="fp16", torch_dtype=torch.float16
)
# load non_ema variant
stable_diffusion = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", variant="non_ema")

๋‹ค๋ฅธ ๋ถ€๋™์†Œ์ˆ˜์  ํƒ€์ž…์˜ ๊ฐ€์ค‘์น˜ ํ˜น์€ non-EMA ๊ฐ€์ค‘์น˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, [DiffusionPipeline.save_pretrained] ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ, ์ด ๋•Œ variant ์ธ์ž๋ฅผ ๋ช…์‹œํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์›๋ž˜์˜ ์ฒดํฌํฌ์ธํŠธ์™€ ๋™์ผํ•œ ํด๋”์— variant๋ฅผ ์ €์žฅํ•ด์•ผ ํ•˜๋ฉฐ, ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋™์ผํ•œ ํด๋”์—์„œ ์˜ค๋ฆฌ์ง€๋„ ์ฒดํฌํฌ์ธํŠธ๊ณผ variant๋ฅผ ๋ชจ๋‘ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

# save as fp16 variant
stable_diffusion.save_pretrained("runwayml/stable-diffusion-v1-5", variant="fp16")
# save as non-ema variant
stable_diffusion.save_pretrained("runwayml/stable-diffusion-v1-5", variant="non_ema")

๋งŒ์•ฝ variant๋ฅผ ๊ธฐ์กด ํด๋”์— ์ €์žฅํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, variant ์ธ์ž๋ฅผ ๋ฐ˜๋“œ์‹œ ๋ช…์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์›๋ž˜์˜ ์˜ค๋ฆฌ์ง€๋„ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๊ฒŒ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

# ๐Ÿ‘Ž this won't work
stable_diffusion = DiffusionPipeline.from_pretrained("./stable-diffusion-v1-5", torch_dtype=torch.float16)
# ๐Ÿ‘ this works
stable_diffusion = DiffusionPipeline.from_pretrained(
    "./stable-diffusion-v1-5", variant="fp16", torch_dtype=torch.float16
)

๋ชจ๋ธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

๋ชจ๋ธ๋“ค์€ [ModelMixin.from_pretrained] ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ ๋ชจ๋ธ ๊ฐ€์ค‘์น˜ ํŒŒ์ผ๊ณผ ์„ค์ • ํŒŒ์ผ(configurations)์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์บ์‹ฑํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด๋Ÿฌํ•œ ํŒŒ์ผ๋“ค์ด ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ๋กœ์ปฌ ์บ์‹œ์— ์ €์žฅ๋˜์–ด ์žˆ๋‹ค๋ฉด, [ModelMixin.from_pretrained]๋Š” ๊ตณ์ด ํ•ด๋‹น ํŒŒ์ผ๋“ค์„ ๋‹ค์‹œ ๋‹ค์šด๋กœ๋“œํ•˜์ง€ ์•Š์œผ๋ฉฐ, ๊ทธ์ € ์บ์‹œ์— ์žˆ๋Š” ์ตœ์‹  ํŒŒ์ผ๋“ค์„ ์žฌ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋ธ์€ subfolder ์ธ์ž์— ๋ช…์‹œ๋œ ํ•˜์œ„ ํด๋”๋กœ๋ถ€ํ„ฐ ๋กœ๋“œ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด runwayml/stable-diffusion-v1-5์˜ UNet ๋ชจ๋ธ์˜ ๊ฐ€์ค‘์น˜๋Š” unet ํด๋”์— ์ €์žฅ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

from diffusers import UNet2DConditionModel

repo_id = "runwayml/stable-diffusion-v1-5"
model = UNet2DConditionModel.from_pretrained(repo_id, subfolder="unet")

ํ˜น์€ ํ•ด๋‹น ๋ชจ๋ธ์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ๋ถ€ํ„ฐ ๋‹ค์ด๋ ‰ํŠธ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ ์—ญ์‹œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

from diffusers import UNet2DModel

repo_id = "google/ddpm-cifar10-32"
model = UNet2DModel.from_pretrained(repo_id)

๋˜ํ•œ ์•ž์„œ ๋ดค๋˜ variant ์ธ์ž๋ฅผ ๋ช…์‹œํ•จ์œผ๋กœ์จ, Non-EMA๋‚˜ fp16์˜ ๊ฐ€์ค‘์น˜๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ ์—ญ์‹œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

from diffusers import UNet2DConditionModel

model = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet", variant="non-ema")
model.save_pretrained("./local-unet", variant="non-ema")

์Šค์ผ€์ค„๋Ÿฌ

์Šค์ผ€์ค„๋Ÿฌ๋“ค์€ [SchedulerMixin.from_pretrained] ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋ธ๊ณผ ๋‹ฌ๋ฆฌ ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๋ณ„๋„์˜ ๊ฐ€์ค‘์น˜๋ฅผ ๊ฐ–์ง€ ์•Š์œผ๋ฉฐ, ๋”ฐ๋ผ์„œ ๋‹น์—ฐํžˆ ๋ณ„๋„์˜ ํ•™์Šต๊ณผ์ •์„ ์š”๊ตฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์Šค์ผ€์ค„๋Ÿฌ๋“ค์€ (ํ•ด๋‹น ์Šค์ผ€์ค„๋Ÿฌ ํ•˜์œ„ํด๋”์˜) configration ํŒŒ์ผ์„ ํ†ตํ•ด ์ •์˜๋ฉ๋‹ˆ๋‹ค.

์—ฌ๋Ÿฌ๊ฐœ์˜ ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๋ถˆ๋Ÿฌ์˜จ๋‹ค๊ณ  ํ•ด์„œ ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์†Œ๋ชจํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋ฉฐ, ๋‹ค์–‘ํ•œ ์Šค์ผ€์ค„๋Ÿฌ๋“ค์— ๋™์ผํ•œ ์Šค์ผ€์ค„๋Ÿฌ configration์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ ์—ญ์‹œ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ์˜ˆ์‹œ ์ฝ”๋“œ์—์„œ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์Šค์ผ€์ค„๋Ÿฌ๋“ค์€ ๋ชจ๋‘ [StableDiffusionPipeline]๊ณผ ํ˜ธํ™˜๋˜๋Š”๋ฐ, ์ด๋Š” ๊ณง ํ•ด๋‹น ์Šค์ผ€์ค„๋Ÿฌ๋“ค์— ๋™์ผํ•œ ์Šค์ผ€์ค„๋Ÿฌ configration ํŒŒ์ผ์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

from diffusers import StableDiffusionPipeline
from diffusers import (
    DDPMScheduler,
    DDIMScheduler,
    PNDMScheduler,
    LMSDiscreteScheduler,
    EulerDiscreteScheduler,
    EulerAncestralDiscreteScheduler,
    DPMSolverMultistepScheduler,
)

repo_id = "runwayml/stable-diffusion-v1-5"

ddpm = DDPMScheduler.from_pretrained(repo_id, subfolder="scheduler")
ddim = DDIMScheduler.from_pretrained(repo_id, subfolder="scheduler")
pndm = PNDMScheduler.from_pretrained(repo_id, subfolder="scheduler")
lms = LMSDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
euler_anc = EulerAncestralDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
euler = EulerDiscreteScheduler.from_pretrained(repo_id, subfolder="scheduler")
dpm = DPMSolverMultistepScheduler.from_pretrained(repo_id, subfolder="scheduler")

# replace `dpm` with any of `ddpm`, `ddim`, `pndm`, `lms`, `euler_anc`, `euler`
pipeline = StableDiffusionPipeline.from_pretrained(repo_id, scheduler=dpm)

DiffusionPipeline์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ธฐ

ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ๋กœ์„œ [DiffusionPipeline.from_pretrained]์€ 2๊ฐ€์ง€๋ฅผ ๋‹ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

  • ์ฒซ์งธ๋กœ, from_pretrained ๋ฉ”์„œ๋“œ๋Š” ์ตœ์‹  ๋ฒ„์ „์˜ ํŒŒ์ดํ”„๋ผ์ธ์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ , ์บ์‹œ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฏธ ๋กœ์ปฌ ์บ์‹œ์— ์ตœ์‹  ๋ฒ„์ „์˜ ํŒŒ์ดํ”„๋ผ์ธ์ด ์ €์žฅ๋˜์–ด ์žˆ๋‹ค๋ฉด, [DiffusionPipeline.from_pretrained]์€ ํ•ด๋‹น ํŒŒ์ผ๋“ค์„ ๋‹ค์‹œ ๋‹ค์šด๋กœ๋“œํ•˜์ง€ ์•Š๊ณ , ๋กœ์ปฌ ์บ์‹œ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ํŒŒ์ดํ”„๋ผ์ธ์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
  • model_index.json ํŒŒ์ผ์„ ํ†ตํ•ด ์ฒดํฌํฌ์ธํŠธ์— ๋Œ€์‘๋˜๋Š” ์ ํ•ฉํ•œ ํŒŒ์ดํ”„๋ผ์ธ ํด๋ž˜์Šค๋กœ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.

ํŒŒ์ดํ”„๋ผ์ธ์˜ ํด๋” ๊ตฌ์กฐ๋Š” ํ•ด๋‹น ํŒŒ์ดํ”„๋ผ์ธ ํด๋ž˜์Šค์˜ ๊ตฌ์กฐ์™€ ์ง์ ‘์ ์œผ๋กœ ์ผ์น˜ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด [StableDiffusionPipeline] ํด๋ž˜์Šค๋Š” runwayml/stable-diffusion-v1-5 ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์™€ ๋Œ€์‘๋˜๋Š” ๊ตฌ์กฐ๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

from diffusers import DiffusionPipeline

repo_id = "runwayml/stable-diffusion-v1-5"
pipeline = DiffusionPipeline.from_pretrained(repo_id)
print(pipeline)

์œ„์˜ ์ฝ”๋“œ ์ถœ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด, pipeline์€ [StableDiffusionPipeline]์˜ ์ธ์Šคํ„ด์Šค์ด๋ฉฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ด 7๊ฐœ์˜ ์ปดํฌ๋„ŒํŠธ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • "feature_extractor": [~transformers.CLIPFeatureExtractor]์˜ ์ธ์Šคํ„ด์Šค
  • "safety_checker": ์œ ํ•ดํ•œ ์ปจํ…์ธ ๋ฅผ ์Šคํฌ๋ฆฌ๋‹ํ•˜๊ธฐ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ
  • "scheduler": [PNDMScheduler]์˜ ์ธ์Šคํ„ด์Šค
  • "text_encoder": [~transformers.CLIPTextModel]์˜ ์ธ์Šคํ„ด์Šค
  • "tokenizer": a [~transformers.CLIPTokenizer]์˜ ์ธ์Šคํ„ด์Šค
  • "unet": [UNet2DConditionModel]์˜ ์ธ์Šคํ„ด์Šค
  • "vae" [AutoencoderKL]์˜ ์ธ์Šคํ„ด์Šค
StableDiffusionPipeline {
  "feature_extractor": [
    "transformers",
    "CLIPImageProcessor"
  ],
  "safety_checker": [
    "stable_diffusion",
    "StableDiffusionSafetyChecker"
  ],
  "scheduler": [
    "diffusers",
    "PNDMScheduler"
  ],
  "text_encoder": [
    "transformers",
    "CLIPTextModel"
  ],
  "tokenizer": [
    "transformers",
    "CLIPTokenizer"
  ],
  "unet": [
    "diffusers",
    "UNet2DConditionModel"
  ],
  "vae": [
    "diffusers",
    "AutoencoderKL"
  ]
}

ํŒŒ์ดํ”„๋ผ์ธ ์ธ์Šคํ„ด์Šค์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ runwayml/stable-diffusion-v1-5์˜ ํด๋” ๊ตฌ์กฐ์™€ ๋น„๊ตํ•ด๋ณผ ๊ฒฝ์šฐ, ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋งˆ๋‹ค ๋ณ„๋„์˜ ํด๋”๊ฐ€ ์žˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

.
โ”œโ”€โ”€ feature_extractor
โ”‚   โ””โ”€โ”€ preprocessor_config.json
โ”œโ”€โ”€ model_index.json
โ”œโ”€โ”€ safety_checker
โ”‚   โ”œโ”€โ”€ config.json
โ”‚   โ””โ”€โ”€ pytorch_model.bin
โ”œโ”€โ”€ scheduler
โ”‚   โ””โ”€โ”€ scheduler_config.json
โ”œโ”€โ”€ text_encoder
โ”‚   โ”œโ”€โ”€ config.json
โ”‚   โ””โ”€โ”€ pytorch_model.bin
โ”œโ”€โ”€ tokenizer
โ”‚   โ”œโ”€โ”€ merges.txt
โ”‚   โ”œโ”€โ”€ special_tokens_map.json
โ”‚   โ”œโ”€โ”€ tokenizer_config.json
โ”‚   โ””โ”€โ”€ vocab.json
โ”œโ”€โ”€ unet
โ”‚   โ”œโ”€โ”€ config.json
โ”‚   โ”œโ”€โ”€ diffusion_pytorch_model.bin
โ””โ”€โ”€ vae
    โ”œโ”€โ”€ config.json
    โ”œโ”€โ”€ diffusion_pytorch_model.bin

๋˜ํ•œ ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ํŒŒ์ดํ”„๋ผ์ธ ์ธ์Šคํ„ด์Šค์˜ ์†์„ฑ์œผ๋กœ์จ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

pipeline.tokenizer
CLIPTokenizer(
    name_or_path="/root/.cache/huggingface/hub/models--runwayml--stable-diffusion-v1-5/snapshots/39593d5650112b4cc580433f6b0435385882d819/tokenizer",
    vocab_size=49408,
    model_max_length=77,
    is_fast=False,
    padding_side="right",
    truncation_side="right",
    special_tokens={
        "bos_token": AddedToken("<|startoftext|>", rstrip=False, lstrip=False, single_word=False, normalized=True),
        "eos_token": AddedToken("<|endoftext|>", rstrip=False, lstrip=False, single_word=False, normalized=True),
        "unk_token": AddedToken("<|endoftext|>", rstrip=False, lstrip=False, single_word=False, normalized=True),
        "pad_token": "<|endoftext|>",
    },
)

๋ชจ๋“  ํŒŒ์ดํ”„๋ผ์ธ์€ model_index.json ํŒŒ์ผ์„ ํ†ตํ•ด [DiffusionPipeline]์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

  • _class_name ๋Š” ์–ด๋–ค ํŒŒ์ดํ”„๋ผ์ธ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
  • _diffusers_version๋Š” ์–ด๋–ค ๋ฒ„์ „์˜ ๋””ํ“จ์ €์Šค๋กœ ํŒŒ์ดํ”„๋ผ์ธ ์•ˆ์˜ ๋ชจ๋ธ๋“ค์ด ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€๋ฅผ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.
  • ๊ทธ ๋‹ค์Œ์€ ๊ฐ๊ฐ์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์ด ์–ด๋–ค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์–ด๋–ค ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ๋ ค์ค๋‹ˆ๋‹ค. (์•„๋ž˜ ์˜ˆ์‹œ์—์„œ "feature_extractor" : ["transformers", "CLIPImageProcessor"]์˜ ๊ฒฝ์šฐ, feature_extractor ์ปดํฌ๋„ŒํŠธ๋Š” transformers ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ CLIPImageProcessor ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค์–ด์กŒ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.)
{
  "_class_name": "StableDiffusionPipeline",
  "_diffusers_version": "0.6.0",
  "feature_extractor": [
    "transformers",
    "CLIPImageProcessor"
  ],
  "safety_checker": [
    "stable_diffusion",
    "StableDiffusionSafetyChecker"
  ],
  "scheduler": [
    "diffusers",
    "PNDMScheduler"
  ],
  "text_encoder": [
    "transformers",
    "CLIPTextModel"
  ],
  "tokenizer": [
    "transformers",
    "CLIPTokenizer"
  ],
  "unet": [
    "diffusers",
    "UNet2DConditionModel"
  ],
  "vae": [
    "diffusers",
    "AutoencoderKL"
  ]
}