Diffusers documentation

OpenVINO

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

OpenVINO

🤗 Optimum ofrece pipelines de Stable Diffusion compatibles con OpenVINO para realizar inferencia en una variedad de procesadores de Intel (consulte la lista completa de dispositivos compatibles).

Deberás instalar 🤗 Optimum Intel con la opción --upgrade-strategy eager para asegurarte de que optimum-intel esté usando la última versión:

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

Esta guía te mostrará cómo usar los pipelines de Stable Diffusion y Stable Diffusion XL (SDXL) con OpenVINO.

Stable Diffusion

Para cargar y ejecutar la inferencia, use OVStableDiffusionPipeline. Si desea cargar un modelo de PyTorch y convertirlo al formato OpenVINO sobre la marcha, establezca export=True:

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")

Para acelerar aún más la inferencia, redimensiona el modelo de forma estática. Si cambias algún parámetro, como la altura o el ancho de las salidas, deberás redimensionar el modelo de forma estática de nuevo.

# 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]

Puedes encontrar más ejemplos en la documentación de 🤗 Optimum, y Stable Diffusion es compatible con texto a imagen, imagen a imagen e inpainting.

Stable Diffusion XL

Para cargar y ejecutar inferencia con SDXL, use OVStableDiffusionXLPipeline:

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]

Para acelerar aún más la inferencia, redimensiona de forma estática el modelo, como se muestra en la sección de Stable Diffusion.

Puedes encontrar más ejemplos en la documentación de 🤗 Optimum, y la ejecución de SDXL en OpenVINO está soportada para texto a imagen e imagen a imagen.

Update on GitHub