-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
You've got a merge issue, need to rebase. |
da75c66
to
4ead969
Compare
@masahi PTAL |
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.
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
a37657d
to
23d4325
Compare
@masahi PTAL. I've implemented all your suggested changes. |
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"
4137c15
to
b9fb779
Compare
e04e03d
to
dbea713
Compare
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.
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.
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. |
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 don't think numpy has an exclusive option? Do we need this? https://numpy.org/doc/stable/reference/generated/numpy.cumprod.html
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'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.
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.
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?
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.
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.
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.
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.
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
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, very nicely written code. Thanks @AndrewZhaoLuo
thanks @AndrewZhaoLuo @mbrookhart @jwfromm |
* 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>
* 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>
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.