Buckets:
Metal Performance Shaders (MPS)
Pipelines with a badge indicate a model can take advantage of the MPS backend on Apple silicon devices for faster inference. Feel free to open a Pull Request to add this badge to pipelines that are missing it.
๐ค Diffusers๋ MacOS ๊ธฐ๊ธฐ์ GPU๋ฅผ ํ์ฉํ๊ธฐ ์ํด Metal ํ๋ ์์ํฌ๋ฅผ ์ฌ์ฉํ๋ PyTorch mps ์ฅ์น๋ฅผ ํตํด Apple silicon(M1/M2 ์นฉ)๊ณผ ํธํ๋ฉ๋๋ค. ๋ค์์ด ํ์ํฉ๋๋ค:
- Apple silicon (M1/M2) ํ๋์จ์ด๊ฐ ํ์ฌ๋ macOS ์ปดํจํฐ
- macOS 12.6 ์ด์ (13.0 ์ด์ ๊ถ์ฅ)
- arm64 ๋ฒ์ ์ Python
- PyTorch 2.0 (๊ถ์ฅ) ๋๋ 1.13(
mps์ ์ต์ ์ง์ ๋ฒ์ )
mps ๋ฐฑ์๋๋ PyTorch์ .to() ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ Stable Diffusion ํ์ดํ๋ผ์ธ์ M1 ๋๋ M2 ์ฅ์น๋ก ์ด๋ํฉ๋๋ค:
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# Recommended if your computer has < 64 GB of RAM
pipe.enable_attention_slicing()
prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]
image
PyTorch mps ๋ฐฑ์๋๋
2**32๋ฅผ ์ด๊ณผํ๋ NDArray ํฌ๊ธฐ๋ฅผ ์ง์ํ์ง ์์ต๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ๋ง๋์ จ๋ค๋ฉด ์กฐ์ฌํ ์ ์๋๋ก Issue๋ฅผ ์ด์ด ์ฃผ์ธ์.
PyTorch 1.13๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, ํ์ดํ๋ผ์ธ์ ํ ๋ฒ ๋ ํต๊ณผ์์ผ "prime"ํด์ผ ํฉ๋๋ค. ์ด๋ ์ฒซ ๋ฒ์งธ ์ถ๋ก ํจ์ค๊ฐ ์ดํ ํจ์ค์ ์ฝ๊ฐ ๋ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํ๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ ์์ ์กฐ์น์ ๋๋ค. ์ด ํจ์ค๋ ํ ๋ฒ๋ง ์ํํ๋ฉด ๋๋ฉฐ, ์ถ๋ก ๋จ๊ณ ํ ๋ฒ๋ง ๊ฑฐ์น๋ฉด ๊ฒฐ๊ณผ๋ฅผ ํ๊ธฐํ ์ ์์ต๋๋ค.
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5").to("mps")
pipe.enable_attention_slicing()
prompt = "a photo of an astronaut riding a horse on mars"
# First-time "warmup" pass if PyTorch version is 1.13
+ _ = pipe(prompt, num_inference_steps=1)
# Results match those from the CPU device after the warmup pass.
image = pipe(prompt).images[0]
๋ฌธ์ ํด๊ฒฐ
์ด ์น์
์์๋ mps ๋ฐฑ์๋๋ฅผ ์ฌ์ฉํ ๋ ๋ฐ์ํ๋ ์ผ๋ฐ์ ์ธ ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋์ดํฉ๋๋ค.
Attention ์ฌ๋ผ์ด์ฑ
M1/M2์ ์ฑ๋ฅ์ ๋ฉ๋ชจ๋ฆฌ ์๋ ฅ์ ๋งค์ฐ ๋ฏผ๊ฐํฉ๋๋ค. ์ด๋ฌํ ์ํฉ์ด ๋ฐ์ํ๋ฉด ์์คํ ์ ํ์ํ ๋ ์๋์ผ๋ก ์ค์์ ์ํํ๋ฉฐ, ์ด๋ก ์ธํด ์ฑ๋ฅ์ด ํฌ๊ฒ ์ ํ๋ฉ๋๋ค.
์ด๋ฌํ ๋ฌธ์ ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด ์ถ๋ก ์ค ๋ฉ๋ชจ๋ฆฌ ๋ถ๋ด์ ์ค์ด๊ณ ์ค์์ ๋ง๊ธฐ ์ํด attention slicing์ ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค. ์ปดํจํฐ์ ์์คํ RAM์ด 64GB ๋ฏธ๋ง์ด๊ฑฐ๋ 512ร512 ํฝ์ ๋ณด๋ค ํฐ ๋นํ์ค ํด์๋๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ๊ฒฝ์ฐ ํนํ ์ค์ํฉ๋๋ค. ํ์ดํ๋ผ์ธ์์ enable_attention_slicing() ํจ์๋ฅผ ํธ์ถํ์ธ์:
from diffusers import DiffusionPipeline
import torch
pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16, variant="fp16", use_safetensors=True).to("mps")
pipeline.enable_attention_slicing()
Attention slicing์ ๋น์ฉ์ด ๋์ attention ์ฐ์ฐ์ ํ ๋ฒ์ ์ํํ๋ ๋์ ์ฌ๋ฌ ๋จ๊ณ๋ก ๋๋์ด ์ํํฉ๋๋ค. ๋ฒ์ฉ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์๋ ์ปดํจํฐ์์๋ ์ผ๋ฐ์ ์ผ๋ก ์ฑ๋ฅ์ด ์ฝ 20% ํฅ์๋์ง๋ง, 64GB ์ด์์ RAM์ด ์๋ ๋๋ถ๋ถ์ Apple silicon ์ปดํจํฐ์์๋ ๋ ๋์ ์ฑ๋ฅ์ ๊ด์ฐฐํ์ต๋๋ค.
๋ฐฐ์น ์ถ๋ก
Generating multiple prompts in a batch๋ฅผ ์ฌ์ฉํ๋ฉด ์ถฉ๋์ด ๋ฐ์ํ๊ฑฐ๋ ์์ ์ ์ผ๋ก ์๋ํ์ง ์์ ์ ์์ต๋๋ค. ์ด ๊ฒฝ์ฐ, ๋ฐฐ์น ์ฒ๋ฆฌ ๋์ ๋ฐ๋ณต(iteration)์ ์๋ํด ๋ณด์ธ์.
Xet Storage Details
- Size:
- 4.15 kB
- Xet hash:
- 5d9f67393ccb555ee4436ddb5744cc315023a265a5adb0a59a3d67b70efc66fa
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.