Skip to content

Commit

Permalink
fix python API
Browse files Browse the repository at this point in the history
  • Loading branch information
itikhono committed Oct 19, 2023
1 parent 50e6ae9 commit 96e9a55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/snippets/ov_model_with_state_infer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
// For each such a pair, its own variable object must be created.
const std::string variable_name("variable0");
auto variable = std::make_shared<ov::op::util::Variable>(
ov::op::util::VariableInfo{ov::PartialShape::dynamic(), ov::element::dynamic, variable_name});
ov::op::util::VariableInfo{ov::PartialShape{1, 1}, ov::element::f32, variable_name});

// Creating ov::Model
auto read = std::make_shared<ov::opset11::ReadValue>(init_const, variable);
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/ov_model_with_state_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def main():
#! [ov:model_create]
# 2. Creating ov.Model
input = ops.parameter([1, 1], dtype=np.float32, name="data")
init_const = ops.constant([0], dtype=np.float32)
read = ops.read_value(init_const, "variable0")
init_const = ops.constant([[0]], dtype=np.float32)
read = ops.read_value(init_const, "variable0", [1, 1], "fp32")
add = ops.add(input, read)
assign = ops.assign(add, "variable0")
add2 = ops.add(add, read)
Expand Down
18 changes: 16 additions & 2 deletions src/bindings/python/src/openvino/runtime/opset6/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,30 @@ def mvn(


@nameable_op
def read_value(init_value: NodeInput, variable_id: str, name: Optional[str] = None) -> Node:
def read_value(init_value: NodeInput,
variable_id: str,
variable_shape: Optional[TensorShape] = None,
variable_type: Optional[str] = None,
name: Optional[str] = None) -> Node:
"""Return a node which produces the Assign operation.
:param init_value: Node producing a value to be returned instead of an unassigned variable.
:param variable_id: Id of a variable to be read.
:param variable_shape: shape to be set into Variable
:param variable_type: type to be set into Variable
:param name: Optional name for output node.
:return: ReadValue node
"""
attr_map = {"variable_id": variable_id}

if variable_type is not None:
attr_map["variable_type"] = variable_type

if variable_shape is not None:
attr_map["variable_shape"] = variable_shape

return _get_node_factory_opset6().create(
"ReadValue",
[as_node(init_value)],
{"variable_id": variable_id},
attr_map,
)

0 comments on commit 96e9a55

Please sign in to comment.