Diffusers documentation

OpenVINO

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

OpenVINO

🤗 يوفر Optimum خطوط أنابيب Stable Diffusion متوافقة مع OpenVINO لتنفيذ الاستدلال على مجموعة متنوعة من معالجات Intel (انظر القائمة الكاملة للأجهزة المدعومة).

ستحتاج إلى تثبيت 🤗 Optimum Intel مع خيار --upgrade-strategy eager للتأكد من أن optimum-intel يستخدم أحدث إصدار:

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

ستُظهر لك هذه الدليل كيفية استخدام خطوط أنابيب Stable Diffusion و Stable Diffusion XL (SDXL) مع OpenVINO.

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 مدعوم لتوليد الصور من النص، وتحويل الصورة إلى صورة، وإعادة رسم المناطق (inpainting).

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، كما أن تشغيل SDXL في OpenVINO مدعوم لتوليد الصور من النص وتحويل الصور إلى صور.

Update on GitHub