Skip to content

Commit

Permalink
Merge branch 'master' into opt_out_gather_crop
Browse files Browse the repository at this point in the history
  • Loading branch information
byungilm authored Jun 14, 2023
2 parents 356bbdc + 5993c49 commit 28c0955
Show file tree
Hide file tree
Showing 26 changed files with 713 additions and 300 deletions.
35 changes: 34 additions & 1 deletion docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,40 @@ pre {
white-space: pre-wrap;
word-wrap: break-word;
}

/* Sphinx-design tabs override */

.sd-tab-set>input:checked+label {
border-color: var(--sd-color-tabs-underline-inactive);
color: var(--sd-color-info-text)!important;
background-color: rgb(0 104 181)!important;
}
.sd-tab-set>input:checked+label:hover {
color: --sd-color-info-text;
background-color: rgb(0,74,134)!important;
}
.sd-tab-set>input:not(:checked)+label:hover {
color: var(--sd-color-black)!important;
background-color: rgb(245, 245, 245)!important;
border-color: var(--sd-color-card-header)!important;
}
.sd-tab-set>label {
border-bottom: 0.125rem solid transparent;
margin-right: 10px!important;
margin-bottom: 8px;
color: var(--sd-color-black)!important;
border-color: var(--sd-color-tabs-underline-inactive);
cursor: pointer;
font-size: var(--sd-fontsize-tabs-label);
font-weight: 400!important;
padding: 5px 16px 2px!important;
transition: color 250ms;
width: auto;
z-index: 1;
}
.sd-tab-content {
box-shadow:none!important;
border-top: solid 2px var(--sd-color-tabs-overline)!important;
}

