diff --git a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp index 710ad70d0b6cfa..578523dd309f93 100644 --- a/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp +++ b/src/bindings/python/src/pyopenvino/graph/dict_attribute_visitor.cpp @@ -274,6 +274,17 @@ void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::Valu if (m_attributes.contains(name)) { OPENVINO_THROW("No AttributeVisitor support for accessing attribute named: ", name); } + + if (auto _adapter = dynamic_cast>*>(&adapter)) { + m_attributes[name.c_str()] = _adapter->get()->get_info().variable_id; + } else if (auto _adapter = dynamic_cast*>(&adapter)) { + auto partial_shape = _adapter->get(); + std::vector shape; + for (const auto& dim : partial_shape) { + shape.push_back(dim.is_dynamic() ? -1 : dim.get_length()); + } + m_attributes[name.c_str()] = shape; + } } void util::DictAttributeSerializer::on_adapter(const std::string& name, ov::ValueAccessor& adapter) { m_attributes[name.c_str()] = adapter.get(); diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.py index 355de9ab151383..3567732bb6faeb 100644 --- a/src/bindings/python/tests/test_graph/test_create_op.py +++ b/src/bindings/python/tests/test_graph/test_create_op.py @@ -1183,11 +1183,15 @@ def test_read_value(): init_value = ov.parameter([2, 2], name="init_value", dtype=np.int32) node = ov.read_value(init_value, "var_id_667", np.int32, [2, 2]) + read_value_attributes = node.get_attributes() assert node.get_type_name() == "ReadValue" assert node.get_output_size() == 1 assert list(node.get_output_shape(0)) == [2, 2] assert node.get_output_element_type(0) == Type.i32 + assert read_value_attributes["variable_type"] == "i32" + assert read_value_attributes["variable_id"] == "var_id_667" + assert read_value_attributes["variable_shape"] == [2, 2] def test_read_value_dyn_variable_pshape(): @@ -1205,11 +1209,13 @@ def test_assign(): input_data = ov.parameter([5, 7], name="input_data", dtype=np.int32) rv = ov.read_value(input_data, "var_id_667", np.int32, [5, 7]) node = ov.assign(rv, "var_id_667") + assign_attributes = node.get_attributes() assert node.get_type_name() == "Assign" assert node.get_output_size() == 1 assert list(node.get_output_shape(0)) == [5, 7] assert node.get_output_element_type(0) == Type.i32 + assert assign_attributes["variable_id"] == "var_id_667" def test_extract_image_patches(): @@ -2353,3 +2359,10 @@ def test_topk_opset11(): assert node.get_output_size() == 2 assert list(node.get_output_shape(0)) == [1, 3, 3] assert list(node.get_output_shape(1)) == [1, 3, 3] + + +def test_parameter_get_attributes(): + parameter = ov.parameter([2, 2], dtype=np.float32, name="InputData") + parameter_attributes = parameter.get_attributes() + assert parameter_attributes["element_type"] == "f32" + assert parameter_attributes["shape"] == [2, 2]