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

[Topi, Relay] Add cumprod #7722

Merged
merged 17 commits into from
Mar 25, 2021
Merged

Conversation

AndrewZhaoLuo
Copy link
Contributor

@AndrewZhaoLuo AndrewZhaoLuo commented Mar 22, 2021

Extends PR #7334 to also have a numpy style cumprod operation.

Creates the notion of a cumulative binary operation. This does what it sounds and assumes the binary operation is associative and commutative. By passing in an identity value we can also extend the notion to exclusive cumulative sums/products. Examples of other operations which would fit this bill include binary xor as well as binary and.

@masahi @mbrookhart please select people who would be suitable to review.

@AndrewZhaoLuo AndrewZhaoLuo changed the title [Topi, Relay] Add cumprod WIP: [Topi, Relay] Add cumprod Mar 22, 2021
@masahi masahi self-assigned this Mar 22, 2021
@AndrewZhaoLuo AndrewZhaoLuo changed the title WIP: [Topi, Relay] Add cumprod [Topi, Relay] Add cumprod Mar 23, 2021
@masahi
Copy link
Member

masahi commented Mar 23, 2021

You've got a merge issue, need to rebase.

@AndrewZhaoLuo AndrewZhaoLuo force-pushed the andrewzhaoluo-add-cumprod branch 4 times, most recently from da75c66 to 4ead969 Compare March 24, 2021 00:55
@AndrewZhaoLuo
Copy link
Contributor Author

@masahi PTAL

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

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

Looks nice. I suggest the following changes

  • combineop -> scanop
  • merge topi/cumsum.py and topi/cumprod.py into topi/scan.py (like the cuda version)
  • merge test_topi_cumsum.py and test_topi_cumprod.py to remove duplication. Something like what you have in relay/test_op_level3.py

@AndrewZhaoLuo
Copy link
Contributor Author

@masahi PTAL. I've implemented all your suggested changes.

Andrew Zhao Luo added 16 commits March 24, 2021 11:52
add cumprod and tests

reinstate tests

rethink
typos fix sum -> prod

more typos

more typo fixes

more typos

add doc strings
make exclusive a bool up and down stack

fix x

fix bool err

it is a bool now

fix

fix thing

formatting to pass linter

lint python

cumprod pylint

fix attribute

fix ordering

add exclusivity tests for end to end

fix things

cuda identity_value
simplify construction

clang-format

more tests

undo simpler construction due to function passing stuff

fix docs

more exclusive doc changes

more fixins"
Copy link
Contributor

@mbrookhart mbrookhart left a comment

Choose a reason for hiding this comment

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

Supporting exclusive for these ops adds quite a bit of complexity to the implementation and the testing, and it doesn't seem to exist in the numpy op. Are we sure we need it?

Otherwise LGTM.

Comment on lines +650 to +654
exclusive : bool, optional
If True, will return exclusive product in which the first element is not
included. In other terms, if True, the j-th output element would be
the product of the first (j-1) elements. Otherwise, it would be the product of
the first j elements.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think numpy has an exclusive option? Do we need this? https://numpy.org/doc/stable/reference/generated/numpy.cumprod.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll defer to @masahi on this. I do agree that it adds a lot of complexity for not much gain.

For what it's worth, thrust has inclusive and exclusive scan operations which is what may have motivated the current interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hehehe, I tagged the wrong line. I know why cuda scan needs to be inclusive or exclusive (it's for other ops), but I'm not sure why cumprod needs the option?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, ONNX cumsum has an exclusive option. There is a good use case for exclusive cumsum but probably not for cumprod. We can always do inclusive scan for cumprod.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well we might as well keep cumprod's exclusive option since it has very little implementation overhead. The only thing that is there to support it is the identity_value fields which are pretty simple. I say we might as well keep it at this point.

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jwfromm jwfromm left a comment

Choose a reason for hiding this comment

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

LGTM, very nicely written code. Thanks @AndrewZhaoLuo

@masahi masahi merged commit 8e23806 into apache:main Mar 25, 2021
@masahi
Copy link
Member

masahi commented Mar 25, 2021

thanks @AndrewZhaoLuo @mbrookhart @jwfromm

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
* make cumbinop, refactor cumsum, add cumprod

* cumsum exclusive test

* Add cumprod + flesh out cumsum tests

add cumprod and tests

reinstate tests

rethink

* add rudimentary scan implementation

* add attributes of cumprod node

* add cumprod strategy

* add cuda strategy

* python relay node construction

* change attrs to be reusuable

* add cumprod nodes

* complete tests

* Fix some typos about sum --> prod

typos fix sum -> prod

more typos

more typo fixes

more typos

add doc strings

* Use Bool instead of int to represent exclusive

make exclusive a bool up and down stack

fix x

fix bool err

it is a bool now

fix

fix thing

formatting to pass linter

lint python

cumprod pylint

fix attribute

fix ordering

add exclusivity tests for end to end

fix things

cuda identity_value

* Overall improve formatting, add doc message corrections

simplify construction

clang-format

more tests

undo simpler construction due to function passing stuff

fix docs

more exclusive doc changes

more fixins"

* merge cumsum and cumprod to scan, merge tests

fix stuff

* remove other mentions of cumbinop -> scanop

* lint formatting

Co-authored-by: Andrew Zhao Luo <andrewzhaoluo@Andrews-MacBook-Pro.local>
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
* make cumbinop, refactor cumsum, add cumprod

* cumsum exclusive test

* Add cumprod + flesh out cumsum tests

add cumprod and tests

reinstate tests

rethink

* add rudimentary scan implementation

* add attributes of cumprod node

* add cumprod strategy

* add cuda strategy

* python relay node construction

* change attrs to be reusuable

* add cumprod nodes

* complete tests

* Fix some typos about sum --> prod

typos fix sum -> prod

more typos

more typo fixes

more typos

add doc strings

* Use Bool instead of int to represent exclusive

make exclusive a bool up and down stack

fix x

fix bool err

it is a bool now

fix

fix thing

formatting to pass linter

lint python

cumprod pylint

fix attribute

fix ordering

add exclusivity tests for end to end

fix things

cuda identity_value

* Overall improve formatting, add doc message corrections

simplify construction

clang-format

more tests

undo simpler construction due to function passing stuff

fix docs

more exclusive doc changes

more fixins"

* merge cumsum and cumprod to scan, merge tests

fix stuff

* remove other mentions of cumbinop -> scanop

* lint formatting

Co-authored-by: Andrew Zhao Luo <andrewzhaoluo@Andrews-MacBook-Pro.local>
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