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 cung cấp các pipeline Stable Diffusion tương thích với OpenVINO để thực hiện suy luận trên nhiều loại bộ xử lý Intel khác nhau (xem danh sách đầy đủ các thiết bị được hỗ trợ).

Bạn cần cài đặt 🤗 Optimum Intel với tùy chọn --upgrade-strategy eager để đảm bảo optimum-intel đang sử dụng phiên bản mới nhất:

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

Hướng dẫn này sẽ cho bạn thấy cách sử dụng các pipeline Stable Diffusion và Stable Diffusion XL (SDXL) với OpenVINO.

Stable Diffusion

Để tải và chạy suy luận, hãy sử dụng OVStableDiffusionPipeline. Nếu bạn muốn tải một mô hình PyTorch và chuyển đổi nó sang định dạng OpenVINO ngay lập tức, hãy đặt 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")

Để tăng tốc suy luận hơn nữa, hãy định hình lại mô hình một cách tĩnh. Nếu bạn thay đổi bất kỳ tham số nào như chiều cao hoặc chiều rộng của đầu ra, bạn sẽ cần định hình lại mô hình của mình một cách tĩnh một lần nữa.

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

Bạn có thể tìm thêm các ví dụ trong tài liệu của 🤗 Optimum, và Stable Diffusion được hỗ trợ cho text-to-image, image-to-image và inpainting.

Stable Diffusion XL

Để tải và chạy suy luận với SDXL, hãy sử dụng 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]

Để tăng tốc suy luận hơn nữa, hãy định hình lại tĩnh mô hình như đã trình bày trong phần Stable Diffusion.

Bạn có thể tìm thêm các ví dụ trong tài liệu của 🤗 Optimum, và việc chạy SDXL trên OpenVINO được hỗ trợ cho cả text-to-image và image-to-image.

Update on GitHub