mirror of
https://github.com/huggingface/diffusers.git
synced 2026-01-27 17:22:53 +03:00
71 lines
3.8 KiB
Markdown
71 lines
3.8 KiB
Markdown
<!--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)์ ๊ด๋ จ์ด ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ด ๋ฌธ์ ๋ ํด๊ฒฐ๋๊ณ ์์ง๋ง ์ง๊ธ์ ๋ฐฐ์น ๋์ ๋ฐ๋ณต ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค. |