Skip to content

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

Merged
zhiics merged 3 commits into
apache:masterfrom
masahi:where-scalar
Sep 4, 2020
Merged

[Relay/topi] Support scalar inputs in where op#6383
zhiics merged 3 commits into
apache:masterfrom
masahi:where-scalar

Conversation

@masahi

@masahi masahi commented Sep 2, 2020

Copy link
Copy Markdown
Member

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

t-vi commented Sep 2, 2020

Copy link
Copy Markdown
Contributor

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.

}
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@masahi

masahi commented Sep 4, 2020

Copy link
Copy Markdown
Member Author

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

@junrushao junrushao left a comment

Copy link
Copy Markdown
Member

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

zhiics commented Sep 4, 2020

Copy link
Copy Markdown
Member

@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

t-vi commented Sep 4, 2020

Copy link
Copy Markdown
Contributor

@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

zhiics commented Sep 4, 2020

Copy link
Copy Markdown
Member

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