/* Navigation panels override */
/* =================================================== */
Expand Down
26 changes: 17 additions & 9 deletions docs/dev/build_linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ The software was validated on:
- [CMake](https://cmake.org/download/) 3.13 or higher
- GCC 7.5 or higher to build OpenVINO Runtime
- Python 3.7 - 3.11 for OpenVINO Runtime Python API
- (Optional) [Install Intel® Graphics Compute Runtime for OpenCL™ Driver package 23.13.26032.30](https://github.com/intel/compute-runtime/releases/tag/23.13.26032.30) to enable inference on Intel integrated GPUs.
- (Optional) Install Intel® Graphics Compute Runtime for OpenCL™ Driver package to enable inference on Intel integrated GPUs. Select a driver package from the table below depending on what version of Ubuntu you are installing on.

| Ubuntu | Driver package |
| --- | ----------- |
| 22.04 | [23.13.26032.30](https://github.com/intel/compute-runtime/releases/tag/23.13.26032.30) |
| 20.04 | [22.24.23453](https://github.com/intel/compute-runtime/releases/tag/22.24.23453) |
| 18.04 | [21.38.21026](https://github.com/intel/compute-runtime/releases/tag/21.38.21026) |

## How to build

Expand All @@ -36,17 +42,17 @@ The software was validated on:
```sh
sudo ./install_build_dependencies.sh
```
> **NOTE**: By default, the build enables the OpenVINO Runtime GPU plugin to infer models on your Intel® Processor Graphics. This requires you to [Install Intel® Graphics Compute Runtime for OpenCL™ Driver package 23.13.26032.30](https://github.com/intel/compute-runtime/releases/tag/23.13.26032.30) before running the build. If you don't want to use the GPU plugin, use the `-DENABLE_INTEL_GPU=OFF` CMake build option and skip the installation of the Intel® Graphics Compute Runtime for OpenCL™ Driver.

3. Create a build folder:
```sh
mkdir build && cd build
```
```sh
mkdir build && cd build
```

4. OpenVINO Runtime uses a CMake-based build system. In the created `build` directory, run `cmake` to fetch project dependencies and create Unix makefiles, then run `make` to build the project:
```sh
cmake -DCMAKE_BUILD_TYPE=Release ..
make --jobs=$(nproc --all)
```
```sh
cmake -DCMAKE_BUILD_TYPE=Release ..
make --jobs=$(nproc --all)
```
The process may take some time to finish.

### Additional Build Options
Expand All @@ -59,6 +65,8 @@ You can use the following additional build options:
cmake -DCMAKE_TOOLCHAIN_FILE=<openvino_repo>/cmake/toolchains/ia32.linux.toolchain.cmake ..
```

- If you don't want to use the GPU plugin, use the `-DENABLE_INTEL_GPU=OFF` CMake build option and skip the installation of the Intel® Graphics Compute Runtime for OpenCL™ Driver.

- To build the OpenVINO Runtime Python API:
1. Install all additional packages (e.g., cython and opencv) listed in the `/src/bindings/python/src/compatibility/openvino/requirements-dev.txt` file:
```sh
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/001-hello-world-with-output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Load an Image
# Reshape to model input shape.
input_image = np.expand_dims(input_image, 0)
plt.imshow(image);
plt.imshow(image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __str__(self):
@mock_needed
def test_load_by_model():
clear_all_stat()
fe = fem.load_by_model(model_path="abc.test_mock_py_mdl")
fe = fem.load_by_model(model="abc.test_mock_py_mdl")
assert fe is not None
assert fe.get_name() == MOCK_PY_FRONTEND_NAME
stat = get_fe_stat()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#pragma once

#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/pattern/matcher.hpp"

#include "snippets/op/subgraph.hpp"

namespace ov {
namespace snippets {
Expand All @@ -15,6 +16,12 @@ class CommonOptimizations : public ov::pass::MatcherPass {
public:
OPENVINO_RTTI("CommonOptimizations", "0");
CommonOptimizations();

private:
// Move up Constants which aren't scalars from body to Subgraph and replace them with Parameters inside body
void ExtractConstants(const std::shared_ptr<op::Subgraph>& subgraph);
// Move up unsupported Transposes on Parameter outputs from body
void ExtractUnsupportedTransposes(const std::shared_ptr<op::Subgraph>& subgraph);
};

} // namespace pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,32 @@
#pragma once

#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/pattern/matcher.hpp"

namespace ov {
namespace snippets {
namespace pass {

/**
* @interface ExplicitTransposeMatMulInputs
* @brief At the moment Snippets supports Transpose only with order {0, 2, 3, 1},
* so if there is pattern in graph:
* in0 Transpose{0, 2, 1, 3}
* \ /
* MatMul[false, true]
* We can set false in MatMul parameter `transposed_b` and
* change Transpose order to {0, 2, 3, 1} which is supported by Snippets
* @brief The pass extracts explicit Transpose node from MatMul with transposed_<a|b> and moves it to Parameter.
* If there is another Transpose, the pass fuses extracted Transpose and existing Transpose.
* For example, At the moment Snippets supports Transpose only with order {0, 2, 3, 1}, so if there is pattern in graph:
* in0 Transpose{0, 2, 1, 3}
* \ /
* MatMul[false, true]
* We can set `false` in MatMul parameter `transposed_b` and change Transpose order to {0, 2, 3, 1} which is supported by Snippets
* @ingroup snippets
*/
class ExplicitTransposeMatMulInputs: public ov::pass::MatcherPass {
public:
OPENVINO_RTTI("ExplicitTransposeMatMulInputs", "0");
ExplicitTransposeMatMulInputs();

// Return `True` if all inputs (except 0-th input) have scalar shape. Otherwise returns `False`
static bool are_weights_scalar(const std::shared_ptr<ov::Node>& node);

private:
static void extract(const ov::Input<ov::Node>& input);
};

} // namespace pass
Expand Down
78 changes: 62 additions & 16 deletions src/common/snippets/src/pass/common_optimizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@

#include "snippets/pass/common_optimizations.hpp"

#include <memory>
#include "openvino/opsets/opset1.hpp"
#include <ngraph/pass/constant_folding.hpp>
#include "openvino/pass/pattern/op/wrap_type.hpp"

#include "transformations/utils/utils.hpp"
#include "snippets/pass/fq_decomposition.hpp"
#include "snippets/pass/softmax_reshape_elimination.hpp"
#include "snippets/pass/explicit_transpose_matmul_inputs.hpp"
#include "snippets/pass/transpose_decomposition.hpp"
#include "snippets/pass/fuse_transpose_brgemm.hpp"
#include "snippets/op/subgraph.hpp"
#include "snippets/utils.hpp"
#include "snippets/itt.hpp"

#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/utils/utils.hpp"

namespace ov {
namespace snippets {
namespace pass {


// Move up Constants which aren't scalars from body to Subgraph and replace them with Parameters inside body
void ConvertConstantsToParameters(const std::shared_ptr<ov::snippets::op::Subgraph>& subgraph) {
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::ConvertConstantsToParameters");
void CommonOptimizations::ExtractConstants(const std::shared_ptr<ov::snippets::op::Subgraph>& subgraph) {
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::ExtractConstants");
auto body = subgraph->body_ptr();

ParameterVector new_parameters;
Expand Down Expand Up @@ -55,6 +52,52 @@ void ConvertConstantsToParameters(const std::shared_ptr<ov::snippets::op::Subgra
}
}

void CommonOptimizations::ExtractUnsupportedTransposes(const std::shared_ptr<op::Subgraph>& subgraph) {
OV_ITT_SCOPED_TASK(ov::pass::itt::domains::SnippetsTransform, "Snippets::ExtractUnsupportedTransposes");
const auto& body = subgraph->body_ptr();
const auto parameters = body->get_parameters();
// [107806]: If count of Parameters isn't equal to Subgraph inputs,
// we cannot guarantee correct extraction since we don't have correct connections between body I/O and Subgraph I/O.
OPENVINO_ASSERT(parameters.size() == subgraph->input_values().size(),
"Failed to extract unsupported transposes: the count of Parameters isn't equal to Subgraph inputs");

bool updated = false;
for (size_t i = 0; i < parameters.size(); ++i) {
const auto& parameter = parameters[i];
const auto& consumers = parameter->get_output_target_inputs(0);
if (consumers.size() != 1)
continue;

const auto transpose = ov::as_type_ptr<opset1::Transpose>(consumers.begin()->get_node()->shared_from_this());
if (!transpose)
continue;

const auto& order = ov::as_type_ptr<opset1::Constant>(transpose->get_input_node_shared_ptr(1));
if (!order)
continue;

const auto order_value = order->cast_vector<int>();
const auto transpose_child = *(transpose->get_output_target_inputs(0).begin());
const auto is_brgemm_case = ov::is_type<opset1::MatMul>(transpose_child.get_node()->shared_from_this());
// If Transpose is supported (can be decomposed or fused into Brgemm), skip
if ((is_brgemm_case && FuseTransposeBrgemm::supported_cases.count(order_value) != 0) ||
(TransposeDecomposition::supported_cases.count(order_value) != 0))
continue;

// If the transpose isn't supported - we have to extract it from Subgraph
transpose->set_argument(0, subgraph->input_value(i));
subgraph->set_argument(i, transpose);
transpose_child.replace_source_output(parameter);
// Update shape
parameter->set_partial_shape(transpose->get_output_partial_shape(0));
updated = true;
}

if (updated) {
subgraph->validate_and_infer_types();
}
}

CommonOptimizations::CommonOptimizations() {
MATCHER_SCOPE(CommonOptimizations);
ov::graph_rewrite_callback callback = [this](ov::pass::pattern::Matcher& m) {
Expand All @@ -65,10 +108,10 @@ CommonOptimizations::CommonOptimizations() {
return false;
}

auto body = subgraph->body_ptr();
const auto& body = subgraph->body_ptr();
const auto is_quantized = subgraph->is_quantized();

// Firsly we should transform all original Converts inside body to ConvertTruncation to save original behavior.
// Firstly, we should transform all original Converts inside body to ConvertTruncation to save original behavior.
// Then if Subgraph contains FakeQuantize we enable specific transformation for quantized subgraphs.
ov::pass::Manager manager;
manager.register_pass<ov::snippets::pass::TransformConvertToConvertTruncation>();
Expand All @@ -80,15 +123,18 @@ CommonOptimizations::CommonOptimizations() {
manager.run_passes(body);

// At the moment only non-scalar Constants of FakeQuantize can be inside Subgraph
// so we can enable ConvertConstantsToParameters pass for quantized models
// so we can enable ExtractConstants pass for quantized models
if (is_quantized) {
ConvertConstantsToParameters(subgraph);
ExtractConstants(subgraph);
}
// Extract unsupported Transposes from body
if (subgraph->has_domain_sensitive_ops()) {
ExtractUnsupportedTransposes(subgraph);
}
return true;
};

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

Expand Down
Loading

0 comments on commit 28c0955

Please sign in to comment.