Skip to content

Commit c101c0e

Browse files
committed
Merge branch 'master' of https://github.com/openvinotoolkit/openvino into clamp
2 parents 62cce40 + 39418ca commit c101c0e

File tree

112 files changed

+1883
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1883
-674
lines changed

.github/workflows/code_style.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ jobs:
3939
with:
4040
github_token: ${{ secrets.GITHUB_TOKEN }}
4141
level: warning
42-
fail_on_error: true
42+
fail_level: error
43+
filter_mode: nofilter
44+
exclude: |
45+
"*/thirdparty/*"
46+
"./temp/*"
4347
4448
clang-format-aarch64:
4549
runs-on: ubuntu-22.04
@@ -71,7 +75,11 @@ jobs:
7175
with:
7276
github_token: ${{ secrets.GITHUB_TOKEN }}
7377
level: warning
74-
fail_on_error: true
78+
fail_level: error
79+
filter_mode: nofilter
80+
exclude: |
81+
"*/thirdparty/*"
82+
"./temp/*"
7583
7684
ShellCheck:
7785
runs-on: ubuntu-22.04
@@ -103,7 +111,7 @@ jobs:
103111
level: style
104112
reporter: github-pr-review
105113
check_all_files_with_shebangs: true
106-
fail_on_error: true
114+
fail_level: error
107115
exclude: |
108116
"*/thirdparty/*"
109117
"./temp/*"

src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py

