Skip to content

Commit

Permalink
Add single layer test for FakeConvert
Browse files Browse the repository at this point in the history
  • Loading branch information
xuchen-intel committed Dec 27, 2024
1 parent 39041c8 commit cd1b9a9
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FakeConvertDecompositionTest : public ov::test::TestsCommon,
result << "dataPrecision=" << element::Type(data_prec) << "_";
result << "destinationPrecision=" << element::Type(dst_prec) << "_";
if (default_shift)
result << "destinationPrecision=true";
result << "defaultShift=true";
else
result << "defaultShift=false";
return result.str();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "single_op_tests/fake_convert.hpp"

namespace {
using ov::test::FakeConvertLayerTest;

const std::vector<std::vector<ov::Shape>> shapes = {{{2, 3, 4, 5}}};

const std::vector<ov::element::Type> data_precisions = {ov::element::f32, ov::element::f16, ov::element::bf16};

const std::vector<ov::element::Type> destination_precisions = {ov::element::f8e4m3, ov::element::f8e5m2};

const std::vector<bool> default_shift = {true, false};

const auto simple_fake_convert_params =
::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes)),
::testing::Values(ov::Shape{1}),
::testing::Values(ov::Shape{1}),
::testing::ValuesIn(data_precisions),
::testing::ValuesIn(destination_precisions),
::testing::ValuesIn(default_shift),
::testing::Values(ov::test::utils::DEVICE_CPU));

const auto broadcast_fake_convert_params =
::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes)),
::testing::Values(ov::Shape{2, 3, 1, 1}),
::testing::Values(ov::Shape{2, 3, 1, 1}),
::testing::ValuesIn(data_precisions),
::testing::ValuesIn(destination_precisions),
::testing::ValuesIn(default_shift),
::testing::Values(ov::test::utils::DEVICE_CPU));

const auto elementwise_fake_convert_params =
::testing::Combine(::testing::ValuesIn(ov::test::static_shapes_to_test_representation(shapes)),
::testing::Values(ov::Shape{2, 3, 4, 5}),
::testing::Values(ov::Shape{2, 3, 4, 5}),
::testing::ValuesIn(data_precisions),
::testing::ValuesIn(destination_precisions),
::testing::ValuesIn(default_shift),
::testing::Values(ov::test::utils::DEVICE_CPU));

INSTANTIATE_TEST_SUITE_P(smoke_FakeConvert_simple,
FakeConvertLayerTest,
simple_fake_convert_params,
FakeConvertLayerTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(smoke_FakeConvert_broadcast,
FakeConvertLayerTest,
broadcast_fake_convert_params,
FakeConvertLayerTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(smoke_FakeConvert_elementwise,
FakeConvertLayerTest,
elementwise_fake_convert_params,
FakeConvertLayerTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "shared_test_classes/single_op/fake_convert.hpp"

namespace ov {
namespace test {

TEST_P(FakeConvertLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "shared_test_classes/base/ov_subgraph.hpp"

namespace ov {
namespace test {
using FakeConvertParams = std::tuple<std::vector<InputShape>, // Data shape
Shape, // Scale shape
Shape, // Shift shape
ov::element::Type, // Input precision
ov::element::Type, // Ddestination precision
bool, // Default shift
std::string>; // Device name

class FakeConvertLayerTest : public testing::WithParamInterface<FakeConvertParams>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<FakeConvertParams>& obj);

protected:
void SetUp() override;
};
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "shared_test_classes/single_op/fake_convert.hpp"

#include "openvino/opsets/opset1.hpp"
#include "openvino/opsets/opset13.hpp"

namespace ov {
namespace test {
std::string FakeConvertLayerTest::getTestCaseName(const testing::TestParamInfo<FakeConvertParams>& obj) {
FakeConvertParams params = obj.param;

std::vector<InputShape> data_shapes;
Shape scale_shape, shift_shape;
element::Type_t data_prec, dst_prec;
bool default_shift;
std::string target_device;
std::tie(data_shapes, scale_shape, shift_shape, data_prec, dst_prec, default_shift, target_device) = params;

std::ostringstream result;
result << "IS=(";
for (const auto& shape : data_shapes) {
result << ov::test::utils::partialShape2str({shape.first}) << "_";
}
result << ")_TS=(";
for (const auto& shape : data_shapes) {
for (const auto& item : shape.second) {
result << ov::test::utils::vec2str(item) << "_";
}
}
result << ")_scaleShape=" << ov::test::utils::vec2str(scale_shape) << "_";
result << "shiftShape=" << ov::test::utils::vec2str(shift_shape) << "_";
result << "dataPrecision=" << element::Type(data_prec) << "_";
result << "destinationPrecision=" << element::Type(dst_prec) << "_";
if (default_shift)
result << "defaultShift=true";
else
result << "defaultShift=false";
return result.str();
}

void FakeConvertLayerTest::SetUp() {
FakeConvertParams params = this->GetParam();

std::vector<InputShape> data_shapes;
Shape scale_shape, shift_shape;
element::Type_t data_prec, dst_prec;
bool default_shift;
std::tie(data_shapes, scale_shape, shift_shape, data_prec, dst_prec, default_shift, targetDevice) = params;

init_input_shapes(data_shapes);

const auto data = std::make_shared<opset1::Parameter>(data_prec, inputDynamicShapes.front());
const auto scale = std::make_shared<opset1::Constant>(data_prec, scale_shape);
const auto shift = std::make_shared<opset1::Constant>(data_prec, shift_shape);

const auto fake_convert = default_shift ? std::make_shared<opset13::FakeConvert>(data, scale, dst_prec)
: std::make_shared<opset13::FakeConvert>(data, scale, shift, dst_prec);
function = std::make_shared<ov::Model>(NodeVector{fake_convert}, ParameterVector{data});
}
} // namespace test
} // namespace ov

0 comments on commit cd1b9a9

Please sign in to comment.