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

[luci/service] Migrate reshape shape inference rule to sinf::Algorithm #13989

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

jongwonyang
Copy link
Member

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]

@jongwonyang jongwonyang added PR/ready for review It is ready to review. Please review it. SSAFY labels Sep 11, 2024
@jongwonyang jongwonyang requested review from a team September 11, 2024 07:41
Comment on lines 106 to 156
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));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure adding these tests is good idea 🤔
Because in another PRs, we talked about not to add NEG tests in similar situations.
(related : #13977)

@shs-park Could you give an opinion about this?

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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. 😅

Copy link
Member Author

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 :)

Copy link
Contributor

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.

shape.rank(node->rank());
for (uint32_t r = 0; r < node->rank(); ++r)
{
// Shape inference rules in this file did not consider unknown dimension.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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)

Copy link
Member Author

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!

@jongwonyang jongwonyang force-pushed the migrate_reshape branch 2 times, most recently from 6ecd2e4 to 82d2717 Compare September 11, 2024 11:50
This commit migrates Reshape shape inference rule to sinf::Algorithm.

ONE-DCO-1.0-Signed-off-by: Jongwon Yang <[email protected]>
shs-park
shs-park previously approved these changes Sep 11, 2024
Copy link
Contributor

@shs-park shs-park left a comment

Choose a reason for hiding this comment

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

LGTM!
=)

Comment on lines +28 to +43
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;
}
Copy link
Contributor

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 in compiler/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?

zetwhite
zetwhite previously approved these changes Sep 12, 2024
seanshpark
seanshpark previously approved these changes Sep 12, 2024
Copy link
Contributor

@seanshpark seanshpark left a comment

Choose a reason for hiding this comment

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

LGTM thank you!

@seanshpark
Copy link
Contributor

Plz resolve conflicts

@jongwonyang jongwonyang dismissed stale reviews from seanshpark, zetwhite, and shs-park via d10a8bf September 12, 2024 03:51
@jongwonyang
Copy link
Member Author

Plz resolve conflicts

Resolved :)

Copy link
Contributor

@shs-park shs-park left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@seanshpark seanshpark left a comment

Choose a reason for hiding this comment

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

LGTM thank you!

@seanshpark seanshpark merged commit 5149447 into Samsung:master Sep 12, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR/ready for review It is ready to review. Please review it. SSAFY
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants