-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Hackathon 5th No.96】add paddle unstack op #20080
Merged
ceciliapeng2011
merged 7 commits into
openvinotoolkit:master
from
Patrick-Star125:unstack
Nov 22, 2023
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "default_opset.hpp" | ||
#include "openvino/frontend/paddle/node_context.hpp" | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace paddle { | ||
namespace op { | ||
NamedOutputs unstack(const NodeContext& node) { | ||
auto data = node.get_input("X"); | ||
auto dim = node.get_attribute<int32_t>("axis"); | ||
if (dim < 0) { | ||
dim = dim + data.get_partial_shape().rank().get_length(); | ||
} | ||
auto axis = default_opset::Constant::create(element::i32, {}, {dim}); | ||
auto shape = data.get_shape(); | ||
liubo-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auto splits = std::make_shared<default_opset::Split>(data, axis, shape[dim]); | ||
auto split_outputs = splits->outputs(); | ||
NamedOutputs named_outputs; | ||
auto out_names = node.get_output_names(); | ||
auto it = std::find(out_names.begin(), out_names.end(), "Y"); | ||
PADDLE_OP_CHECK(node, it != out_names.end(), "Expected output not found"); | ||
for (const auto& split_output : split_outputs) { | ||
named_outputs[*it].push_back(std::make_shared<default_opset::Squeeze>(split_output)); | ||
liubo-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return named_outputs; | ||
} | ||
} // namespace op | ||
} // namespace paddle | ||
} // namespace frontend | ||
} // 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
42 changes: 42 additions & 0 deletions
42
src/frontends/paddle/tests/test_models/gen_scripts/generate_unstack.py
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,42 @@ | ||
# Copyright (C) 2018-2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# unstack paddle model generator | ||
# | ||
import paddle | ||
import numpy as np | ||
from save_model import saveModel | ||
import sys | ||
|
||
|
||
def unstack(name: str, x, axis): | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
x_node = paddle.static.data(name="x", shape=x.shape, dtype=x.dtype) | ||
out = paddle.unstack(x_node, axis) | ||
place = paddle.CPUPlace() | ||
exe = paddle.static.Executor(place) | ||
exe.run(paddle.static.default_startup_program()) | ||
outs = exe.run(feed={"x": x}, fetch_list=[out]) | ||
saveModel(name, exe, feedkeys=['x'], fetchlist=out, inputs=[x], outputs=outs, target_dir=sys.argv[1]) | ||
|
||
return outs | ||
|
||
|
||
def main(): | ||
dtype = np.float32 | ||
x = np.random.randn(2, 3, 4).astype(dtype) | ||
unstack(name='unstack_1', x=x, axis=0) | ||
|
||
dtype = np.int32 | ||
x = np.random.randn(2, 3, 4).astype(dtype) | ||
unstack(name='unstack_2', x=x, axis=1) | ||
|
||
dtype = np.int64 | ||
x = np.random.randn(3, 4).astype(dtype) | ||
unstack(name='unstack_3', x=x, axis=-1) | ||
|
||
liubo-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this line, because split op can accept negative axis: https://github.com/openvinotoolkit/openvino/blob/master/docs/articles_en/documentation/openvino_ir/operation_sets/operations_specifications/movement/Split_1.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you validated it again? Could you help to update your uni-test screenshot if not ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, missed the notification email, we should keep these code because index access of
shape
is bounded within [0, abs(dim)-1]