Diffusers 文件

OpenVINO

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

OpenVINO

🤗 Optimum 提供了與 OpenVINO 相容的 Stable Diffusion 管道,可在各種英特爾處理器上執行推理(參閱支援裝置的完整列表)。

您需要使用 --upgrade-strategy eager 選項安裝 🤗 Optimum Intel,以確保 optimum-intel 使用最新版本。

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

本指南將向您展示如何使用 OpenVINO 的 Stable Diffusion 和 Stable Diffusion XL (SDXL) 管道。

Stable Diffusion

要載入並執行推理,請使用 OVStableDiffusionPipeline。如果您想載入 PyTorch 模型並即時將其轉換為 OpenVINO 格式,請設定 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")

為了進一步加速推理,請靜態重塑模型。如果您更改了任何引數,例如輸出高度或寬度,則需要再次靜態重塑模型。

# 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 文件中找到更多示例,並且 Stable Diffusion 支援文字到影像、影像到影像和影像修復。

Stable Diffusion XL

要使用 SDXL 載入並執行推理,請使用 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]

為了進一步加速推理,請像 Stable Diffusion 部分中所示,靜態重塑模型。

您可以在 🤗 Optimum 文件中找到更多示例,OpenVINO 中執行 SDXL 支援文字到影像和影像到影像。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.