Skip to content

[JIT] min(li) max(li)#26351

Closed
eellison wants to merge 2 commits intopytorch:masterfrom
eellison:max_list
Closed

[JIT] min(li) max(li)#26351
eellison wants to merge 2 commits intopytorch:masterfrom
eellison:max_list

Conversation

@eellison
Copy link
Copy Markdown
Contributor

Add min and max of a list to JIT. Fixes #26036

@eellison eellison requested a review from apaszke as a code owner September 17, 2019 17:25
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: pybind Related to our Python bindings / interactions with other Python libraries labels Sep 17, 2019
Copy link
Copy Markdown
Contributor

@driazati driazati left a comment

Choose a reason for hiding this comment

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

It would be nice to have it for all our iterables like tuple and dict too

Comment thread test/test_jit.py Outdated
return max(li)


int_lists = [1], [2, 1, 2], [-3, 4, 2], [-2, -7, 1, 4], [2, 1, 0, 4]
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.

Check an empty list too

}
return repeated;
}
case TypeKind::BoolType:
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.

Does this fix #26036? Add it to the PR description if so

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 is in the PR description :')

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.

looool, I had the exact same question! I'll wait till this in, this way I don't have to fix my PR.

}

template <typename T>
int listMin(Stack& stack) {
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.

The copy paste isn't great, it could be 1 method that returns a std::tuple(min, max) then when used you can statically .get<1> or .get<0>

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.

See discussion here: #26155 (comment)

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.

Also i don't think doing twice as many comparisons is worth it either

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.

We might not necessarily save a whole lot here, since we would probably need lambda wrappers and get<0>, get<1> aren't very descriptive even in the context of Operator("min. We are probably very unlikely to ever hit an issue with these two functions to warrant the deduplication of the two?

@eellison
Copy link
Copy Markdown
Contributor Author

It would be nice to have it for all our iterables like tuple and dict too

It will already work for tuple because we allow homogenous tuples to match to lists. min() for heterogenous tuples isn't well-defined

Copy link
Copy Markdown
Contributor

@Krovatkin Krovatkin left a comment

Choose a reason for hiding this comment

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

:shipit:

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.

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

"aten::reverse(" decl_type "[](a!) self) -> ()", \
listReverse<value_type>, \
aliasAnalysisFromSchema()), \
Operator( \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we make these in the aten namespace instead of prim since these two have schema.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmmm seems like the previous one already in prim.. nvm.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@eellison merged this pull request in a06e1c3.

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Add min and max of a list to JIT. Fixes pytorch#26036
Pull Request resolved: pytorch#26351

Differential Revision: D17427547

Pulled By: eellison

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

Labels

Merged module: pybind Related to our Python bindings / interactions with other Python libraries oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jit] Bool list isn't being created in python -> script conversion

7 participants