OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPUW] Update NPUW caching and exporting docs (#30591)
Alexey Smirnov3612b8621c1c
diff --git a/docs/articles_en/openvino-workflow-generative/inference-with-genai/inference-with-genai-on-npu.rst b/docs/articles_en/openvino-workflow-generative/inference-with-genai/inference-with-genai-on-npu.rstindex 11453576864..7a346ed728c 100644--- a/docs/articles_en/openvino-workflow-generative/inference-with-genai/inference-with-genai-on-npu.rst+++ b/docs/articles_en/openvino-workflow-generative/inference-with-genai/inference-with-genai-on-npu.rst@@ -244,11 +244,14 @@ reusing them for future pipeline runs.CACHE_DIR------------------------------------------------------------------------------------------------``CACHE_DIR`` operates similarly to the older ``NPUW_CACHE_DIR``, except for two differences:+``CACHE_DIR`` operates similarly to the older ``NPUW_CACHE_DIR``, except for the differences below:* It creates a single ".blob" file and loads it faster.-* It stores all model weights inside the blob, making it much bigger than individual compiled- schedules for model's subgraphs stored by ``NPUW_CACHE_DIR``.+* Blob type is defined by ``"CACHE_MODE"``. By default it's ``"OPTIMIZE_SIZE"``, in which case NPUW+ produces weightless blob, so either original weights file or ``ov::Model`` object is required+ to load such a blob.+* Optionally, you can cache a blob with weights inside making it much bigger than the default+ weightless blob. To do so, you need to pass ``"CACHE_MODE" : "OPTIMIZE_SPEED"`` in the config... tab-set::@@ -276,10 +279,16 @@ Specifying ``EXPORT_BLOB`` and ``BLOB_PATH`` parameters works similarly to ``CAC* It allows to explicitly specify where to **store** the compiled model.* For subsequent runs, it requires the same ``BLOB_PATH`` to **import** the compiled model.+* Blob type is defined by ``"CACHE_MODE"``. By default it's ``"OPTIMIZE_SIZE"``, in which case NPUW+ produces weightless blob, so either original weights file or ``ov::Model`` object is required+ to load such a blob.+* To export a blob with weights you need to pass ``"CACHE_MODE" : "OPTIMIZE_SPEED"`` in the config.+* If the blob is exported as weightless you also need to either provide+ ``"WEIGHTS_PATH" : "path\\to\\original\\model.bin"`` or ``"MODEL_PTR" : original ov::Model object``... tab-set::- .. tab-item:: Export example+ .. tab-item:: Export weightless example.. tab-set::@@ -297,10 +306,52 @@ Specifying ``EXPORT_BLOB`` and ``BLOB_PATH`` parameters works similarly to ``CAC.. code-block:: cpp- ov::AnyMap pipeline_config = { { "EXPORT_BLOB", "YES" }, { "BLOB_PATH", ".npucache\\compiled_model.blob" } };+ ov::AnyMap pipeline_config = { { "EXPORT_BLOB", "YES" }, { "BLOB_PATH", ".npucache\\compiled_model.blob" } };ov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);++ .. tab-item:: Import weightless example- .. tab-item:: Import example+ .. tab-set::++ .. tab-item:: Python+ :sync: py++ .. code-block:: python++ pipeline_config = { "BLOB_PATH": ".npucache\\compiled_model.blob", "WEIGHTS_PATH": "path\\to\\original\\model.bin" }+ pipe = ov_genai.LLMPipeline(model_path, "NPU", pipeline_config)+++ .. tab-item:: C+++ :sync: cpp++ .. code-block:: cpp++ ov::AnyMap pipeline_config = { { "BLOB_PATH", ".npucache\\compiled_model.blob" }, { "WEIGHTS_PATH", "path\\to\\original\\model.bin" } };+ ov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);++ .. tab-item:: Export with weights example++ .. tab-set::++ .. tab-item:: Python+ :sync: py++ .. code-block:: python++ pipeline_config = { "EXPORT_BLOB": "YES", "BLOB_PATH": ".npucache\\compiled_model.blob", "CACHE_MODE" : "OPTIMIZE_SPEED" }+ pipe = ov_genai.LLMPipeline(model_path, "NPU", pipeline_config)+++ .. tab-item:: C+++ :sync: cpp++ .. code-block:: cpp++ ov::AnyMap pipeline_config = { { "EXPORT_BLOB", "YES" }, { "BLOB_PATH", ".npucache\\compiled_model.blob" }, { "CACHE_MODE", "OPTIMIZE_SPEED" } };+ ov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);++ .. tab-item:: Import with weights example.. tab-set::@@ -322,6 +373,44 @@ Specifying ``EXPORT_BLOB`` and ``BLOB_PATH`` parameters works similarly to ``CACov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);+Blob encryption+-----------------------------------------------------------------------------------------------++When exporting NPUW blobs you can also specify encryption and decryption functions for the blob.+In case of weightless blob the whole blob is encrypted, in case of blob with weights everything but+model weights is encrypted.++.. tab-set::++ .. tab-item:: Export example++ .. tab-set::++ .. tab-item:: C+++ :sync: cpp++ .. code-block:: cpp++ ov::EncryptionCallbacks encryption_callbacks;+ encryption_callbacks.encrypt = [](const std::string& s) { return s; };+ ov::AnyMap pipeline_config = { { "EXPORT_BLOB", "YES" }, { "BLOB_PATH", ".npucache\\compiled_model.blob" }, { "CACHE_ENCRYPTION_CALLBACKS", encryption_callbacks } };+ ov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);++ .. tab-item:: Import example++ .. tab-set::++ .. tab-item:: C+++ :sync: cpp++ .. code-block:: cpp++ ov::EncryptionCallbacks encryption_callbacks;+ encryption_callbacks.decrypt = [](const std::string& s) { return s; };+ ov::AnyMap pipeline_config = { { "BLOB_PATH", ".npucache\\compiled_model.blob" }, { "WEIGHTS_PATH", "path\\to\\original\\model.bin" }, { "CACHE_ENCRYPTION_CALLBACKS", encryption_callbacks } };+ ov::genai::LLMPipeline pipe(model_path, "NPU", pipeline_config);++Disable memory allocation+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++