BleachNick's picture
upload required packages
87d40d2
<!--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.
-->
# Habana Gaudiμ—μ„œ Stable Diffusion을 μ‚¬μš©ν•˜λŠ” 방법
πŸ€— DiffusersλŠ” πŸ€— [Optimum Habana](https://huggingface.co/docs/optimum/habana/usage_guides/stable_diffusion)λ₯Ό ν†΅ν•΄μ„œ Habana Gaudi와 ν˜Έν™˜λ©λ‹ˆλ‹€.
## μš”κ΅¬ 사항
- Optimum Habana 1.4 λ˜λŠ” 이후, [μ—¬κΈ°](https://huggingface.co/docs/optimum/habana/installation)에 μ„€μΉ˜ν•˜λŠ” 방법이 μžˆμŠ΅λ‹ˆλ‹€.
- SynapseAI 1.8.
## μΆ”λ‘  νŒŒμ΄ν”„λΌμΈ
Gaudiμ—μ„œ Stable Diffusion 1 및 2둜 이미지λ₯Ό μƒμ„±ν•˜λ €λ©΄ 두 μΈμŠ€ν„΄μŠ€λ₯Ό μΈμŠ€ν„΄μŠ€ν™”ν•΄μ•Ό ν•©λ‹ˆλ‹€:
- [`GaudiStableDiffusionPipeline`](https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline)이 ν¬ν•¨λœ νŒŒμ΄ν”„λΌμΈ. 이 νŒŒμ΄ν”„λΌμΈμ€ *ν…μŠ€νŠΈ-이미지 생성*을 μ§€μ›ν•©λ‹ˆλ‹€.
- [`GaudiDDIMScheduler`](https://huggingface.co/docs/optimum/habana/package_reference/stable_diffusion_pipeline#optimum.habana.diffusers.GaudiDDIMScheduler)이 ν¬ν•¨λœ μŠ€μΌ€μ€„λŸ¬. 이 μŠ€μΌ€μ€„λŸ¬λŠ” Habana Gaudi에 μ΅œμ ν™”λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.
νŒŒμ΄ν”„λΌμΈμ„ μ΄ˆκΈ°ν™”ν•  λ•Œ, HPU에 λ°°ν¬ν•˜κΈ° μœ„ν•΄ `use_habana=True`λ₯Ό 지정해야 ν•©λ‹ˆλ‹€.
λ˜ν•œ κ°€λŠ₯ν•œ κ°€μž₯ λΉ λ₯Έ 생성을 μœ„ν•΄ `use_hpu_graphs=True`둜 **HPU κ·Έλž˜ν”„**λ₯Ό ν™œμ„±ν™”ν•΄μ•Ό ν•©λ‹ˆλ‹€.
λ§ˆμ§€λ§‰μœΌλ‘œ, [Hugging Face Hub](https://huggingface.co/Habana)μ—μ„œ λ‹€μš΄λ‘œλ“œν•  수 μžˆλŠ” [Gaudi configuration](https://huggingface.co/docs/optimum/habana/package_reference/gaudi_config)을 지정해야 ν•©λ‹ˆλ‹€.
```python
from optimum.habana import GaudiConfig
from optimum.habana.diffusers import GaudiDDIMScheduler, GaudiStableDiffusionPipeline
model_name = "stabilityai/stable-diffusion-2-base"
scheduler = GaudiDDIMScheduler.from_pretrained(model_name, subfolder="scheduler")
pipeline = GaudiStableDiffusionPipeline.from_pretrained(
model_name,
scheduler=scheduler,
use_habana=True,
use_hpu_graphs=True,
gaudi_config="Habana/stable-diffusion",
)
```
νŒŒμ΄ν”„λΌμΈμ„ ν˜ΈμΆœν•˜μ—¬ ν•˜λ‚˜ μ΄μƒμ˜ ν”„λ‘¬ν”„νŠΈμ—μ„œ λ°°μΉ˜λ³„λ‘œ 이미지λ₯Ό 생성할 수 μžˆμŠ΅λ‹ˆλ‹€.
```python
outputs = pipeline(
prompt=[
"High quality photo of an astronaut riding a horse in space",
"Face of a yellow cat, high resolution, sitting on a park bench",
],
num_images_per_prompt=10,
batch_size=4,
)
```
더 λ§Žμ€ 정보λ₯Ό μ–»κΈ° μœ„ν•΄, Optimum Habana의 [λ¬Έμ„œ](https://huggingface.co/docs/optimum/habana/usage_guides/stable_diffusion)와 곡식 Github μ €μž₯μ†Œμ— 제곡된 [μ˜ˆμ‹œ](https://github.com/huggingface/optimum-habana/tree/main/examples/stable-diffusion)λ₯Ό ν™•μΈν•˜μ„Έμš”.
## 벀치마크
λ‹€μŒμ€ [Habana/stable-diffusion](https://huggingface.co/Habana/stable-diffusion) Gaudi ꡬ성(ν˜Όν•© 정밀도 bf16/fp32)을 μ‚¬μš©ν•˜λŠ” Habana first-generation Gaudi 및 Gaudi2의 지연 μ‹œκ°„μž…λ‹ˆλ‹€:
| | Latency (배치 크기 = 1) | Throughput (배치 크기 = 8) |
| ---------------------- |:------------------------:|:---------------------------:|
| first-generation Gaudi | 4.29s | 0.283 images/s |
| Gaudi2 | 1.54s | 0.904 images/s |