Skip to content

Add support for lists for prim::min and prim::max#26155

Closed
Krovatkin wants to merge 2 commits intopytorch:masterfrom
Krovatkin:krovatkin/min_lists
Closed

Add support for lists for prim::min and prim::max#26155
Krovatkin wants to merge 2 commits intopytorch:masterfrom
Krovatkin:krovatkin/min_lists

Conversation

@Krovatkin
Copy link
Copy Markdown
Contributor

No description provided.

@Krovatkin Krovatkin requested a review from apaszke as a code owner September 13, 2019 06:24
@pytorchbot pytorchbot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Sep 13, 2019
@Krovatkin Krovatkin requested a review from eellison September 13, 2019 06:24
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good, couple comments

Comment thread test/test_jit.py Outdated
Copy link
Copy Markdown
Contributor

@eellison eellison Sep 13, 2019

Choose a reason for hiding this comment

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

nit: combine test_min_list and test_max_list and then rewrite inputs as a pairwise iteration over a list of inputs ? would be much shorter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's a little tricky since I have empty-list tests and those will get typed as Tensor[]. Let me see if I can make it look a bit better.

Copy link
Copy Markdown
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 they will get typed as Tensor[] since they're inputs to the function

Comment thread torch/csrc/jit/register_prim_ops.cpp Outdated
Copy link
Copy Markdown
Contributor

@eellison eellison Sep 13, 2019

Choose a reason for hiding this comment

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

It would be nice if there was a way to write minList and maxList as one function, since the only difference is the comparator... i dont think theres a nice way of doing it though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think there's a way: multiplying by -1 both sides is equivalent to switching from < to >, but I don't think it's worthwhile to deduplicate these two functions at the expense of readability. And I hope we won't hit a bug with these, since min/max of lists is a fairly canonical problem to the point everyone just remembers it by heart.

Comment thread torch/csrc/jit/register_prim_ops.cpp Outdated
Copy link
Copy Markdown
Contributor

@eellison eellison Sep 13, 2019

Choose a reason for hiding this comment

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

thx!

edit: actually - i thought you were adding supporting for max(list) but you're adding support for max(list1, list2) (which is also good). since you are doing the latter not the form do you mind dropping this? sorry for confusion.

Comment thread test/test_jit.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lists here are int

@eellison
Copy link
Copy Markdown
Contributor

eellison commented Sep 16, 2019

This will give a runtime error when used with a boollist bc of #26036... Could you remove the registered op for ([]bool, []bool) or fix the implementation?

Edit: nvm this should be fine, I fix this in #26351

@eellison eellison mentioned this pull request Sep 17, 2019
fix prim::int(int[] x) case when x = []

refactor tests

merge min/max tests

remove 0-length prim::min support

fix clang-tidy errors

add bools case back
Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Krovatkin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@Krovatkin merged this pull request in 18eb92e.

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary: Pull Request resolved: pytorch#26155

Differential Revision: D17455540

Pulled By: Krovatkin

fbshipit-source-id: e3aee465d108b59691d6c68f85fbf212a5d6a125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants