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
Modify encryption callback to expect a binary string in Python API (#28953)
Tomasz Krupaae3b71f6f85c
diff --git a/docs/articles_en/assets/snippets/ov_caching.py b/docs/articles_en/assets/snippets/ov_caching.pyindex 3d1942ac35a..ca44f2a0d28 100644--- a/docs/articles_en/assets/snippets/ov_caching.py+++ b/docs/articles_en/assets/snippets/ov_caching.py@@ -56,11 +56,11 @@ if "GPU" in core.available_devices:# ! [ov:caching:part5]import base64-def encrypt_base64(src):- return base64.b64encode(bytes(src, "utf-8"))+def encrypt_base64(src: bytes):+ return base64.b64encode(src)-def decrypt_base64(src):- return base64.b64decode(bytes(src, "utf-8"))+def decrypt_base64(src: bytes):+ return base64.b64decode(src)core = ov.Core()core.set_property({props.cache_dir: path_to_cache_dir})@@ -73,14 +73,14 @@ compiled_model = core.compile_model(model=model, device_name=device_name, config# ! [ov:caching:part6]import base64-def encrypt_base64(src):- return base64.b64encode(bytes(src, "utf-8"))+def encrypt_base64(src: bytes):+ return base64.b64encode(src)-def decrypt_base64(src):- return base64.b64decode(bytes(src, "utf-8"))+def decrypt_base64(src: bytes):+ return base64.b64decode(src)core = ov.Core()-if "GPU" in core.available_devices:+if any("GPU" in device for device in core.available_devices):core.set_property({props.cache_dir: path_to_cache_dir})config_cache = {}config_cache["CACHE_ENCRYPTION_CALLBACKS"] = [encrypt_base64, decrypt_base64]diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cppindex 8e8c405dfd2..199e7f0320a 100644--- a/src/bindings/python/src/pyopenvino/utils/utils.cpp+++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp@@ -298,14 +298,14 @@ std::map<std::string, ov::Any> properties_to_any_map(const std::map<std::string,[py_encrypt](const std::string& in_str) -> std::string {// Acquire GIL, execute Python functionpy::gil_scoped_acquire acquire;- return (*py_encrypt)(in_str).cast<std::string>();+ return (*py_encrypt)(py::bytes(in_str)).cast<std::string>();};std::function<std::string(const std::string&)> decrypt_func =[py_decrypt](const std::string& in_str) -> std::string {// Acquire GIL, execute Python functionpy::gil_scoped_acquire acquire;- return (*py_decrypt)(in_str).cast<std::string>();+ return (*py_decrypt)(py::bytes(in_str)).cast<std::string>();};ov::EncryptionCallbacks encryption_callbacks{encrypt_func, decrypt_func};properties_to_cpp[property.first] = encryption_callbacks;diff --git a/src/bindings/python/tests/utils/helpers.py b/src/bindings/python/tests/utils/helpers.pyindex 4da5dd77946..aa67eb957c6 100644--- a/src/bindings/python/tests/utils/helpers.py+++ b/src/bindings/python/tests/utils/helpers.py@@ -198,11 +198,11 @@ def generate_relu_compiled_model(def encrypt_base64(src):- return base64.b64encode(bytes(src, "utf-8"))+ return base64.b64encode(src)def decrypt_base64(src):- return base64.b64decode(bytes(src, "utf-8"))+ return base64.b64decode(src)def generate_relu_compiled_model_with_config(