Skip to content

Add namedtuple return for min, median, mode, kthvalue, add test for namedtuple return API#16186

Closed
zasdfgbnm wants to merge 65 commits intopytorch:masterfrom
zasdfgbnm:more-namedtuple-return
Closed

Add namedtuple return for min, median, mode, kthvalue, add test for namedtuple return API#16186
zasdfgbnm wants to merge 65 commits intopytorch:masterfrom
zasdfgbnm:more-namedtuple-return

Conversation

@zasdfgbnm
Copy link
Collaborator

This partially fixes #394 and depend on #15429. I suggest to review this only after #15429 get landed, otherwise the diff might be large to review.

The test only allows explicitly whitelisted operators to have named return.

cc: @ezyang


path = os.path.dirname(os.path.realpath(__file__))
aten_native_yaml = os.path.join(path, '../aten/src/ATen/native/native_functions.yaml')
whitelist = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we intend to give all functions named outputs in short order? In this case, I don't feel like this test case is giving us much utility, except perhaps reminding us to carefully audit choice of named outputs. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ezyang Yes, I added this test simply to remind people be careful on these names, because this might be a point people could easily forget. I'm OK with removing it if this won't be a problem.

@zasdfgbnm
Copy link
Collaborator Author

zasdfgbnm commented Jan 29, 2019

@ezyang There is no strong reason for disabling the name of fractional max pool, just because this name was given before the nametuple return merged. So I'm planning to disable it for now and add back in later PRs. Do you think I should revert the changes on fractional max pool?

Edit: I think at least we should rename the return name of fractional max pool from (output, indices) to (values, indices), which matches with the output of max, min, etc., what do you think?

@zasdfgbnm
Copy link
Collaborator Author

Due to the merge of #16111, I think now this PR depend on #16253 to make codegen to copy field names to JIT.

@ezyang
Copy link
Contributor

ezyang commented Jan 29, 2019

I think I'm OK to codify the outputs of FractionalMaxPool as (output, indices); this is consistent with documentation and the naming of input arguments. Let's keep it.

You need to rebase this PR, is that right?

@zasdfgbnm
Copy link
Collaborator Author

@ezyang Do you mean rebase on #16253? I believe this would fix all the fails, but not tested yet. I would just wait for #16253 to be landed and then work on this.

@zasdfgbnm
Copy link
Collaborator Author

zasdfgbnm commented Feb 11, 2019

@ezyang This should be ready for review now after merging with master.

Is it OK that I remove the return name of fractional max pooling in this PR, and add them back in following PRs together with other max pooling operators (including 1d and 2d fractional max pooling)?

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.

okey dokey

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.

@ezyang 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.

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

@ezyang
Copy link
Contributor

ezyang commented Feb 15, 2019

Ugh, this needs a merge with master now :(

@ezyang
Copy link
Contributor

ezyang commented Feb 15, 2019

I attempted a merge, if you could look it over that would be appreciated.

@zasdfgbnm
Copy link
Collaborator Author

@ezyang Did you just resolve a merge conflict? I read through this diff, it looks good to me.

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.

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

facebook-github-bot pushed a commit that referenced this pull request Feb 16, 2019
…amedtuple return API (#16186)

Summary:
This partially fixes #394 and depend on #15429. I suggest to review this only after #15429 get landed, otherwise the diff might be large to review.

The test only allows explicitly whitelisted operators to have named return.

Differential Revision: D14070735

Pulled By: ezyang

fbshipit-source-id: ace2a672998b4e4a8094f52cbda5aa1cea6e3b42
@zasdfgbnm
Copy link
Collaborator Author

Closing since it is merged now. @ezyang Please put #16950 to a higher priority than my other related PR. I need this to be able to build and continue working on #17195.

@zasdfgbnm zasdfgbnm closed this Feb 16, 2019
@zasdfgbnm zasdfgbnm deleted the more-namedtuple-return branch February 16, 2019 14:13
>>> torch.kthvalue(x,2,0,True)
(tensor([[ 4., 5., 6.]]), tensor([[ 1, 1, 1]]))
>>> torch.kthvalue(x, 2, 0, True)
torch.return_types.kthvalue(values=tensor([[4., 5., 6.]]), indices=tensor([[1, 1, 1]]))
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 do something to avoid printing this really long type? We can pretend that all of them are a ResultTuple or sth like that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are customizing the printing at #17136

facebook-github-bot pushed a commit that referenced this pull request Mar 26, 2019
Summary:
More ops for #394. ~~Also need to rebase after landing #16186, because we need to update the whitelist of the new unit test added in #16186.~~

cc: ezyang
Pull Request resolved: #17093

Differential Revision: D14620068

Pulled By: ezyang

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return namedtuples from torch.* function with multiple return arguments

5 participants