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

[Relay/topi] Support scalar inputs in where op #6383

Merged
merged 3 commits into from
Sep 4, 2020

Conversation

masahi
Copy link
Member

@masahi masahi commented Sep 2, 2020

This adds support for relay/topi where op to take scalar values as input. This use case came up in hummingbird project. See microsoft/hummingbird#232 (comment)

I think this is a reasonable feature to add. The output shape is the same as condition's shape. Condition's shape has to be 1D. We could allow condition shape to be arbitrary when x and y are scalar, but I didn't make that change.

please review @zhiics @siju-samuel @junrushao1994

@t-vi
Copy link
Contributor

t-vi commented Sep 2, 2020

I'm not sure if I'm letting the perfect be the enemy of the good here, but I wonder where it would be worthwhile to implement complete implicit broadcasting semantics rather than adding another special case.

@@ -1663,7 +1663,12 @@ bool WhereRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
<< "condition and x must have the same shape: " << cond_shape << " vs " << x_shape;
}
}
reporter->Assign(types[3], TensorType(x_shape, x->dtype));
if (x_shape.size() == 0) {
// if x and y are scalar, the condition shape becomes the output shape
Copy link
Member

Choose a reason for hiding this comment

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

Check condition rank is 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

@junrushao
Copy link
Member

I don't know for sure...Isn't the output shape be the broadcasted shape between x, y, cond?

@masahi
Copy link
Member Author

masahi commented Sep 4, 2020

@zhiics @junrushao1994 @t-vi Any other comments? I think this is a no brainer change. To keep it simple I don't want to get into broadcasting stuff for now.

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

I think it is good enough. LGTM, Thanks!

@zhiics
Copy link
Member

zhiics commented Sep 4, 2020

@t-vi do you have more comments? please take another look per https://tvm.apache.org/docs/contribute/code_review.html#approve-and-request-changes-explicitly

@t-vi
Copy link
Contributor

t-vi commented Sep 4, 2020

@zhiics No, thank you for reminding me, I have no actionable comment here.

@zhiics zhiics merged commit 8508ec3 into apache:master Sep 4, 2020
@zhiics
Copy link
Member

zhiics commented Sep 4, 2020

Thanks @masahi @t-vi @junrushao1994

kevinthesun pushed a commit to kevinthesun/tvm that referenced this pull request Sep 17, 2020
* support where with scalars

* add test for where with scalar

* add comment
kevinthesun pushed a commit to kevinthesun/tvm that referenced this pull request Sep 18, 2020
* support where with scalars

* add test for where with scalar

* add comment
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 18, 2020
* support where with scalars

* add test for where with scalar

* add comment
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.

4 participants