Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Deprecate `PostponedConstant` constructor causing Tensor copy (#31981)

Przemyslaw Wysockic38949673adf
diff --git a/src/bindings/python/src/openvino/utils/postponed_constant.py b/src/bindings/python/src/openvino/utils/postponed_constant.py
index 6c7db5b8e76..cb58ee5b840 100644
--- a/src/bindings/python/src/openvino/utils/postponed_constant.py
+++ b/src/bindings/python/src/openvino/utils/postponed_constant.py
@@ -47,6 +47,16 @@ class PostponedConstant(Op):
self.m_maker = maker
if name is not None:
self.friendly_name = name
+
+ if callable(self.m_maker) and hasattr(self.m_maker.__call__, "__code__") and self.m_maker.__call__.__code__.co_argcount > 1:
+ from openvino._pyopenvino.util import deprecation_warning
+ deprecation_warning(
+ "PostponedConstant.__init__ with Callable[[Tensor], None]",
+ "2026.0",
+ "Please use PostponedConstant's 'maker' argument as Callable[[], Tensor] instead of Callable[[Tensor], None].",
+ 3
+ )
+
self.constructor_validate_and_infer_types()
def evaluate(self, outputs: TensorVector, _: list[Tensor]) -> bool: # type: ignore
diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.py
index a4db87c1fbb..ec4f12b5098 100644
--- a/src/bindings/python/tests/test_utils/test_utils.py
+++ b/src/bindings/python/tests/test_utils/test_utils.py
@@ -187,7 +187,16 @@ def test_serialize_postponned_constant(prepare_ir_paths):
def test_serialize_postponned_constant_maker_tensor_copy(prepare_ir_paths):
maker = MakerTensorCopy()
- model = create_model(maker)
+ with pytest.warns(
+ DeprecationWarning,
+ match=(
+ "PostponedConstant.__init__ with Callable\\[\\[Tensor\\], None\\] "
+ "is deprecated and will be removed in version 2026.0"
+ ),
+ ) as w:
+ model = create_model(maker)
+ assert issubclass(w[0].category, DeprecationWarning)
+ assert "Please use PostponedConstant's 'maker' argument as Callable[[], Tensor] instead of Callable[[Tensor], None]" in str(w[0].message)
assert maker.called_times() == 0
model_export_file_name, weights_export_file_name = prepare_ir_paths