Spaces:
Running
on
Zero
Running
on
Zero
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
specific language governing permissions and limitations under the License. | |
--> | |
# Apple Silicon (M1/M2)μμ Stable Diffusionμ μ¬μ©νλ λ°©λ² | |
Diffusersλ Stable Diffusion μΆλ‘ μ μν΄ PyTorch `mps`λ₯Ό μ¬μ©ν΄ Apple μ€λ¦¬μ½κ³Ό νΈνλ©λλ€. λ€μμ Stable Diffusionμ΄ μλ M1 λλ M2 μ»΄ν¨ν°λ₯Ό μ¬μ©νκΈ° μν΄ λ°λΌμΌ νλ λ¨κ³μ λλ€. | |
## μꡬ μ¬ν | |
- Apple silicon (M1/M2) νλμ¨μ΄μ Mac μ»΄ν¨ν°. | |
- macOS 12.6 λλ μ΄ν (13.0 λλ μ΄ν μΆμ²). | |
- Python arm64 λ²μ | |
- PyTorch 2.0(μΆμ²) λλ 1.13(`mps`λ₯Ό μ§μνλ μ΅μ λ²μ ). Yhttps://pytorch.org/get-started/locally/μ μ§μΉ¨μ λ°λΌ `pip` λλ `conda`λ‘ μ€μΉν μ μμ΅λλ€. | |
## μΆλ‘ νμ΄νλΌμΈ | |
μλ μ½λλ μ΅μν `to()` μΈν°νμ΄μ€λ₯Ό μ¬μ©νμ¬ `mps` λ°±μλλ‘ Stable Diffusion νμ΄νλΌμΈμ M1 λλ M2 μ₯μΉλ‘ μ΄λνλ λ°©λ²μ 보μ¬μ€λλ€. | |
<Tip warning={true}> | |
**PyTorch 1.13μ μ¬μ© μ€μΌ λ ** μΆκ° μΌνμ± μ λ¬μ μ¬μ©νμ¬ νμ΄νλΌμΈμ "νλΌμ΄λ°"νλ κ²μ μΆμ²ν©λλ€. μ΄κ²μ λ°κ²¬ν μ΄μν λ¬Έμ μ λν μμ ν΄κ²° λ°©λ²μ λλ€. 첫 λ²μ§Έ μΆλ‘ μ λ¬μ νμ μ λ¬μ μ½κ° λ€λ₯Έ κ²°κ³Όλ₯Ό μμ±ν©λλ€. μ΄ μ λ¬μ ν λ²λ§ μννλ©΄ λλ©° μΆλ‘ λ¨κ³λ₯Ό ν λ²λ§ μ¬μ©νκ³ κ²°κ³Όλ₯Ό νκΈ°ν΄λ λ©λλ€. | |
</Tip> | |
μ΄μ νμμ μ€λͺ ν κ²λ€μ ν¬ν¨ν μ¬λ¬ λ¬Έμ λ₯Ό ν΄κ²°νλ―λ‘ PyTorch 2 μ΄μμ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. | |
```python | |
# `huggingface-cli login`μ λ‘κ·ΈμΈλμ΄ μμμ νμΈ | |
from diffusers import DiffusionPipeline | |
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5") | |
pipe = pipe.to("mps") | |
# μ»΄ν¨ν°κ° 64GB μ΄νμ RAM λ¨μΌ λ μΆμ² | |
pipe.enable_attention_slicing() | |
prompt = "a photo of an astronaut riding a horse on mars" | |
# μ²μ "μλ°μ " μ λ¬ (μ μ€λͺ μ 보μΈμ) | |
_ = pipe(prompt, num_inference_steps=1) | |
# κ²°κ³Όλ μλ°μ μ λ¬ νμ CPU μ₯μΉμ κ²°κ³Όμ μΌμΉν©λλ€. | |
image = pipe(prompt).images[0] | |
``` | |
## μ±λ₯ μΆμ² | |
M1/M2 μ±λ₯μ λ©λͺ¨λ¦¬ μλ ₯μ λ§€μ° λ―Όκ°ν©λλ€. μμ€ν μ νμν κ²½μ° μλμΌλ‘ μ€μλμ§λ§ μ€μν λ μ±λ₯μ΄ ν¬κ² μ νλ©λλ€. | |
νΉν μ»΄ν¨ν°μ μμ€ν RAMμ΄ 64GB λ―Έλ§μ΄κ±°λ 512 Γ 512ν½μ λ³΄λ€ ν° λΉνμ€ ν΄μλμμ μ΄λ―Έμ§λ₯Ό μμ±νλ κ²½μ°, μΆλ‘ μ€μ λ©λͺ¨λ¦¬ μλ ₯μ μ€μ΄κ³ μ€μνμ λ°©μ§νκΈ° μν΄ *μ΄ν μ μ¬λΌμ΄μ±*μ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. μ΄ν μ μ¬λΌμ΄μ±μ λΉμ©μ΄ λ§μ΄ λλ μ΄ν μ μμ μ ν λ²μ λͺ¨λ μννλ λμ μ¬λ¬ λ¨κ³λ‘ μνν©λλ€. μΌλ°μ μΌλ‘ λ²μ© λ©λͺ¨λ¦¬κ° μλ μ»΄ν¨ν°μμ ~20%μ μ±λ₯ μν₯μ λ―ΈμΉμ§λ§ 64GB μ΄μμ΄ μλ κ²½μ° λλΆλΆμ Apple Silicon μ»΄ν¨ν°μμ *λ λμ μ±λ₯*μ΄ κ΄μ°°λμμ΅λλ€. | |
```python | |
pipeline.enable_attention_slicing() | |
``` | |
## Known Issues | |
- μ¬λ¬ ν둬ννΈλ₯Ό λ°°μΉλ‘ μμ±νλ κ²μ [μΆ©λμ΄ λ°μνκ±°λ μμ μ μΌλ‘ μλνμ§ μμ΅λλ€](https://github.com/huggingface/diffusers/issues/363). μ°λ¦¬λ μ΄κ²μ΄ [PyTorchμ `mps` λ°±μλ](https://github.com/pytorch/pytorch/issues/84039)μ κ΄λ ¨μ΄ μλ€κ³ μκ°ν©λλ€. μ΄ λ¬Έμ λ ν΄κ²°λκ³ μμ§λ§ μ§κΈμ λ°°μΉ λμ λ°λ³΅ λ°©λ²μ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. |