| <!--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 | |
|
|