-
Notifications
You must be signed in to change notification settings - Fork 93
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
Conversation
557c48f
to
ab3b293
Compare
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 { |
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.
please extract this function into some common file for example creating a new file named onnxoptimizer/passes/utils.h
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.
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 { |
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.
EliminateShapeSlice is better because the order of eliminated nodes in graph is Shape -> Slice
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.
what do you think of EliminateSliceAfterShape ? In this pass, Pattern Shape -> Slice
be matched, we want to eliminate Slice
op , but Shape
will reserve.
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.
Great 👍
Signed-off-by: haoshengqiang <[email protected]>
Signed-off-by: haoshengqiang <[email protected]>
ab3b293
to
2d3a205
Compare
Signed-off-by: haoshengqiang <[email protected]>
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)) || |
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.
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.
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.
Great
Signed-off-by: haoshengqiang <[email protected]>
Signed-off-by: haoshengqiang [email protected]