Skip to content

Commit

Permalink
Merge branch 'ci/gha/risc-v-sccache' of github.com:akashchi/openvino …
Browse files Browse the repository at this point in the history
…into ci/gha/risc-v-sccache
  • Loading branch information
akashchi committed Jan 26, 2024
2 parents 6232791 + f773109 commit 40d11ea
Show file tree
Hide file tree
Showing 147 changed files with 2,663 additions and 1,588 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/job_python_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install OpenVINO dependencies (Linux)
if: runner.os == 'Linux'
run: $INSTALL_DIR/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y
run: $INSTALL_DIR/install_dependencies/install_openvino_dependencies.sh -c=core -c=dev -y -c=gpu

- name: Fetch setup_python action
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ jobs:
Overall_Status:
name: ci/gha_overall_status
needs: [Smart_CI, Build, Debian_Packages, Samples, Conformance, ONNX_Runtime, CXX_Unit_Tests, Python_Unit_Tests,
CPU_Functional_Tests, TensorFlow_Hub_Models_Tests, PyTorch_Models_Tests, NVIDIA_Plugin, ONNX_Models]
CPU_Functional_Tests, TensorFlow_Hub_Models_Tests, PyTorch_Models_Tests, NVIDIA_Plugin]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from openvino.runtime.opset1.ops import exp
from openvino.runtime.opset9.ops import eye
from openvino.runtime.opset13.ops import fake_convert
from openvino.runtime.opset1.ops import fake_quantize
from openvino.runtime.opset13.ops import fake_quantize
from openvino.runtime.opset1.ops import floor
from openvino.runtime.opset1.ops import floor_mod
from openvino.runtime.opset8.ops import gather
Expand Down
58 changes: 57 additions & 1 deletion src/bindings/python/src/openvino/runtime/opset13/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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 apply_affix_on, binary_op, nameable_op, unary_op
from openvino.runtime.utils.types import (
NumericData,
NodeInput,
Expand Down Expand Up @@ -347,3 +347,59 @@ def result(data: Union[Node, Output, NumericData], name: Optional[str] = None) -
if isinstance(data, Node):
return Result(data.output(0))
return Result(data)


@nameable_op
@apply_affix_on("data", "input_low", "input_high", "output_low", "output_high")
def fake_quantize(
data: NodeInput,
input_low: NodeInput,
input_high: NodeInput,
output_low: NodeInput,
output_high: NodeInput,
levels: int,
auto_broadcast: str = "NUMPY",
name: Optional[str] = None,
*,
prefix: Optional[str] = None,
suffix: Optional[str] = None,
) -> Node:
r"""Perform an element-wise linear quantization on input data.
:param data: The node with data tensor.
:param input_low: The node with the minimum for input values.
:param input_high: The node with the maximum for input values.
:param output_low: The node with the minimum quantized value.
:param output_high: The node with the maximum quantized value.
:param levels: The number of quantization levels. Integer value.
:param auto_broadcast: The type of broadcasting specifies rules used for
auto-broadcasting of input tensors.
:param name: Optional name of the new node.
:param prefix: Optional keyword-only string to apply before original names of
all generated input nodes (for example: passed as numpy arrays).
:param suffix: Optional keyword-only string to apply after original names of
all generated input nodes (for example: passed as numpy arrays).
:return: New node with quantized value.
Input floating point values are quantized into a discrete set of floating point values.
.. code-block:: python
if x <= input_low:
output = output_low
if x > input_high:
output = output_high
else:
output = fake_quantize(output)
Fake quantize uses the following logic:
\f[ output =
\dfrac{round( \dfrac{data - input\_low}{(input\_high - input\_low)\cdot (levels-1)})}
{(levels-1)\cdot (output\_high - output\_low)} + output\_low \f]
"""
return _get_node_factory_opset13().create(
"FakeQuantize",
as_nodes(data, input_low, input_high, output_low, output_high),
{"levels": levels, "auto_broadcast": auto_broadcast.upper()},
)
30 changes: 29 additions & 1 deletion src/bindings/python/src/openvino/runtime/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# SPDX-License-Identifier: Apache-2.0

from functools import wraps
from typing import Any, Callable
from inspect import getfullargspec
from typing import Any, Callable, List

from openvino.runtime import Node, Output
from openvino.runtime.utils.types import NodeInput, as_node, as_nodes
Expand All @@ -27,6 +28,33 @@ def wrapper(*args: Any, **kwargs: Any) -> Node:
return wrapper


def _apply_affix(node: Node, prefix: str = "", suffix: str = "") -> Node:
node.friendly_name = prefix + node.friendly_name + suffix
return node


def apply_affix_on(*node_names: Any) -> Callable:
"""Add prefix and/or suffix to all openvino names of operators defined as arguments."""

def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Node:
arg_names = getfullargspec(func).args
arg_mapping = dict(zip(arg_names, args))
for node_name in node_names:
# Apply only on auto-generated nodes. Create such node and apply affixes.
# Any Node instance supplied by the user is keeping the name as-is.
if node_name in arg_mapping and not isinstance(arg_mapping[node_name], Node):
arg_mapping[node_name] = _apply_affix(as_node(arg_mapping[node_name]),
prefix=kwargs.get("prefix", ""),
suffix=kwargs.get("suffix", ""),
)
results = func(**arg_mapping, **kwargs)
return results
return wrapper
return decorator


def unary_op(node_factory_function: Callable) -> Callable:
"""Convert the first input value to a Constant Node if a numeric value is detected."""

Expand Down
109 changes: 109 additions & 0 deletions src/bindings/python/tests/test_graph/test_affix_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest
import re

import openvino.runtime.opset13 as ov
from openvino import Type


@pytest.mark.parametrize("prefix_string", [
"ABC",
"custom_prefix_",
])
@pytest.mark.parametrize("suffix_string", [
"XYZ",
"_custom_suffix",
])
def test_fake_quantize_affix_fails(prefix_string, suffix_string):
levels = np.int32(4)
data_shape = [1, 2, 3, 4]
bound_shape = []

data_name = "data"
parameter_data = ov.parameter(data_shape, name=data_name, dtype=np.float32)

input_low_name = "input_low"
parameter_input_low = ov.parameter(bound_shape, name=input_low_name, dtype=np.float32)

input_high_name = "input_high"
parameter_input_high = ov.parameter(bound_shape, name=input_high_name, dtype=np.float32)

output_low_name = "output_low"
parameter_output_low = ov.parameter(bound_shape, name=output_low_name, dtype=np.float32)

output_high_name = "output_high"
parameter_output_high = ov.parameter(bound_shape, name=output_high_name, dtype=np.float32)

model = ov.fake_quantize(
parameter_data,
parameter_input_low,
parameter_input_high,
parameter_output_low,
parameter_output_high,
levels,
prefix=prefix_string,
suffix=suffix_string,
)

# Check if node was created correctly
assert model.get_type_name() == "FakeQuantize"
assert model.get_output_size() == 1
assert list(model.get_output_shape(0)) == [1, 2, 3, 4]

assert data_name == parameter_data.friendly_name
assert input_low_name == parameter_input_low.friendly_name
assert input_high_name == parameter_input_high.friendly_name
assert output_low_name == parameter_output_low.friendly_name
assert output_high_name == parameter_output_high.friendly_name


@pytest.mark.parametrize("prefix_string", [
"",
"ABC",
"custom_prefix_",
])
@pytest.mark.parametrize("suffix_string", [
"",
"XYZ",
"_custom_suffix",
])
def test_fake_quantize_affix(prefix_string, suffix_string):
levels = np.int32(4)
data_shape = [1, 2, 3, 4]
bound_shape = [1]

a_arr = np.ones(data_shape, dtype=np.float32)
b_arr = np.array(bound_shape, dtype=np.float32)
c_arr = np.array(bound_shape, dtype=np.float32)
d_arr = np.array(bound_shape, dtype=np.float32)
e_arr = np.array(bound_shape, dtype=np.float32)

model = ov.fake_quantize(
a_arr,
b_arr,
c_arr,
d_arr,
e_arr,
levels,
prefix=prefix_string,
suffix=suffix_string,
)

# Check if node was created correctly
assert model.get_type_name() == "FakeQuantize"
assert model.get_output_size() == 1
assert list(model.get_output_shape(0)) == [1, 2, 3, 4]
# Check that data parameter and node itself do not change:
if prefix_string != "":
assert prefix_string not in model.friendly_name
if suffix_string != "":
assert suffix_string not in model.friendly_name
# Check that other parameters change:
for node_input in model.inputs():
generated_node = node_input.get_source_output().get_node()
assert prefix_string in generated_node.friendly_name
assert suffix_string in generated_node.friendly_name
4 changes: 2 additions & 2 deletions src/core/dev_api/validation_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ OPENVINO_API std::shared_ptr<op::v0::Constant> get_constant_from_source(const Ou
/// \brief Make scalar tensor which stores maximum value of ov::element::Type.
/// \param et Element type to get its maximum.
/// \return Tensor with maximum value.
Tensor make_tensor_of_max_value(const element::Type_t et);
OPENVINO_API Tensor make_tensor_of_max_value(const element::Type_t et);

/// \brief Make scalar tensor which stores minimum value of ov::element::Type.
/// \param et Element type to get its minimum.
/// \return Tensor with minimum value.
Tensor make_tensor_of_min_value(const element::Type_t et);
OPENVINO_API Tensor make_tensor_of_min_value(const element::Type_t et);

/// @brief Get the tensors shapes as ov::PartialShape.
///
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/ngraph/evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class NGRAPH_API_DEPRECATED Evaluator {
/// \brief Ensure value has been analyzed
class ValueInst : public Inst {
public:
ValueInst(const Output<Node>& value) : Inst(value.get_node()), m_index(value.get_index()) {}
ValueInst(const ov::Output<Node>& value) : Inst(value.get_node()), m_index(value.get_index()) {}

ValueInst(const RawNodeOutput& value) : Inst(value.node), m_index(value.index) {}

Expand Down Expand Up @@ -162,7 +162,7 @@ class NGRAPH_API_DEPRECATED Evaluator {

public:
/// \brief Determine information about value
V evaluate(const Output<Node>& value) {
V evaluate(const ov::Output<Node>& value) {
InstStack inst_stack;
inst_stack.push(InstPtr(new ValueInst(value)));
while (!inst_stack.empty()) {
Expand Down
16 changes: 9 additions & 7 deletions src/core/include/ngraph/graph_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool is_post_dominated(Node* X, Node* Y);

NGRAPH_API_DEPRECATED
NGRAPH_API
bool is_equal_to_const_value(const std::string& const_value, const Output<Node>& reduce_constant);
bool is_equal_to_const_value(const std::string& const_value, const ov::Output<Node>& reduce_constant);

// input nodes are cloned and returned
// NodeMap input may contain default node mapping i.e. pre-cloned nodes
Expand Down Expand Up @@ -156,15 +156,17 @@ void insert_new_node_between(const std::shared_ptr<Node>& src_node,

NGRAPH_API_DEPRECATED
NGRAPH_API
std::shared_ptr<Node> make_zero(const element::Type& element_type, const Shape& shape);
std::shared_ptr<Node> make_zero(const ov::element::Type& element_type, const ov::Shape& shape);

NGRAPH_API_DEPRECATED
NGRAPH_API
std::shared_ptr<Node> make_constant_from_string(std::string val, const element::Type& element_type, const Shape& shape);
std::shared_ptr<Node> make_constant_from_string(std::string val,
const ov::element::Type& element_type,
const ov::Shape& shape);

NGRAPH_API_DEPRECATED
NGRAPH_API
bool is_zero(const Output<Node>& reduce_constant);
bool is_zero(const ov::Output<Node>& reduce_constant);

NGRAPH_API_DEPRECATED
NGRAPH_API
Expand All @@ -182,7 +184,7 @@ NodeVector extract_subgraph(const NodeVector& results, const NodeVector& args);

NGRAPH_API_DEPRECATED
NGRAPH_API
bool is_one(const Output<Node>& reduce_constant);
bool is_one(const ov::Output<Node>& reduce_constant);

// Returns true if `node` is live in the graph i.e. a result op
// transitively uses this `node`
Expand Down Expand Up @@ -213,12 +215,12 @@ void plot_graph(std::shared_ptr<Function> f,
/// of `src`.
NGRAPH_API_DEPRECATED
NGRAPH_API
std::vector<Input<Node>> get_inputs_from(Node& src, Node& dst);
std::vector<ov::Input<Node>> get_inputs_from(Node& src, Node& dst);
/// \return A vector containing a handle for each output of src that is connected to an input
/// of `dst`.
NGRAPH_API_DEPRECATED
NGRAPH_API
std::vector<Output<Node>> get_outputs_to(Node& src, Node& dst);
std::vector<ov::Output<Node>> get_outputs_to(Node& src, Node& dst);

/// Checks the func for graph cycles starting from results going backwards, then from parameters
/// going forward.
Expand Down
1 change: 0 additions & 1 deletion src/core/include/ngraph/ngraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "ngraph/shape.hpp"
#include "ngraph/specialize_function.hpp"
#include "ngraph/type/element_type.hpp"
#include "ngraph/validation_util.hpp"
#include "openvino/core/descriptor/input.hpp"
#include "openvino/core/descriptor/output.hpp"
#include "openvino/core/descriptor/tensor.hpp"
Expand Down
4 changes: 1 addition & 3 deletions src/core/include/ngraph/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "ngraph/check.hpp"
#include "ngraph/coordinate_diff.hpp"
#include "ngraph/deprecated.hpp"
#include "ngraph/node_input.hpp"
#include "ngraph/node_output.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/output_vector.hpp"
#include "ngraph/strides.hpp"
Expand Down Expand Up @@ -90,7 +88,7 @@ using NodeTypeInfo = Node::type_info_t;
// Like an Output but with a Node* instead of a shared_ptr<Node>
using ov::RawNodeOutput;

using RawNodeOutputMap = std::map<RawNodeOutput, Output<Node>>;
using RawNodeOutputMap = std::map<RawNodeOutput, ov::Output<Node>>;

using ov::check_new_args_count;

Expand Down
29 changes: 0 additions & 29 deletions src/core/include/ngraph/node_input.hpp

This file was deleted.

Loading

0 comments on commit 40d11ea

Please sign in to comment.