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.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

OpenVINO

🤗 Optimum は、OpenVINO 互換の Stable Diffusion パイプラインを提供し、さまざまな Intel プロセッサ上で推論を実行できます(サポート対象デバイスの完全なリストを参照)。

--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の実行は、テキストから画像への変換と画像から画像への変換の両方をサポートしています。

Update on GitHub