Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into azure-python
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Oct 13, 2023
2 parents 704732d + 44a3255 commit b080b19
Show file tree
Hide file tree
Showing 67 changed files with 1,663 additions and 1,696 deletions.
33 changes: 16 additions & 17 deletions .ci/azure/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ jobs:
CMAKE_VERSION: 3.24.0
CMAKE_CMD: $(WORK_DIR)\cmake-$(CMAKE_VERSION)-windows-x86_64\cmake-$(CMAKE_VERSION)-windows-x86_64\bin\cmake.exe
OV_CMAKE_TOOLCHAIN_FILE: $(REPO_DIR)\cmake\toolchains\mt.runtime.win32.toolchain.cmake
PYTHON_DIR: C:\hostedtoolcache\windows\Python\3.8.2\x64

PYTHON_EXE: C:\hostedtoolcache\windows\Python\3.8.2\x64\python.exe

steps:
- script: |
Expand All @@ -82,8 +81,8 @@ jobs:
- script: |
powershell -command "Invoke-RestMethod -Headers @{\"Metadata\"=\"true\"} -Method GET -Uri http://169.254.169.254/metadata/instance/compute?api-version=2019-06-01 | format-custom"
where python
python --version
where $(PYTHON_EXE)
$(PYTHON_EXE) --version
where java
java -version
wmic computersystem get TotalPhysicalMemory
Expand All @@ -104,20 +103,20 @@ jobs:
path: openvino_contrib

- script: |
python -m pip install --upgrade pip
$(PYTHON_EXE) -m pip install --upgrade pip
rem For running Python API tests
python -m pip install -r $(REPO_DIR)\src\bindings\python\src\compatibility\openvino\requirements-dev.txt
python -m pip install -r $(REPO_DIR)\src\bindings\python\wheel\requirements-dev.txt
python -m pip install -r $(REPO_DIR)\src\bindings\python\requirements.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\src\compatibility\openvino\requirements-dev.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\wheel\requirements-dev.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\bindings\python\requirements.txt
rem For running Paddle frontend unit tests
python -m pip install -r $(REPO_DIR)\src\frontends\paddle\tests\requirements.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\paddle\tests\requirements.txt
rem For running ONNX frontend unit tests
python -m pip install -r $(REPO_DIR)\src\frontends\onnx\tests\requirements.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\onnx\tests\requirements.txt
rem For running TensorFlow frontend unit tests
python -m pip install -r $(REPO_DIR)\src\frontends\tensorflow\tests\requirements.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\src\frontends\tensorflow\tests\requirements.txt
rem For MO unit tests
python -m pip install -r $(REPO_DIR)\tools\mo\requirements.txt
python -m pip install -r $(REPO_DIR)\tools\mo\requirements_dev.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\tools\mo\requirements.txt
$(PYTHON_EXE) -m pip install -r $(REPO_DIR)\tools\mo\requirements_dev.txt
rem Speed up build
powershell -command "Invoke-WebRequest https://github.com/Kitware/CMake/releases/download/v$(CMAKE_VERSION)/cmake-$(CMAKE_VERSION)-windows-x86_64.zip -OutFile cmake-$(CMAKE_VERSION)-windows-x86_64.zip"
powershell -command "Expand-Archive -Force cmake-$(CMAKE_VERSION)-windows-x86_64.zip"
Expand All @@ -142,7 +141,7 @@ jobs:
-DENABLE_TESTS=ON ^
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON ^
-DENABLE_STRICT_DEPENDENCIES=OFF ^
-DPython3_EXECUTABLE=$(PYTHON_DIR)\python.exe ^
-DPython3_EXECUTABLE=$(PYTHON_EXE) ^
-DENABLE_PYTHON=ON ^
-DBUILD_nvidia_plugin=OFF ^
-DCUSTOM_OPERATIONS="calculate_grid;complex_mul;fft;grid_sample;sparse_conv;sparse_conv_transpose" ^
Expand Down Expand Up @@ -170,7 +169,7 @@ jobs:
- script: dir $(INSTALL_DIR) /s
displayName: 'List install files'

