Skip to content
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

eliminate slice shape #82

Merged
merged 5 commits into from
Jul 7, 2022
Merged

Conversation

HSQ79815
Copy link
Collaborator

@HSQ79815 HSQ79815 commented Jul 1, 2022

Signed-off-by: haoshengqiang [email protected]

@HSQ79815 HSQ79815 force-pushed the eliminate_nop_slice_shape branch from 557c48f to ab3b293 Compare July 1, 2022 09:46
const auto &dims_of_shape_node_input = shape_node->input()->sizes();
std::vector<Dimension> result_of_shape_op;

auto add_y_if_negative = [](int64_t x, int64_t y) -> int64_t {
Copy link
Member

@daquexian daquexian Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract this function into some common file for example creating a new file named onnxoptimizer/passes/utils.h

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other passes also use this helper function, so I will handle with it by new PR.

namespace ONNX_NAMESPACE {
namespace optimization {

struct EliminateSliceShape final : public PredicateBasedPass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EliminateShapeSlice is better because the order of eliminated nodes in graph is Shape -> Slice

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think of EliminateSliceAfterShape ? In this pass, Pattern Shape -> Slice be matched, we want to eliminate Slice op , but Shape will reserve.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 👍

onnxoptimizer/passes/eliminate_slice_shape.h Outdated Show resolved Hide resolved
onnxoptimizer/passes/eliminate_slice_shape.h Outdated Show resolved Hide resolved
HSQ79815 added 2 commits July 5, 2022 18:00
Signed-off-by: haoshengqiang <[email protected]>
Signed-off-by: haoshengqiang <[email protected]>
@HSQ79815 HSQ79815 force-pushed the eliminate_nop_slice_shape branch from ab3b293 to 2d3a205 Compare July 5, 2022 10:00
HSQ79815 added 2 commits July 5, 2022 18:08
Signed-off-by: haoshengqiang <[email protected]>
if (!fetch_first_value_of_tensor(node->inputs()[1], slice_start) ||
!fetch_first_value_of_tensor(node->inputs()[2], slice_end) ||
(node->inputs().size() == 5 &&
!fetch_first_value_of_tensor(node->inputs()[4], slice_step)) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fetch_sole_value_of_tensor a better name? And then an ONNX_ASSERT should be added to check the tensor has only one element.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

Signed-off-by: haoshengqiang <[email protected]>
@daquexian daquexian merged commit 709f445 into onnx:master Jul 7, 2022
@HSQ79815 HSQ79815 deleted the eliminate_nop_slice_shape branch July 9, 2022 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants