forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ShapeInfer][Op] Internal GLU op - common shape_infer (openvinotoolki…
…t#27750) ### Details: - Align internal GLU shape_infer - Move shape_infer from the op to the shape_inference directory - Update shape_infer to use template as a shape type - Remove VariadicSplit object creation to call variadic split shape_infer - Register GLU shape_infer for CPU - Update GPU calc_output to use common GLU shape_infer ### Tickets: - 157615
- Loading branch information
Showing
7 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "ov_ops/glu.hpp" | ||
#include "utils.hpp" | ||
#include "variadic_split_shape_inference.hpp" | ||
|
||
namespace ov { | ||
namespace op { | ||
namespace internal { | ||
template <class TShape, class TRShape = result_shape_t<TShape>> | ||
std::vector<TRShape> shape_infer(const GLU* op, const std::vector<TShape>& input_shapes) { | ||
const auto inputs_count = input_shapes.size(); | ||
NODE_SHAPE_INFER_CHECK(op, input_shapes, inputs_count == 1); | ||
|
||
int64_t axis = op->get_axis(); | ||
std::vector<int64_t> split_lengths = {op->get_split_lengths(), -1}; | ||
std::unordered_map<size_t, ov::Tensor> const_data; | ||
const_data.emplace(1, ov::Tensor(ov::element::i64, ov::Shape{}, &axis)); | ||
const_data.emplace(2, ov::Tensor(ov::element::i64, ov::Shape{split_lengths.size()}, split_lengths.data())); | ||
|
||
const ov::Shape split_len_size{split_lengths.size()}; | ||
const ov::Shape scalar{}; | ||
std::vector<TShape> variadic_split_input_shapes{input_shapes[0], scalar, split_len_size}; | ||
|
||
return {std::move( | ||
ov::op::variadic_split::shape_infer(op, variadic_split_input_shapes, ov::make_tensor_accessor(const_data))[0])}; | ||
} | ||
} // namespace internal | ||
} // namespace op | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/plugins/intel_cpu/tests/unit/shape_inference_test/glu_shape_inference_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "common_test_utils/test_assertions.hpp" | ||
#include "ov_ops/glu.hpp" | ||
#include "utils.hpp" | ||
|
||
using namespace ov; | ||
using namespace ov::intel_cpu; | ||
using ov::op::v0::Constant; | ||
using ov::op::v0::Parameter; | ||
using testing::HasSubstr; | ||
|
||
TEST(StaticShapeInferenceTest, GLUStaticShapeInferenceTestDefaultCtor) { | ||
constexpr int64_t axis = -1; | ||
constexpr int64_t split_lengths = 48; | ||
|
||
const auto op = std::make_shared<op::internal::GLU>(); | ||
const auto data = std::make_shared<Parameter>(element::f16, PartialShape::dynamic()); | ||
|
||
op->set_arguments(ov::OutputVector{data}); | ||
op->set_axis(axis); | ||
op->set_split_lengths(split_lengths); | ||
|
||
std::vector<StaticShape> static_input_shapes = {StaticShape{20, 1, 96}}; | ||
const auto static_output_shapes = shape_inference(op.get(), static_input_shapes); | ||
ASSERT_EQ(static_output_shapes.size(), 1); | ||
EXPECT_EQ(static_output_shapes[0], StaticShape({20, 1, 48})); | ||
} | ||
|
||
TEST(StaticShapeInferenceTest, GLUStaticShapeInferenceTestBasic) { | ||
constexpr int64_t axis = -1; | ||
constexpr int64_t split_lengths = 48; | ||
const auto glu_type = ov::op::internal::GLU::GluType::Swish; | ||
|
||
const auto data = std::make_shared<Parameter>(element::f16, PartialShape::dynamic()); | ||
const auto op = std::make_shared<op::internal::GLU>(data, axis, split_lengths, glu_type, 1); | ||
|
||
std::vector<StaticShape> static_input_shapes = {StaticShape{20, 1, 96}}; | ||
const auto static_output_shapes = shape_inference(op.get(), static_input_shapes); | ||
ASSERT_EQ(static_output_shapes.size(), 1); | ||
EXPECT_EQ(static_output_shapes[0], StaticShape({20, 1, 48})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters