Skip to content

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

[PyOV] allow constant accept keyword args (#27346)

Anastasia Kuporosova2f78f6f9ca0f
diff --git a/src/bindings/python/src/openvino/runtime/opset13/ops.py b/src/bindings/python/src/openvino/runtime/opset13/ops.py
index cb201d3d426..a624ffb4f79 100644
--- a/src/bindings/python/src/openvino/runtime/opset13/ops.py
+++ b/src/bindings/python/src/openvino/runtime/opset13/ops.py
@@ -15,7 +15,7 @@ from openvino.runtime import Node, Shape, Type, Output, Tensor
from openvino.runtime.op import Constant, Result
from openvino.runtime.opset1 import convert_like
from openvino.runtime.opset_utils import _get_node_factory
-from openvino.runtime.utils.decorators import binary_op, nameable_op, unary_op
+from openvino.runtime.utils.decorators import binary_op, nameable_op, unary_op, overloading
from openvino.runtime.utils.types import (
NumericData,
NodeInput,
@@ -271,7 +271,7 @@ def scaled_dot_product_attention(
return _get_node_factory_opset13().create("ScaledDotProductAttention", inputs, attributes)
-@singledispatch
+@overloading(Union[NumericData, np.number, bool, np.bool_, list], Union[NumericType, Type], Optional[str], bool) # type: ignore
@nameable_op
def constant(
value: Union[NumericData, np.number, bool, np.bool_, list],
@@ -339,9 +339,9 @@ def constant(
return Constant(_value, shared_memory=_shared_memory)
+@overloading(Tensor, bool, Optional[str]) # type: ignore
@nameable_op
-def _(
+def constant( # noqa: F811
tensor: Tensor,
shared_memory: bool = False,
name: Optional[str] = None,
diff --git a/src/bindings/python/tests/test_graph/test_constant.py b/src/bindings/python/tests/test_graph/test_constant.py
index e28a4ad0551..131654855b3 100644
--- a/src/bindings/python/tests/test_graph/test_constant.py
+++ b/src/bindings/python/tests/test_graph/test_constant.py
@@ -87,7 +87,7 @@ def test_init_with_array(src_dtype, dst_dtype, shared_flag, data_getter):
data = np.ascontiguousarray(data)
# Create constant from based on numpy dtype or openvino type
- ov_const = ops.constant(data, dtype=dst_dtype, shared_memory=shared_flag)
+ ov_const = ops.constant(data, dst_dtype, shared_memory=shared_flag)
# Check shape and element type of Constant class
assert isinstance(ov_const, Constant)
@@ -842,7 +842,7 @@ def test_get_data_casting_bf16(src_dtype, dst_dtype, copy_flag):
)
def test_get_data_casting_packed(src_dtype, ov_type, dst_dtype, copy_flag):
data = np.array([[0, 0, 0, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]], dtype=src_dtype)
- ov_const = ops.constant(data, dtype=ov_type)
+ ov_const = ops.constant(value=data, dtype=ov_type)
arr = ov_const.get_data(dtype=dst_dtype, copy=copy_flag)
if dst_dtype is None:
@@ -867,7 +867,7 @@ def test_const_from_tensor(shared_flag):
shape = [1, 3, 32, 32]
arr = np.ones(shape).astype(np.float32)
ov_tensor = Tensor(arr, shape, Type.f32)
- ov_const = ops.constant(ov_tensor, shared_memory=shared_flag)
+ ov_const = ops.constant(tensor=ov_tensor, shared_memory=shared_flag)
assert isinstance(ov_const, Constant)
assert np.all(list(ov_const.shape) == shape)