Skip to content

functionalization: avoid some unnecessary view_copy calls#75819

Closed
bdhirsh wants to merge 6 commits intogh/bdhirsh/206/basefrom
gh/bdhirsh/206/head
Closed

functionalization: avoid some unnecessary view_copy calls#75819
bdhirsh wants to merge 6 commits intogh/bdhirsh/206/basefrom
gh/bdhirsh/206/head

Conversation

@bdhirsh
Copy link
Collaborator

@bdhirsh bdhirsh commented Apr 14, 2022

When we're performing a sync on a FuntionalTensorWrapper, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using functionalize() and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.

Stack from ghstack:

Differential Revision: D35705380

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Apr 14, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit f96d020 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@bdhirsh bdhirsh requested review from albanD and ezyang April 14, 2022 20:25
@bdhirsh bdhirsh changed the title avoid some unnecessary view_copy calls functionalization: avoid some unnecessary view_copy calls Apr 14, 2022
bdhirsh added 2 commits April 14, 2022 13:37
When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM 

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.




[ghstack-poisoned]
When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM 

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.




[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Apr 14, 2022
and exporting it to fbcode
(not actually landing tis)

[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request Apr 14, 2022
and exporting it to fbcode
(not actually landing tis)

ghstack-source-id: b486c57
Pull Request resolved: #75835
bdhirsh added a commit that referenced this pull request Apr 14, 2022
bdhirsh added a commit that referenced this pull request Apr 14, 2022
and exporting it to fbcode
(not actually landing tis)

ghstack-source-id: b486c57
Pull Request resolved: #75835
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.

Nice! Having a test would be even better!

When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM 

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.




[ghstack-poisoned]
bdhirsh added 2 commits April 15, 2022 15:26
When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM 

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.




[ghstack-poisoned]
When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc @ZolotukhinM 

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.




[ghstack-poisoned]
@bdhirsh
Copy link
Collaborator Author

bdhirsh commented Apr 17, 2022

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

@facebook-github-bot
Copy link
Contributor

@pytorchbot merge this

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

Merge failed due to Command git -C /home/runner/work/pytorch/pytorch push origin master returned non-zero exit code 1
To https://github.com/pytorch/pytorch
! [remote rejected] master -> master (cannot lock ref 'refs/heads/master': is at 7be1b29 but expected 4c7b4b5)
error: failed to push some refs to 'https://github.com/pytorch/pytorch'

Raised by https://github.com/pytorch/pytorch/actions/runs/2185815423

@bdhirsh
Copy link
Collaborator Author

bdhirsh commented Apr 18, 2022

@pytorchmergebot merge this please

@github-actions
Copy link
Contributor

Hey @bdhirsh.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request Apr 18, 2022
Summary:
Pull Request resolved: #75819

When we're performing a sync on a `FuntionalTensorWrapper`, right now we first apply any updates to the base, and then we unconditionally regenerate the current tensor from the base.

This came up in the context of mobile using `functionalize()` and seeing an extra copy, so I have tests in a corresponding functorch PR: https://github.com/pytorch/functorch/pull/678/files#diff-449582f4f3e1ae76a73397c4b8ca62cc9dd5235dd831187f143180b498dee332R2872

cc ZolotukhinM

We can avoid some unnecessary copies going to the backend if we skip the regenerating when we know that there weren't any updates to apply.

Test Plan: Imported from OSS

Reviewed By: zhxchen17

Differential Revision: D35705380

Pulled By: bdhirsh

fbshipit-source-id: acd6811b4ca45e3b9d277496b391994fc7240927
@facebook-github-bot facebook-github-bot deleted the gh/bdhirsh/206/head branch April 22, 2022 14:17
bdhirsh added a commit that referenced this pull request May 11, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 11, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 13, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 13, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 18, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 19, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 20, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 20, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 20, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 20, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 23, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 23, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 24, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 24, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 24, 2022
…iews of same base"

welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
bdhirsh added a commit that referenced this pull request May 24, 2022
welp, I realized my "perf improvement" from #75819 was wrong. This originally came up because `functionalize()` was sometimes emit an unnecessary `view_copy`, but there's a more correct fix that I can make inside of functorch, which I have here: pytorch/functorch#795






[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants