# OpenVINO

🤗 [Optimum](https://github.com/huggingface/optimum-intel)은 다양한 Intel 프로세서에서 추론을 수행할 수 있는 OpenVINO와 호환되는 Stable Diffusion 파이프라인을 제공합니다(지원되는 장치의 [전체 목록](https://docs.openvino.ai/latest/openvino_docs_OV_UG_supported_plugins_Supported_Devices.html)을 참조하세요).

`--upgrade-strategy eager` 옵션을 사용하여 🤗 Optimum Intel을 설치해야 [`optimum-intel`](https://github.com/huggingface/optimum-intel)이 최신 버전을 사용하는지 확인할 수 있습니다:

```bash
pip install --upgrade-strategy eager optimum["openvino"]
```

이 가이드에서는 OpenVINO와 함께 Stable Diffusion 및 Stable Diffusion XL (SDXL) 파이프라인을 사용하는 방법을 보여줍니다.

## Stable Diffusion

로드 및 추론 실행을 위해 `OVStableDiffusionPipeline`을 사용합니다. PyTorch 모델을 로드하여 OpenVINO 형식으로 즉시 변환하려면 `export=True`를 설정하세요:

```python
from optimum.intel import OVStableDiffusionPipeline

model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
pipeline = OVStableDiffusionPipeline.from_pretrained(model_id, export=True)
prompt = "sailing ship in storm by Rembrandt"
image = pipeline(prompt).images[0]

# Don't forget to save the exported model
pipeline.save_pretrained("openvino-sd-v1-5")
```

추론 속도를 더 높이기 위해 모델을 정적으로 리셰이프합니다. 출력 높이 또는 너비와 같은 매개변수를 변경하면 모델을 다시 정적으로 리셰이프해야 합니다.

```python
# Define the shapes related to the inputs and desired outputs
batch_size, num_images, height, width = 1, 1, 512, 512

# Statically reshape the model
pipeline.reshape(batch_size, height, width, num_images)
# Compile the model before inference
pipeline.compile()

image = pipeline(
    prompt,
    height=height,
    width=width,
    num_images_per_prompt=num_images,
).images[0]
```

    

🤗 Optimum [문서](https://huggingface.co/docs/optimum/intel/inference#stable-diffusion)에서 더 많은 예시를 찾을 수 있으며, Stable Diffusion은 텍스트-이미지 생성, 이미지-이미지 변환, 인페인팅을 지원합니다.

## Stable Diffusion XL

SDXL로 로드하고 추론을 실행하려면 `OVStableDiffusionXLPipeline`을(를) 사용하세요:

```python
from optimum.intel import OVStableDiffusionXLPipeline

model_id = "stabilityai/stable-diffusion-xl-base-1.0"
pipeline = OVStableDiffusionXLPipeline.from_pretrained(model_id)
prompt = "sailing ship in storm by Rembrandt"
image = pipeline(prompt).images[0]
```

추론 속도를 더 높이기 위해, Stable Diffusion 섹션에 나와 있듯이 모델을 [정적으로 리사이즈](#stable-diffusion)합니다.

🤗 Optimum [문서](https://huggingface.co/docs/optimum/intel/inference#stable-diffusion-xl)에서 더 많은 예시를 확인할 수 있으며, OpenVINO에서 SDXL을 실행하는 기능은 텍스트-이미지 생성 및 이미지-이미지 변환을 지원합니다.

