Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into flush_interim_tensors
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnick committed Aug 20, 2024
2 parents f570550 + db22d0a commit 5b9d05a
Show file tree
Hide file tree
Showing 175 changed files with 9,020 additions and 7,395 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dev_cpu_linux_snippets_libxsmm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- 'src/plugins/intel_cpu/src/emitters/tpp/**'
- 'src/plugins/intel_cpu/src/transformations/snippets/**'
- 'src/plugins/intel_cpu/src/transformations/tpp/**'
- 'src/plugins/intel_cpu/tests/unit/snippets_transformations/**'
- 'src/plugins/intel_cpu/tests/functional/shared_tests_instances/snippets/**'

concurrency:
group: ${{ github.event_name == 'push' && github.run_id || github.ref }}-linux-cpu-dev
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/job_pytorch_models_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ jobs:
TEST_DEVICE: CPU
USE_SYSTEM_CACHE: False

- name: RoPE Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
export PYTHONPATH=${MODEL_HUB_TESTS_INSTALL_DIR}:$PYTHONPATH
python3 -m pytest ${MODEL_HUB_TESTS_INSTALL_DIR}/transformation_tests/test_transformations.py -m precommit --html=${INSTALL_TEST_DIR}/TEST-torch_rope_tests.html --self-contained-html -v --tb=short -n 2
env:
TEST_DEVICE: CPU
USE_SYSTEM_CACHE: False

