-
Notifications
You must be signed in to change notification settings - Fork 286
Text2Image pipeline export/import #2716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Text2Image pipeline export/import #2716
Conversation
@TianmengChen @likholat @Wovchena Please review the sample with export/import API proposal: https://github.com/openvinotoolkit/openvino.genai/pull/2716/files#diff-7c43ee3f358ffafcb7b99c16da468002ff143722294947b8bcb22bd153894a10R67 |
LGTM. Why did NPU use a property instead of |
LGTM |
@dmatveev We want to enable export/import blobs for Image2Image pipeline and potentially for other pipelines as well. |
} | ||
|
||
void test_npu_request_size(const std::filesystem::path& models_path) { | ||
ov::AnyMap properties{{"NPU_USE_NPUW", "YES"}, {"NPUW_DEVICES", "CPU"}, {"NPUW_ONLINE_PIPELINE", "NONE"}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for bothering. Just a question here, should we use NPUW for image generation pipeline? I think NPU should be able to handle image generation pipeline without enable NPUW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work without NPUW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds export/import functionality for Text2Image UNet model components, enabling users to export compiled models to blob files and later import them for faster loading. The implementation supports exporting individual model components (UNet, CLIP text encoders, VAE) and provides Python bindings for the export functionality.
- Adds export/import methods to core image generation model classes (UNet2DConditionModel, CLIPTextModel, AutoencoderKL)
- Implements blob path property handling to enable model import during construction
- Provides Python bindings and documentation for the new export/import API
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
src/python/py_utils.cpp | Adds support for PosixPath objects in Python property conversion |
src/python/py_image_generation_pipelines.cpp | Exposes export_model method for Text2ImagePipeline in Python |
src/python/py_image_generation_models.cpp | Adds Python bindings for export_model methods on individual model classes |
src/python/openvino_genai/py_openvino_genai.pyi | Type stub definitions for the new export_model methods |
src/cpp/src/utils.hpp | Declares utility functions for blob export/import operations |
src/cpp/src/utils.cpp | Implements blob export/import utility functions |
src/cpp/src/image_generation/text2image_pipeline.cpp | Adds export_model method to Text2ImagePipeline |
src/cpp/src/image_generation/stable_diffusion_xl_pipeline.hpp | Implements export/import logic for SDXL pipeline components |
src/cpp/src/image_generation/models/ | Adds export/import methods to UNet inference classes |
src/cpp/src/image_generation/models/unet2d_condition_model.cpp | Implements export/import for UNet2DConditionModel |
src/cpp/src/image_generation/models/clip_text_model.cpp | Implements export/import for CLIPTextModel |
src/cpp/src/image_generation/models/autoencoder_kl.cpp | Implements export/import for AutoencoderKL |
src/cpp/src/image_generation/diffusion_pipeline.hpp | Adds virtual export_model method to base DiffusionPipeline |
src/cpp/include/openvino/genai/ | Header updates with export_model method declarations |
src/cpp/include/openvino/genai/common_types.hpp | Defines blob_path property for specifying import directory |
samples/ | Documentation and examples for using the export/import functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
OV PR merged. export/import on NPU device with fallback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests. I think the test should check that a new pipeline can be constructed form the blob. Save the blob to a temp dir instead of cache to reduce share usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no image generation python tests for the moment. I propose to implement it in a separate PR, I'll create a ticket for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know.
Adding a file shouldn't be a big deal. Anna wouldn't be able to implement it easily because she isn't familiar with GenAI's tests because of the reason you named, so adding export test here should be a good start
@TianmengChen could you please test this export/import API on NPU device? |
Hi @as-suvorov , can you give me example codes, when I use ov::CacheMode::OPTIMIZE_SPEED it return here are my test codes:
and can you give me some example codes like heterogeneous_stable_diffusion.cpp example, that text_encoder on CPU |
This is NPU plugin issue, we need help from NPU team. std::string device = "GPU";
ov::genai::Text2ImagePipeline pipeline(models_path, device, ov::cache_mode(ov::CacheMode::OPTIMIZE_SPEED));
pipeline.export_model(models_path / "blobs");
ov::genai::Text2ImagePipeline imported_pipeline(models_path, device, ov::genai::blob_path(models_path / "blobs")); Let's also try to remove cache mode for NPU: std::string device = "NPU";
ov::genai::Text2ImagePipeline pipeline(models_path, device);
pipeline.export_model(models_path / "blobs"); |
@TianmengChen please check heterogeneous_stable_diffusion with export/import sample: https://gist.github.com/as-suvorov/7cd131b6f42a4326cfb75c1bab8dae6d |
Thanks @as-suvorov , I first tried with this code on NPU and remove xml and bin file under unet, vae, text_encoder, and it works.
But for heterogeneous_stable_diffusion example, it return this: text_encoder_device: CPU But this model can run with original heterogeneous_stable_diffusion example. FYI @JohnLeFeng |
There is a limitation of NPU export/import unet model implementation. The batch size is not preserved and model always imported with batch size 1: https://github.com/openvinotoolkit/openvino.genai/pull/2716/files#r2355059791 |
This is the only workaround I see at the moment |
Implements
void export_model(const std::filesystem::path& blob_path)
andov::Property<std::filesystem::path> blob_path{"blob_path"}
forText2ImagePipeline
.Ticket: 171706