Skip to content

Support variadic returns in Schema's operator<<#23204

Closed
houseroad wants to merge 6 commits intogh/houseroad/7/basefrom
gh/houseroad/7/head
Closed

Support variadic returns in Schema's operator<<#23204
houseroad wants to merge 6 commits intogh/houseroad/7/basefrom
gh/houseroad/7/head

Conversation

@houseroad
Copy link
Member

@houseroad houseroad commented Jul 23, 2019

Stack from ghstack:

old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: D16433592

old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
} else if (schema.returns().size() > 1) {

const auto& returns = schema.returns();
if (schema.is_varret()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if varret is analogous to vararg, it should be appended after the previous args. So it'd be nice to do so for generality

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, let's make it nice :-)

old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
@pytorchbot pytorchbot added the module: tests Issues related to tests (not the torch.testing module) label Jul 24, 2019
out << schema.returns()[i].type()->str();

const auto& returns = schema.returns();
out << "(";
Copy link
Collaborator

Choose a reason for hiding this comment

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

so the change here to align returning tuple, right? is it why all of the expect files change? are you sure it's a safe change?

I'm still getting confused by how we treat tuple return vs multiple args tbh. cc @suo @zdevito

Copy link
Member Author

Choose a reason for hiding this comment

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

after some digging, I think this diff is fine with existing function schema parser. Here is the reasoning:

  1. when parsing the results, we automatically remove the outer pair of parentheses. related code This code also tells us multiple returns should be something like (int, float), one example is aten::divmod(int x, int y) -> (int, int) defined here

  2. since we use the outer pair parentheses to represent multi-returns, to return a tuple, we should use two pairs of parentheses. My updates on the expect files are actually correct, because the returns are all single tuples, one example

The test in #23208 already make sure that all the serialized schemas can be correctly parsed (i.e., parsed schemas are exactly equal to the original ones.)

Copy link
Member Author

Choose a reason for hiding this comment

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

also executed the following code:

        s1 = parse_schema('any(Tensor self, int dim, bool keepdim=False) -> (Tensor, Tensor)')
        s2 = parse_schema('any(Tensor self, int dim, bool keepdim=False) -> ((Tensor, Tensor))')
        print(len(s1.returns))
        print(len(s2.returns))

output is

2
1

this also shows that, for tuple, we should use '(())'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, existing parsing is a bit non-pythonic (as python would treat it as a tuple). However, I think we can land it avoid changing existing parser and schemas

old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Differential Revision: [D16433592](https://our.internmc.facebook.com/intern/diff/D16433592/)
@zou3519 zou3519 deleted the gh/houseroad/7/head branch July 26, 2019 18:00
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jul 26, 2019
Summary:
old: prim::PythonOp(...) ->
new: prim::PythonOp(...) -> ...

Pull Request resolved: pytorch/pytorch#23204
ghstack-source-id: 87208343

Reviewed By: zrphercule

Differential Revision: D16433592

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

This pull request has been merged in c8c5e11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: internals Related to internal abstractions in c10 and ATen module: tests Issues related to tests (not the torch.testing module)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants