Skip to content

[ivalue] Add tuple constructor + to<std::tuple<Args...>>#26668

Closed
bwasti wants to merge 1 commit intopytorch:masterfrom
bwasti:ivalue_tuple
Closed

[ivalue] Add tuple constructor + to<std::tuple<Args...>>#26668
bwasti wants to merge 1 commit intopytorch:masterfrom
bwasti:ivalue_tuple

Conversation

@bwasti
Copy link
Contributor

@bwasti bwasti commented Sep 23, 2019

This PR adds the ability to use tuples directly with the IValue constructor rather than the vector approach

@pytorchbot pytorchbot added module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen labels Sep 23, 2019
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Sep 23, 2019
@bwasti bwasti requested a review from ezyang September 23, 2019 21:03
@bwasti bwasti changed the title [ivalue] Add tuple constructor/destructor [ivalue] Add tuple constructor + to<std::tuple<Args...>> Sep 23, 2019
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably better if we use SFINAE based on is_constructible<IValue, Args>..., if it works.

@ezyang ezyang requested review from smessmer and zdevito September 24, 2019 14:10
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please make this constructor private?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, we seem to have a polyfill for std::apply in C++17.h, can we just use that directly here?

Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

I think this could be simpler.

@ezyang
Copy link
Contributor

ezyang commented Sep 24, 2019

cc'ed @smessmer for C++ guidance, and @zdevito to sanity check that IValue should take tuple arguments (I think it should)

@bwasti
Copy link
Contributor Author

bwasti commented Sep 24, 2019

simplified it a bit and address sfinae comment

note: I didn't use ghstack for this so it has some (two lines) of the changes in #26739
they will go away soon

Copy link
Contributor

Choose a reason for hiding this comment

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

This is pleasing to my eye!

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: avoid dumping helper functions like this in global namespace; put it in namespace detail { ... } or similar

Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a runtime test that the number of elements in the tuple matches the number of arguments in the parameter pack. I don't see that test in this function, or the function above.

Copy link
Contributor

@ezyang ezyang 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, but we need that runtime test that the number of tuple elements matches the IValue...

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

No issues beyond what @ezyang has mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should not be part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, sorry -- I mentioned that in an above comment (I didn't use ghstack for this). will go away

@bwasti
Copy link
Contributor Author

bwasti commented Sep 25, 2019

updated -- the windows build failure looks legit so I'm looking into that

edit: it's just this bug #25389

@bwasti bwasti requested a review from ezyang September 27, 2019 18:34
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... an assert? The existing guidance in this file is a bit murky: it is true most of the type tests are done using AT_ASSERT, but that old mean actually means that we haven't appropriately applied the guidance from #20287

I think ivalue tests should be done with TORCH_CHECK. The reasoning is that IValue is part of the public C++ API, and a user may very well attempt to extract an IValue at the wrong type. IT would be wrong for them to report an error message to PyTorch in that case.

Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

yay!

Copy link
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.

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

Copy link
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.

@bwasti is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 30, 2019
Summary:
This PR adds the ability to use tuples directly with the IValue constructor rather than the vector<IValue> approach
Pull Request resolved: pytorch/pytorch#26668

Differential Revision: D17668653

Pulled By: bwasti

fbshipit-source-id: aff7f62fe3b502df78b28b2355cff88d88ad288c
@facebook-github-bot
Copy link
Contributor

@bwasti merged this pull request in e083387.

pdlive215 pushed a commit to pdlive215/pytorch that referenced this pull request Nov 27, 2019
Summary:
This PR adds the ability to use tuples directly with the IValue constructor rather than the vector<IValue> approach
Pull Request resolved: pytorch#26668

Differential Revision: D17668653

Pulled By: bwasti

fbshipit-source-id: aff7f62fe3b502df78b28b2355cff88d88ad288c
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
This PR adds the ability to use tuples directly with the IValue constructor rather than the vector<IValue> approach
Pull Request resolved: pytorch#26668

Differential Revision: D17668653

Pulled By: bwasti

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

Labels

Merged module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants