[PT FE] Cannot get length of dynamic dimension (#15449)
* Create output tensor for bound evaluate depends on element type and shape, rank dynamism * Add test to simulate pytorch bound evaluation for when output has got dynamic data type or rank * Correct code style * Correct shape for dynamic tensor.
This commit is contained in:
1 parent
264cb18619
commit
19e60759cd
2 files changed
+64
-2
No files matched your search
@@ -80,8 +80,17 @@ ov::Tensor evaluate_bound(const Output<Node>& output, bool is_upper, bool invali
|
||||
ov::TensorVector outputs;
|
||||
for (const auto& out : node->outputs()) {
|
||||
const auto& out_shape = out.get_partial_shape();
|
||||
auto shape = out_shape.is_static() ? out_shape.to_shape() : Shape(out_shape.rank().get_length());
|
||||
outputs.emplace_back(out.get_element_type(), shape);
|
||||
const auto& out_et = out.get_element_type();
|
||||
|
||||
if (out_et.is_dynamic()) {
|
||||
outputs.emplace_back();
|
||||
} else if (out_shape.is_static()) {
|
||||
outputs.emplace_back(out_et, out_shape.to_shape());
|
||||
} else if (out_shape.rank().is_static()) {
|
||||
outputs.emplace_back(out_et, Shape(out_shape.rank().get_length()));
|
||||
} else {
|
||||
outputs.emplace_back(out_et, Shape{0});
|
||||
}
|
||||
}
|
||||
|
||||
if (is_upper ? node->evaluate_upper(outputs) : node->evaluate_lower(outputs)) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "bound_evaluate.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/util/framework_node.hpp"
|
||||
#include "openvino/opsets/opset10.hpp"
|
||||
#include "type_prop.hpp"
|
||||
|
||||
using namespace ov;
|
||||
using namespace ov::opset10;
|
||||
|
||||
class EvaluateBoundTest : public TypePropOpTest<op::util::FrameworkNode> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
const auto c_inputs =
|
||||
ParameterVector(2, std::make_shared<Parameter>(element::f32, PartialShape{-1, 24, {1, -1}, {1, -1}}));
|
||||
const auto c = std::make_shared<Concat>(OutputVector(c_inputs.begin(), c_inputs.end()), 1);
|
||||
const auto s = std::make_shared<ShapeOf>(c);
|
||||
const auto s_res = std::make_shared<Result>(s);
|
||||
const auto body = std::make_shared<Model>(OutputVector{s_res}, c_inputs);
|
||||
|
||||
fn_op = make_op(OutputVector{s}, 0, 2);
|
||||
|
||||
auto attrs = op::util::FrameworkNodeAttrs();
|
||||
attrs.set_type_name("some_type");
|
||||
fn_op->set_attrs(attrs);
|
||||
fn_op->set_function(0, body);
|
||||
fn_op->set_function(1, body);
|
||||
}
|
||||
|
||||
std::shared_ptr<op::util::FrameworkNode> fn_op;
|
||||
};
|
||||
|
||||
// Simulate scenarios in pytorch when eval bounds for node PtFrameworkNode which inherits from FrameworkNode
|
||||
TEST_F(EvaluateBoundTest, no_exception_when_node_has_output_with_dynamic_rank) {
|
||||
fn_op->set_output_type(0, element::i32, PartialShape::dynamic());
|
||||
fn_op->set_output_type(1, element::i32, PartialShape{{1, 4}});
|
||||
fn_op->validate_and_infer_types();
|
||||
|
||||
EXPECT_NO_THROW(evaluate_both_bounds(fn_op));
|
||||
}
|
||||
|
||||
TEST_F(EvaluateBoundTest, no_exception_when_node_has_output_with_dynamic_element_type) {
|
||||
fn_op->set_output_type(0, element::dynamic, PartialShape{4});
|
||||
fn_op->set_output_type(1, element::dynamic, PartialShape{4});
|
||||
fn_op->validate_and_infer_types();
|
||||
|
||||
EXPECT_NO_THROW(evaluate_both_bounds(fn_op));
|
||||
}
|
||||
Reference in new issue
Block a user