-
Notifications
You must be signed in to change notification settings - Fork 157
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
[luci/service] Migrate reshape shape inference rule to sinf::Algorithm #13989
Conversation
TEST(ShapeRuleTest, reshape_input_tensor_undefined_NEG) | ||
{ | ||
auto g = loco::make_graph(); | ||
auto node_reshape = g->nodes()->create<luci::CircleReshape>(); | ||
auto tensor_input = g->nodes()->create<luci::CircleInput>(); | ||
auto shape_by_input = g->nodes()->create<luci::CircleConst>(); | ||
|
||
tensor_input->dtype(loco::DataType::S32); | ||
tensor_input->shape({2, 3, 4}); | ||
tensor_input->shape_status(luci::ShapeStatus::UNDEFINED); | ||
|
||
shape_by_input->dtype(loco::DataType::S32); | ||
shape_by_input->size<loco::DataType::S32>(2); | ||
shape_by_input->at<loco::DataType::S32>(0) = 6; | ||
shape_by_input->at<loco::DataType::S32>(1) = 4; | ||
shape_by_input->shape_status(luci::ShapeStatus::VALID); | ||
|
||
node_reshape->tensor(tensor_input); | ||
node_reshape->shape(shape_by_input); | ||
|
||
loco::TensorShape output_shape; | ||
luci::sinf::Rule shape_inf_rule; | ||
|
||
ASSERT_FALSE(shape_inf_rule.infer(node_reshape, output_shape)); | ||
} | ||
|
||
TEST(ShapeRuleTest, reshape_input_shape_undefined_NEG) | ||
{ | ||
auto g = loco::make_graph(); | ||
auto node_reshape = g->nodes()->create<luci::CircleReshape>(); | ||
auto tensor_input = g->nodes()->create<luci::CircleInput>(); | ||
auto shape_by_input = g->nodes()->create<luci::CircleConst>(); | ||
|
||
tensor_input->dtype(loco::DataType::S32); | ||
tensor_input->shape({2, 3, 4}); | ||
tensor_input->shape_status(luci::ShapeStatus::VALID); | ||
|
||
shape_by_input->dtype(loco::DataType::S32); | ||
shape_by_input->size<loco::DataType::S32>(2); | ||
shape_by_input->at<loco::DataType::S32>(0) = 6; | ||
shape_by_input->at<loco::DataType::S32>(1) = 4; | ||
shape_by_input->shape_status(luci::ShapeStatus::UNDEFINED); | ||
|
||
node_reshape->tensor(tensor_input); | ||
node_reshape->shape(shape_by_input); | ||
|
||
loco::TensorShape output_shape; | ||
luci::sinf::Rule shape_inf_rule; | ||
|
||
ASSERT_FALSE(shape_inf_rule.infer(node_reshape, output_shape)); | ||
} |
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.
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.
I think so too.
Also, since the purpose of this PR is a simple migration, I don't think there's a need to include additional tests this time.
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.
I think so too. Also, since the purpose of this PR is a simple migration, I don't think there's a need to include additional tests this time.
You mean, not just neg tests, but also all the tests are unnecessary? Because it's just migration?
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.
For general (normal) cases, I think it's okay to leave it as is. 😅
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.
Thanks for your opinion. Then, I'll remove the neg cases only :)
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.
Thank you! And since we don't have enough NEG tests then, I think you could continue by creating a separate issue to add more NEG tests.
436119f
to
87e20be
Compare
shape.rank(node->rank()); | ||
for (uint32_t r = 0; r < node->rank(); ++r) | ||
{ | ||
// Shape inference rules in this file did not consider unknown dimension. |
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.
// Shape inference rules in this file did not consider unknown dimension. | |
// TODO remove this copy from `use_own(node);` | |
// Shape inference rules in this file did not consider unknown dimension. |
like #13987 (review)
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.
I have applied this suggestion. Thanks!
6ecd2e4
to
82d2717
Compare
This commit migrates Reshape shape inference rule to sinf::Algorithm. ONE-DCO-1.0-Signed-off-by: Jongwon Yang <[email protected]>
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.
LGTM!
=)
std::ostream &operator<<(std::ostream &os, const loco::TensorShape &tensor_shape) | ||
{ | ||
os << "["; | ||
for (uint32_t r = 0; r < tensor_shape.rank(); ++r) | ||
{ | ||
if (r) | ||
os << ","; | ||
|
||
if (tensor_shape.dim(r).known()) | ||
os << tensor_shape.dim(r).value(); | ||
else | ||
os << "?"; | ||
} | ||
os << "]"; | ||
return os; | ||
} |
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.
(Not for this PR)
I find out that there are many std::ostream &operator<<
overloadings for TensorShape
in luci/services
.
- search
operator<<(std::ostream &os, const loco::TensorShape
incompiler/luci/service/
compiler/luci/service/src/CircleShapeInference.cpp: 30 31: std::ostream &operator<<(std::ostream &os, const loco::TensorShape &tensor_shape) 32 { compiler/luci/service/src/CircleShapeInferenceRule.cpp: 37 38: std::ostream &operator<<(std::ostream &os, const loco::TensorShape &tensor_shape) 39 { compiler/luci/service/src/Validate.cpp: 33 34: std::ostream &operator<<(std::ostream &os, const loco::TensorShape &tensor_shape) 35 {
How about introduce new file name compiler/luci/service/src/logHelper.h
and making one implementation?
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.
LGTM thank you!
Plz resolve conflicts |
d10a8bf
Resolved :) |
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.
👍
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.
LGTM thank you!
This PR migrates reshape shape inference rule to
sinf::Algorithm
.This PR is the first step of implementing dynamic shape inference algorithm for reshape operation.
Further implementation in the draft will be uploaded as a separate PR with detailed explanation after merging this PR.
Related: #13927
Draft: #13935
ONE-DCO-1.0-Signed-off-by: Jongwon Yang [email protected]