+35-20
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(self, pt_module, fx_gm=None, nodes=None,
178178
self._input_signature = []
179179
self._example_input = None
180180

181-
if issubclass(type(pt_module), torch.fx.graph_module.GraphModule):
181+
if isinstance(pt_module, torch.fx.graph_module.GraphModule):
182182
self._input_is_list = None
183183
self._nodes = list(pt_module.graph.nodes)
184184
found_types = []
@@ -187,38 +187,34 @@ def __init__(self, pt_module, fx_gm=None, nodes=None,
187187
if value.op == 'placeholder':
188188
self._inputs.append(i)
189189
self._input_signature.append(value.name)
190-
if hasattr(value, "meta") and ('tensor_meta' in value.meta.keys()) and value.meta['tensor_meta']:
191-
found_shapes.append(value.meta['tensor_meta'].shape)
192-
found_types.append(
193-
OVAny(pt_to_ov_type_map[str(value.meta['tensor_meta'].dtype)]))
194-
else:
195-
found_shapes.append(None)
196-
found_types.append(None)
190+
191+
found_shapes.append(self.get_found_shape(value))
192+
found_types.append(self.get_found_dtype(value))
193+
if found_shapes[-1] is not None:
194+
new_shape = []
195+
for dim in found_shapes[-1]:
196+
if (dynamic_shapes or type(dim).__name__ == "SymInt"):
197+
new_shape.append(-1)
198+
else:
199+
new_shape.append(dim)
200+
found_shapes[-1] = torch.Size(new_shape)
201+
197202
elif value.op == 'output':
198203
# Instead of putting output index, refer to its target
199204
uargs = self.unpack_containers(value.args)
200205
self._outputs = [(arg[0], self._nodes.index(arg[1]))
201206
for arg in uargs if arg[1] is not None]
202-
for idx, shape in enumerate(found_shapes):
203-
if shape is not None:
204-
new_shape = []
205-
for dim in shape:
206-
if (dynamic_shapes or type(dim).__name__ == "SymInt"):
207-
new_shape.append(-1)
208-
else:
209-
new_shape.append(dim)
210-
found_shapes[idx] = torch.Size(new_shape)
211207

212208
if not input_shapes or len(input_shapes) == 0:
213209
self.input_shapes = found_shapes
214210
if not input_types or len(input_types) == 0:
215211
self.input_types = found_types
216212

217-
if hasattr(pt_module, "forward"):
218-
input_params = inspect.signature(pt_module.forward).parameters
213+
if hasattr(self.pt_module, "forward"):
214+
input_params = inspect.signature(self.pt_module.forward).parameters
219215
self._input_signature = list(input_params)
220216

221-
elif issubclass(type(pt_module), torch.fx.Node):
217+
elif isinstance(pt_module, torch.fx.Node):
222218
self._nodes = nodes # passed from outer context
223219

224220
# FIXME: Quadratic complexity nodes*nodes considering the outer loop over all nodes
@@ -234,6 +230,23 @@ def __init__(self, pt_module, fx_gm=None, nodes=None,
234230
self.input_types.append(
235231
BaseFXDecoder.get_type_for_value(arg))
236232

233+
@staticmethod
234+
def get_found_shape(value) -> str:
235+
# If input is a tensor, read the shape from meta data
236+
if hasattr(value, "meta"):
237+
if ('tensor_meta' in value.meta.keys()) and value.meta['tensor_meta']:
238+
return value.meta['tensor_meta'].shape
239+
if ('val' in value.meta.keys()) and isinstance(value.meta["val"], torch.Tensor):
240+
return value.meta['val'].shape
241+
return None
242+
243+
@staticmethod
244+
def get_found_dtype(value) -> str:
245+
# If input is a tensor, read the data type from meta data
246+
if hasattr(value, "meta") and ('tensor_meta' in value.meta.keys()) and value.meta['tensor_meta']:
247+
return OVAny(pt_to_ov_type_map[str(value.meta['tensor_meta'].dtype)])
248+
return None
249+
237250
def get_input_signature_name(self, index: int) -> str:
238251
if self._input_signature is not None and index < len(self._input_signature):
239252
return self._input_signature[index]
@@ -331,6 +344,8 @@ def get_subgraph_decoder(self, index):
331344

332345
def get_op_type(self):
333346
if self.pt_module.op == 'call_function':
347+
if type(self.pt_module.target).__name__ == "EdgeOpOverload":
348+
return self.pt_module.target.__name__
334349
return str(self.pt_module.target)
335350
elif self.pt_module.op == 'get_attr':
336351
return 'get_attr' # FIXME should be aligned with get_attr from TS implementation

src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, options):
7575
"torch.ops.aten.argmin.default": None,
7676
"torch.ops.aten.as_strided.default": None,
7777
"torch.ops.aten.as_strided_.default": None,
78+
"torch.ops.aten.as_strided_copy.default": None,
7879
"torch.ops.aten.asin.default": None,
7980
"torch.ops.aten.asinh.default": None,
8081
"torch.ops.aten.asinh.default": None,
@@ -118,6 +119,7 @@ def __init__(self, options):
118119
"torch.ops.aten.erf.default": None,
119120
"torch.ops.aten.exp.default": None,
120121
"torch.ops.aten.expand.default": None,
122+
"torch.ops.aten.expand_copy.default": None,
121123
"torch.ops.aten.fake_quantize_per_channel_affine_cachemask.default": None,
122124
"torch.ops.aten.fill.Scalar": None,
123125
"torch.ops.aten.fill_.Scalar": None,
@@ -196,6 +198,7 @@ def __init__(self, options):
196198
"torch.ops.aten.new_zeros.default": None,
197199
"torch.ops.aten.ones.default": None,
198200
"torch.ops.aten.permute.default": None,
201+
"torch.ops.aten.permute_copy.default": None,
199202
"torch.ops.aten.pow.Scalar": None,
200203
"torch.ops.aten.pow.Tensor_Scalar": None,
201204
"torch.ops.aten.pow.Tensor_Tensor": None,
@@ -213,6 +216,7 @@ def __init__(self, options):
213216
"torch.ops.aten.scatter.src": None,
214217
"torch.ops.aten.scatter.value": None,
215218
"torch.ops.aten.select.int": None,
219+
"torch.ops.aten.select_copy.int": None,
216220
"torch.ops.aten.select_scatter.default": None,
217221
"torch.ops.aten.sigmoid.default": None,
218222
"torch.ops.aten.sigmoid_.default": None,
@@ -222,13 +226,16 @@ def __init__(self, options):
222226
"torch.ops.aten.sin.default": None,
223227
"torch.ops.aten.sinh.default": None,
224228
"torch.ops.aten.slice.Tensor": None,
229+
"torch.ops.aten.slice_copy.Tensor": None,
225230
"torch.ops.aten.slice_scatter.default": None,
226231
"torch.ops.aten.sort.default": None,
227232
"torch.ops.aten.split.Tensor": None,
228233
"torch.ops.aten.split_with_sizes.default": None,
234+
"torch.ops.aten.split_with_sizes_copy.default": None,
229235
"torch.ops.aten.sqrt.default": None,
230236
"torch.ops.aten.squeeze.dim": None,
231237
"torch.ops.aten.squeeze.dims": None,
238+
"torch.ops.aten.squeeze_copy.dims": None,
232239
"torch.ops.aten.stack.default": None,
233240
"torch.ops.aten.std.correction": None,
234241
"torch.ops.aten.sub.default": None,
@@ -246,10 +253,12 @@ def __init__(self, options):
246253
"torch.ops.aten.unbind.int": None,
247254
"torch.ops.aten.unfold.default": None,
248255
"torch.ops.aten.unsqueeze.default": None,
256+
"torch.ops.aten.unsqueeze_copy.default": None,
249257
"torch.ops.aten.upsample_nearest2d.default": None,
250258
"torch.ops.aten.var.correction": None,
251259
"torch.ops.aten.var_mean.correction": None,
252260
"torch.ops.aten.view.default": None,
261+
"torch.ops.aten.view_copy.default": None,
253262
"torch.ops.aten.where.self": None,
254263
"torch.ops.aten.zeros.default": None,
255264
"torch.ops.aten.zeros_like.default": None,

src/bindings/python/src/pyopenvino/utils/utils.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ py::object from_ov_any(const ov::Any& any) {
192192
std::string property_name = it;
193193
auto mutability = it.get_mutability();
194194
std::string mutability_str;
195-
switch (mutability)
196-
{
195+
switch (mutability) {
197196
case ov::PropertyMutability::RW:
198197
mutability_str = "RW";
199198
break;

src/common/transformations/include/transformations/low_precision/mark_dequantization_subgraph.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class TRANSFORMATIONS_API KeepConstPrecision : public ov::pass::MatcherPass {
7272
public:
7373
OPENVINO_MATCHER_PASS_RTTI("KeepConstPrecision");
7474
explicit KeepConstPrecision(const element::TypeVector& precisions,
75-
bool fold_subtract_const = false,
76-
bool fold_multiply_const = true);
75+
bool fold_subtract_const = false,
76+
bool fold_multiply_const = true);
7777
};
7878

7979
} // namespace pass

src/common/transformations/src/transformations/low_precision/mark_dequantization_subgraph.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ we cannot perform swapping as this would break another part of the graph.
5656
ZP Const
5757
5858
59-
Input Convert Input
60-
│ │ │ │
61-
▼ ▼ ▼ ▼
59+
Input Convert Input
60+
│ │ │ │
61+
▼ ▼ ▼ ▼
6262
Scale Convert Reshape Reshape Convert Scale
6363
| │ (64,1,1,1) (1,64,1,1) │ │
6464
| │ │ │ │ |
65-
▼ ▼ ▼ ▼ ▼ ▼
65+
▼ ▼ ▼ ▼ ▼ ▼
6666
Reshape Subtract Subtract Reshape
6767
| | | |
6868
▼ ▼ ▼ ▼
@@ -73,13 +73,13 @@ Though, we can perform swapping if the shapes are same for all branches: e.g.
7373
ZP Const
7474
7575
76-
Input Convert Input
77-
│ │ │ │
78-
▼ ▼ ▼ ▼
76+
Input Convert Input
77+
│ │ │ │
78+
▼ ▼ ▼ ▼
7979
Convert Reshape Reshape Convert
8080
Scale │ (64,1,1,1) (64,1,1,1) │ Scale
8181
| │ │ │ │ |
82-
▼ ▼ ▼ ▼ ▼ ▼
82+
▼ ▼ ▼ ▼ ▼ ▼
8383
Reshape Subtract Subtract Reshape
8484
| | | |
8585
▼ ▼ ▼ ▼
@@ -104,8 +104,8 @@ Scale Convert Convert Input
104104
Subtract Reshape
105105
| |
106106
▼ ▼
107-
Multiply
108-
107+
Multiply
108+
109109
Step 2: the right part of the graph would be matched transforming the graph above into the final form:
110110
111111
ZP Const
@@ -150,17 +150,18 @@ bool can_swap(const PatternValueMap& pt_map,
150150
auto first_shape = target_inputs.begin()->get_node()->output(0).get_shape();
151151

152152
// Step 1 (see steps description in the comments above)
153-
if (std::all_of(std::next(target_inputs.begin()), target_inputs.end(),
153+
if (std::all_of(std::next(target_inputs.begin()),
154+
target_inputs.end(),
154155
[&](const ov::Input<ov::Node>& input) {
155156
return input.get_node()->get_output_partial_shape(0).is_static() &&
156157
input.get_node()->get_shape() == first_shape;
157158
})) {
158-
return true;
159+
return true;
159160
} else if (first_node->get_output_partial_shape(0).is_static() &&
160161
second_node->get_output_partial_shape(0).is_static() &&
161162
first_node->get_output_shape(0) == second_node->get_output_shape(0)) {
162-
// Step 2
163-
return true;
163+
// Step 2
164+
return true;
164165
}
165166
}
166167
}

src/common/transformations/src/transformations/op_conversions/scaled_dot_product_attention_decomposition.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "itt.hpp"
1010
#include "openvino/core/rt_info.hpp"
11+
#include "openvino/core/validation_util.hpp"
1112
#include "openvino/op/add.hpp"
1213
#include "openvino/op/broadcast.hpp"
1314
#include "openvino/op/concat.hpp"
@@ -68,9 +69,23 @@ std::shared_ptr<ov::Node> ov::pass::ScaledDotProductAttentionDecomposition::deco
6869
auto one_f = register_new_node<v1::ConvertLike>(one_i, query);
6970
auto zero_f = register_new_node<v1::ConvertLike>(zero_i, query);
7071

72+
auto build_extract_dim_subgraph = [this, &zero_i](const std::shared_ptr<v3::ShapeOf>& shape_of,
73+
const int64_t idx) -> std::shared_ptr<ov::Node> {
74+
const auto dim_to_extract_const = v0::Constant::create(element::i32, Shape{}, {idx});
75+
const auto gather = std::make_shared<v8::Gather>(shape_of, dim_to_extract_const, zero_i);
76+
// When dim_to_extract is static but the whole shape is dynamic,
77+
// ConstantFolding can't fold ShapeOf->Gather subgraph in this case.
78+
// So it's better to explicitly extract the needed dimension.
79+
if (auto constant = ov::util::get_constant_from_source(gather)) {
80+
return register_new_node(constant);
81+
}
82+
register_new_node(dim_to_extract_const);
83+
return register_new_node(gather);
84+
};
85+
7186
Output<Node> scale;
7287
if (node->get_input_size() < 5) {
73-
scale = register_new_node<v8::Gather>(q_shape, minus_one, zero_i)->output(0);
88+
scale = build_extract_dim_subgraph(q_shape, -1);
7489
scale = register_new_node<v1::ConvertLike>(scale, query);
7590
auto sqrt_scale = register_new_node<v0::Sqrt>(scale);
7691
scale = register_new_node<v1::Divide>(one_f, sqrt_scale);
@@ -112,8 +127,8 @@ std::shared_ptr<ov::Node> ov::pass::ScaledDotProductAttentionDecomposition::deco
112127
atten_mask = mask;
113128
}
114129
} else {
115-
auto target_s_len = register_new_node<v8::Gather>(q_shape, minus_two, zero_i);
116-
auto source_s_len = register_new_node<v8::Gather>(k_shape, minus_two, zero_i);
130+
auto target_s_len = build_extract_dim_subgraph(q_shape, -2);
131+
auto source_s_len = build_extract_dim_subgraph(k_shape, -2);
117132
auto ssl = register_new_node<v0::Unsqueeze>(source_s_len, zero_i);
118133
auto tsl = register_new_node<v0::Unsqueeze>(target_s_len, zero_i);
119134
auto mask_shape = register_new_node<v0::Concat>(OutputVector{tsl, ssl}, 0);

0 commit comments

Comments
 (0)