- script: python -m pip install openvino-dev --find-links=$(INSTALL_DIR)\tools
- script: $(PYTHON_EXE) -m pip install openvino-dev --find-links=$(INSTALL_DIR)\tools
displayName: 'Install Wheels'

- script: |
Expand All @@ -195,12 +194,12 @@ jobs:
if not exist %USERPROFILE%\Documents\Intel\OpenVINO\openvino_c_samples_build\ exit 1
displayName: 'Build c samples'
- script: python -m pip install -r $(INSTALL_TEST_DIR)\smoke_tests\requirements.txt
- script: $(PYTHON_EXE) -m pip install -r $(INSTALL_TEST_DIR)\smoke_tests\requirements.txt
displayName: 'Install dependencies for samples smoke tests'

- script: |
call $(SETUPVARS) && ^
python -m pytest $(INSTALL_DIR)\tests\smoke_tests\ --env_conf $(INSTALL_TEST_DIR)\smoke_tests\env_config.yml -s --junitxml=$(INSTALL_TEST_DIR)/TEST-SamplesSmokeTests.xml
$(PYTHON_EXE) -m pytest $(INSTALL_DIR)\tests\smoke_tests\ --env_conf $(INSTALL_TEST_DIR)\smoke_tests\env_config.yml -s --junitxml=$(INSTALL_TEST_DIR)/TEST-SamplesSmokeTests.xml
env:
IE_APP_PATH: $(INSTALL_DIR)\samples_bin
IE_APP_PYTHON_PATH: $(INSTALL_DIR)\samples\python\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ function( _find_cython_executable )
get_filename_component( _python_path ${Python3_EXECUTABLE} PATH )
file(TO_CMAKE_PATH "$ENV{HOME}" ENV_HOME)
find_host_program( CYTHON_EXECUTABLE
NAMES cython cython.bat cython3
HINTS ${_python_path} ${ENV_HOME}/.local/bin $ENV{HOMEBREW_OPT}/cython/bin
NAMES cython cython.exe cython.bat cython3
HINTS ${_python_path}
${ENV_HOME}/.local/bin
$ENV{HOMEBREW_OPT}/cython/bin
${ENV_HOME}/Library/Python/${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/bin
${_python_path}/Scripts
)
else()
find_host_program( CYTHON_EXECUTABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
from openvino.runtime.opset4.ops import mish
from openvino.runtime.opset1.ops import mod
from openvino.runtime.opset9.ops import multiclass_nms
from openvino.runtime.opset13.ops import multinomial
from openvino.runtime.opset1.ops import multiply
from openvino.runtime.opset6.ops import mvn
from openvino.runtime.opset1.ops import negative
Expand Down
41 changes: 41 additions & 0 deletions src/bindings/python/src/openvino/runtime/opset13/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,47 @@ def bitwise_xor(
)


@nameable_op
def multinomial(
probs: NodeInput,
num_samples: NodeInput,
convert_type: str,
with_replacement: bool,
log_probs: bool,
global_seed: int = 0,
op_seed: int = 0,
) -> Node:
"""Return a node which generates a sequence of class indices sampled from the multinomial distribution.
:param probs: Tensor with probabilities of floating-point type, and shape [class_size] or [batch_size, class_size].
:param num_samples: Tensor (scalar or 1D) a single element of type i32 or i64,
specifying the number of samples to draw from the multinomial distribution.
:param convert_type: Specifies the output tensor type, possible values: 'i64', 'i32'.
:param with_replacement: Flag that specifies whether to sample with replacement.
:param log_probs: Flag that specifies whether *probs* should be treated as unnormalized log probabilities.
:param global_seed: Specifies global seed value. Required to be a positive integer or 0.
:param op_seed: Specifies operational seed value. Required to be a positive integer or 0.
:return: The new node performing Multinomial operation.
"""
inputs = as_nodes(probs, num_samples)

if global_seed < 0:
raise RuntimeError(f"global_seed should be positive or 0. Got: {global_seed}")

if op_seed < 0:
raise RuntimeError(f"op_seed should be positive or 0. Got: {op_seed}")

attributes = {
"convert_type": convert_type,
"with_replacement": with_replacement,
"log_probs": log_probs,
"global_seed": global_seed,
"op_seed": op_seed,
}
return _get_node_factory_opset13().create("Multinomial", inputs, attributes)


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

import numpy as np
import pytest

import openvino.runtime.opset13 as ops
from openvino.runtime import PartialShape, Dimension, Type


@pytest.mark.parametrize(
("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"),
[
([4, 16], [], "i32", False, True, 7461, 1546, PartialShape([4, -1])),
([8], [1], "i64", True, False, 0, 0, PartialShape([-1])),
],
)
def test_multinomial_param_inputs(probs_shape, num_samples_shape, convert_type, with_replacement, log_probs, global_seed, op_seed, expected_out_shape):
probs = ops.parameter(probs_shape, dtype=np.float32)
num_samples = ops.parameter(num_samples_shape, dtype=np.int32)

op = ops.multinomial(probs, num_samples,
convert_type=convert_type,
with_replacement=with_replacement,
log_probs=log_probs,
global_seed=global_seed,
op_seed=op_seed)
assert op.get_output_size() == 1
assert op.get_type_name() == "Multinomial"
assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64
assert op.get_output_partial_shape(0) == expected_out_shape


@pytest.mark.parametrize(
("probs_array", "num_samples_val", "convert_type", "with_replacement", "log_probs", "global_seed", "op_seed", "expected_out_shape"),
[
(np.array([0.7, 0.3, 0.6, 0.5]), 3, "i32", False, True, 111, 222, PartialShape([3])),
(np.array([[0.7, 0.3], [0.6, 0.5]]), 2, "i64", True, False, 111, 222, PartialShape([2, 2])),
],
)
def test_multinomial_const_inputs(probs_array, num_samples_val, convert_type, with_replacement, log_probs, global_seed, op_seed, expected_out_shape):
probs = ops.constant(probs_array, dtype=np.float32)
num_samples = ops.constant(num_samples_val, dtype=np.int32)

op = ops.multinomial(probs, num_samples,
convert_type=convert_type,
with_replacement=with_replacement,
log_probs=log_probs,
global_seed=global_seed,
op_seed=op_seed)

assert op.get_output_size() == 1
assert op.get_type_name() == "Multinomial"
assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64
assert op.get_output_partial_shape(0) == expected_out_shape


@pytest.mark.parametrize(
("probs_shape", "num_samples_shape", "convert_type", "with_replacement", "log_probs", "expected_out_shape"),
[
([10], [1], "i32", True, True, PartialShape([-1])),
([2, 16], [], "i64", False, False, PartialShape([2, -1])),
],
)
def test_multinomial_default_attrs(probs_shape, num_samples_shape, convert_type, with_replacement, log_probs, expected_out_shape):
probs = ops.parameter(probs_shape, dtype=np.float32)
num_samples = ops.parameter(num_samples_shape, dtype=np.int32)

op = ops.multinomial(probs, num_samples,
convert_type=convert_type,
with_replacement=with_replacement,
log_probs=log_probs)

assert op.get_output_size() == 1
assert op.get_type_name() == "Multinomial"
assert op.get_output_element_type(0) == Type.i32 if convert_type == "i32" else Type.i64
assert op.get_output_partial_shape(0) == expected_out_shape
5 changes: 5 additions & 0 deletions src/core/dev_api/validation_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ bool try_apply_auto_padding(const PartialShape& image_shape,
CoordinateDiff& padding_above,
CoordinateDiff& padding_below);

/// @brief Get the tensors shapes as ov::PartialShape.
///
/// @param tensors Input tensors vector to get their shapes.
/// @return Vector of partial shapes same size as input tensor vector.
OPENVINO_API std::vector<PartialShape> get_tensors_partial_shapes(const TensorVector& tensors);
} // namespace util
} // namespace ov
22 changes: 9 additions & 13 deletions src/core/include/openvino/core/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,21 +554,17 @@ OPENVINO_API void NodeValidationFailure::create(const CheckLocInfo& check_loc_in
NODE_VALIDATION_CHECK(std::make_pair(static_cast<const ::ov::Node*>((node)), &(input_shapes)), __VA_ARGS__)

namespace ov {
template <typename T>
void check_new_args_count(const Node* node, T new_args) {
NODE_VALIDATION_CHECK(node,
new_args.size() == node->input_values().size(),
"clone_with_new_inputs() expected ",
node->input_values().size(),
" argument",
(node->input_values().size() == 1 ? "" : "s"),
" but got ",
new_args.size());
}

} // namespace ov
/**
* @brief Check new arguments size if match node inputs count.
*
* This check is required in cloning ov::Node.
*
* @param node Pointer to node.
* @param new_args Vector with new outputs to check.
*/
void OPENVINO_API check_new_args_count(const Node* const node, const OutputVector& new_args);

namespace ov {
/// \brief Visits a reference to a node that has been registered with the visitor.
template <>
class OPENVINO_API AttributeAdapter<std::shared_ptr<ov::Node>> : public VisitorAdapter {
Expand Down
22 changes: 9 additions & 13 deletions src/core/include/openvino/core/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ class Shape : public std::vector<size_t> {
OPENVINO_API std::string to_string() const;
};

/**
* @brief Number of elements in spanned by a shape
* @ingroup ov_model_cpp_api
*/
template <typename SHAPE_TYPE>
size_t shape_size(const SHAPE_TYPE& shape) {
size_t size = 1;
for (auto d : shape) {
size *= d;
}
return size;
}

/**
* Number of elements in a subset of dimensions of a shape.
* Returns a product of dimensions in a range [start_dim;end_dim)
Expand All @@ -72,6 +59,15 @@ size_t shape_size(ForwardIt start_dim, const ForwardIt end_dim) {
std::multiplies<typename std::iterator_traits<ForwardIt>::value_type>());
}

/**
* @brief Number of elements in spanned by a shape
* @ingroup ov_model_cpp_api
*/
template <typename SHAPE_TYPE>
size_t shape_size(const SHAPE_TYPE& shape) {
return shape_size(shape.begin(), shape.end());
}

/// Row-major strides for a shape
template <typename SHAPE_TYPE>
std::vector<size_t> row_major_strides(const SHAPE_TYPE& shape) {
Expand Down
16 changes: 5 additions & 11 deletions src/core/include/openvino/op/topk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OPENVINO_API TopK : public util::TopKBase {
/// the biggest element of two.
/// \param sort Specifies order of output elements and/or indices
/// Accepted values: none, index, value
/// \param index_element_type Specyfies type of produced indices
/// \param index_element_type Specifies type of produced indices
TopK(const Output<Node>& data,
const Output<Node>& k,
const int64_t axis,
Expand All @@ -53,9 +53,7 @@ class OPENVINO_API TopK : public util::TopKBase {

std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
bool has_evaluate() const override;

protected:
Expand Down Expand Up @@ -83,7 +81,7 @@ class OPENVINO_API TopK : public util::TopKBase {
/// the biggest element of two.
/// \param sort Specifies order of output elements and/or indices
/// Accepted values: none, index, value
/// \param index_element_type Specyfies type of produced indices
/// \param index_element_type Specifies type of produced indices
TopK(const Output<Node>& data,
const Output<Node>& k,
const int64_t axis,
Expand All @@ -99,9 +97,7 @@ class OPENVINO_API TopK : public util::TopKBase {
const element::Type& index_element_type = element::i32);
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
bool has_evaluate() const override;
};
} // namespace v3
Expand Down Expand Up @@ -153,9 +149,7 @@ class OPENVINO_API TopK : public util::TopKBase {
bool visit_attributes(AttributeVisitor& visitor) override;
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;

OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END
bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override;
bool has_evaluate() const override;

bool get_stable() const {
Expand Down
23 changes: 0 additions & 23 deletions src/core/include/openvino/op/util/evaluate_helpers.hpp

This file was deleted.

Loading

0 comments on commit b080b19

Please sign in to comment.