- name: StatefulToStateless Test
if: ${{ inputs.model_scope == 'precommit' }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows_conditional_compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
-DCMAKE_COMPILE_WARNING_AS_ERROR=ON `
-DENABLE_PROFILING_ITT=ON `
-DSELECTIVE_BUILD=COLLECT `
-DENABLE_FASTER_BUILD=ON `
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=ON `
-DCMAKE_TOOLCHAIN_FILE=${{ env.ONECORE_TOOLCHAIN }} `
-S ${{ env.OPENVINO_REPO }} `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ Convert Tokenizers:
tokenizer_dir = Path("tokenizer/")
core = Core()
ov_tokenizer = core.read_model(tokenizer_dir / "openvino_tokenizer")
ov_detokenizer = core.read_model(tokenizer_dir / "openvino_detokenizer")
ov_tokenizer = core.read_model(tokenizer_dir / "openvino_tokenizer.xml")
ov_detokenizer = core.read_model(tokenizer_dir / "openvino_detokenizer.xml")
tokenizer, detokenizer = core.compile_model(ov_tokenizer), core.compile_model(ov_detokenizer)
Expand Down Expand Up @@ -278,7 +278,7 @@ You can find more information and code snippets in the `OpenVINO Tokenizers Note

.. code-block:: python
input numpy as np
import numpy as np
text_input = ["Quick brown fox jumped"]
Expand Down
152 changes: 86 additions & 66 deletions src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions src/bindings/python/src/openvino/frontend/pytorch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def fetch_attr(self_module, target: str):
Return:
Any: The value of the attribute.
"""
target_atoms = target.split('.')
target_atoms = target.split(".")
attr_itr = self_module
for i, atom in enumerate(target_atoms):
if not hasattr(attr_itr, atom):
Expand Down Expand Up @@ -91,12 +91,13 @@ def get_value_from_getattr(getattr_node, self_module):
node = stack.pop()
attr_name = node.s("name")
assert hasattr(
module, attr_name), f"No attribute with name \"{attr_name}\" found in module."
module, attr_name), f'No attribute with name "{attr_name}" found in module.'
path_name = ".".join([path_name, attr_name])
module = getattr(module, attr_name)
return module, path_name

def graph_has_ops(graph, op_types:list) -> bool:

def graph_has_ops(graph, op_types: list) -> bool:
res = False
for n in graph.nodes():
if any(kind in n.kind() for kind in op_types):
Expand All @@ -106,7 +107,7 @@ def graph_has_ops(graph, op_types:list) -> bool:
if res:
return res
return res


pt_to_ov_type_map = {
"float": OVType.f32,
Expand Down Expand Up @@ -134,7 +135,7 @@ def graph_has_ops(graph, op_types:list) -> bool:
"torch.BoolTensor": OVType.boolean,
"torch.quint8": OVType.u8,
"torch.qint8": OVType.i8,
"torch.qint32": OVType.i32
"torch.qint32": OVType.i32,
}


Expand All @@ -159,7 +160,7 @@ def process_dict_inputs(inputs, input_params, model):
ordered_inputs.append(input_name)

input_signature = list(input_params)
if ordered_inputs == input_signature[:len(ordered_inputs)]:
if ordered_inputs == input_signature[: len(ordered_inputs)]:
example_inputs = [inputs[input_name] for input_name in ordered_inputs]
if all([isinstance(inp, torch.Tensor) for inp in example_inputs]):
return {"example_inputs": [inputs[name] for name in ordered_inputs]}, ordered_inputs, model
Expand Down Expand Up @@ -191,8 +192,8 @@ def process_dict_inputs(inputs, input_params, model):
str(input_params[input_name]).replace("NoneType", "None"))
input_params_str.append(f"{input_name}={input_name}")

wrapper_class = wrapper_template.format(input_sign=', '.join(
input_sign_str), example_input=', '.join(input_params_str))
wrapper_class = wrapper_template.format(input_sign=", ".join(
input_sign_str), example_input=", ".join(input_params_str))
result = {}
try:
exec(wrapper_class, result)
Expand All @@ -210,7 +211,8 @@ def prepare_example_inputs_and_model(inputs, input_params, model):
input_is_list = False
input_signature = list(input_params)
if isinstance(inputs, dict):
examples, ordered, wrapped = process_dict_inputs(inputs, input_params, model)
examples, ordered, wrapped = process_dict_inputs(
inputs, input_params, model)
return examples, ordered, wrapped, input_is_list
if isinstance(inputs, list) and len(inputs) == 1 and isinstance(inputs[0], torch.Tensor):
if "typing.List" in str(input_params[input_signature[0]].annotation):
Expand All @@ -219,7 +221,7 @@ def prepare_example_inputs_and_model(inputs, input_params, model):

if isinstance(inputs, torch.Tensor):
inputs = [inputs]
input_signature = input_signature[:len(inputs)]
input_signature = input_signature[: len(inputs)]
return {"example_inputs": inputs}, input_signature, model, input_is_list


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <memory>

#include "layer_transformation.hpp"

namespace ov {
namespace pass {
namespace low_precision {

/**
* @ingroup ov_transformation_common_api
* @brief SliceTransformation propagates dequantization operations through Slice operation.
*
* For more details about the transformation, refer to
* [SliceTransformation](@ref openvino_docs_OV_UG_lpt_SliceTransformation) page
* in the OpenVINO Developer Guide.
*/
class LP_TRANSFORMATIONS_API SliceTransformation : public LayerTransformation {
public:
OPENVINO_RTTI("SliceTransformation", "0");
SliceTransformation(const Params& params = Params());
bool transform(TransformationContext& context, ov::pass::pattern::Matcher& m) override;
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> op) const override;
bool isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept override;
};

} // namespace low_precision
} // namespace pass
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "low_precision/relu.hpp"
#include "low_precision/squeeze.hpp"
#include "low_precision/subtract.hpp"
#include "low_precision/slice.hpp"
#include "low_precision/space_to_batch.hpp"
#include "low_precision/split.hpp"
#include "low_precision/shuffle_channels.hpp"
Expand Down Expand Up @@ -267,6 +268,7 @@ bool ov::pass::low_precision::LowPrecision::run_on_model(const std::shared_ptr<o
ADD_MATCHER(common, ReshapeTransformation, params)
ADD_MATCHER(common, SqueezeTransformation, params)
ADD_MATCHER(common, ShuffleChannelsTransformation, params)
ADD_MATCHER(common, SliceTransformation, params)
ADD_MATCHER(common, SpaceToBatchTransformation, params)
ADD_MATCHER(common, SplitTransformation, params)
ADD_MATCHER(common, StridedSliceTransformation, params)
Expand Down
67 changes: 67 additions & 0 deletions src/common/low_precision_transformations/src/slice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <memory>

#include "low_precision/slice.hpp"

#include "itt.hpp"
#include "openvino/util/log.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/opsets/opset8.hpp"

#include "low_precision/network_helper.hpp"

namespace ov {
namespace pass {
namespace low_precision {

SliceTransformation::SliceTransformation(const Params& params) : LayerTransformation(params) {
MATCHER_SCOPE(SliceTransformation);
auto matcher = ov::pass::pattern::wrap_type<ov::opset8::Slice>();

ov::graph_rewrite_callback callback = [this](pattern::Matcher& m) {
auto op = m.get_match_root();
if (transformation_callback(op)) {
return false;
}
return transform(*context, m);
};

auto m = std::make_shared<ov::pass::pattern::Matcher>(matcher, matcher_name);
this->register_matcher(m, callback);
}

bool SliceTransformation::transform(TransformationContext& context, ov::pass::pattern::Matcher& m) {
if (!SliceTransformation::canBeTransformed(context, m.get_match_root())) {
return false;
}

const auto strided_slice = NetworkHelper::separateInStandaloneBranch(m.get_match_root(), defaultPrecisions);
auto dequantization = NetworkHelper::getDequantization(strided_slice, defaultPrecisions);
const auto newOperation = moveDequantizationAfter(context, strided_slice, NetworkHelper::getDequantization(strided_slice, defaultPrecisions));

OPENVINO_DEBUG("LPT: done: ", newOperation);
return true;
}

bool SliceTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> operation) const {
if (!LayerTransformation::canBeTransformed(context, operation)) {
return false;
}

if (!ov::is_type<ov::opset8::Slice>(operation)) {
return false;
}

const auto dequantization = NetworkHelper::getDequantization(operation);
return dequantization.isPerTensor();
}

bool SliceTransformation::isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept {
return true;
}
} // namespace low_precision
} // namespace pass
} // namespace ov
Loading

0 comments on commit 5b9d05a

Please sign in to comment.