Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functionalization: add a copy() native function #76083

Closed
wants to merge 9 commits into from

Conversation

bdhirsh
Copy link
Contributor

@bdhirsh bdhirsh commented Apr 20, 2022

Right now the functionalization codegen has special logic to handle copy_(). Instead, in this PR I add an at::copy native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

copy() decomposes into to and expand, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since copy() decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because at::copy() really just exists for the functionalization pass anyway.

Existing tests for copy_ in test_functionalization.py should test the change (since the end-result trace is the same).

Stack from ghstack:

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Apr 20, 2022

🔗 Helpful links

💊 CI failures summary and remediations

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

Expand to see more
  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages

See GitHub Actions build pull / linux-bionic-py3.7-clang9 / test (default, 1, 2, linux.2xlarge) (1/1)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-04-25T22:33:34.3858700Z RuntimeError: test_dataloader failed!
2022-04-25T22:33:34.2007869Z Generated XML report: test-reports/python-unittest/test_dataloader/TEST-TestCustomPinFn-20220425223243.xml
2022-04-25T22:33:34.2011568Z Generated XML report: test-reports/python-unittest/test_dataloader/TEST-TestDataLoader2-20220425223243.xml
2022-04-25T22:33:34.2015335Z Generated XML report: test-reports/python-unittest/test_dataloader/TEST-TestDataLoader2_EventLoop-20220425223243.xml
2022-04-25T22:33:34.2018142Z Generated XML report: test-reports/python-unittest/test_dataloader/TEST-TestIndividualWorkerQueue-20220425223243.xml
2022-04-25T22:33:34.2021015Z Generated XML report: test-reports/python-unittest/test_dataloader/TEST-TestStringDataLoader-20220425223243.xml
2022-04-25T22:33:34.3852004Z Traceback (most recent call last):
2022-04-25T22:33:34.3852510Z   File "test/run_test.py", line 1063, in <module>
2022-04-25T22:33:34.3854651Z     main()
2022-04-25T22:33:34.3855022Z   File "test/run_test.py", line 1041, in main
2022-04-25T22:33:34.3858399Z     raise RuntimeError(err_message)
2022-04-25T22:33:34.3858700Z RuntimeError: test_dataloader failed!
2022-04-25T22:33:34.6152198Z 
2022-04-25T22:33:34.6152470Z real	38m30.351s
2022-04-25T22:33:34.6152746Z user	110m52.024s
2022-04-25T22:33:34.6152971Z sys	9m26.906s
2022-04-25T22:33:34.6153331Z + cleanup
2022-04-25T22:33:34.6153527Z + retcode=1
2022-04-25T22:33:34.6153751Z + set +x
2022-04-25T22:33:34.6190921Z ##[error]Process completed with exit code 1.
2022-04-25T22:33:34.6318695Z ##[group]Run pytorch/pytorch/.github/actions/get-workflow-job-id@master
2022-04-25T22:33:34.6318944Z with:

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 a review from ezyang April 20, 2022 13:41
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
Right now the functionalization codegen has special logic to handle `copy_()`. Instead, in this PR I add an `at::copy` native function (not exposed to python), and effectively move that logic into C++ and out of the codegen.

`copy()` decomposes into `to` and `expand`, and it's CompositeImplicitAutograd so it won't appear in traces.

One annoying thing - since `copy()` decomposes into a view op, and it decomposes "underneath" functionalization, I need to manually handle the case where we want to remove view ops from the functionalization pass. This feels not-too-awful mostly because `at::copy()` really just exists for the functionalization pass anyway.

Existing tests for `copy_` in `test_functionalization.py` should test the change (since the end-result trace is the same).




[ghstack-poisoned]
@bdhirsh
Copy link
Contributor Author

bdhirsh commented Apr 25, 2022

@pytorchbot merge this please

@github-actions
Copy link

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.

@bdhirsh bdhirsh reopened this Apr 25, 2022
@seemethere seemethere closed this Apr 25, 2022
facebook-github-bot pushed a commit that referenced this pull request Apr 26, 2022
Summary:
Pull Request resolved: #76083

Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/5da76acd1d8ad1c40f8d58d52a12aa215dbae7ce

Reviewed By: osalpekar

Differential Revision: D35938186

Pulled By: bdhirsh

fbshipit-source-id: 4a93d39088b5944cf4911c9c08feb549ecb72ac3
@facebook-github-bot facebook-github-bot deleted the gh/bdhirsh/209/head branch April 29, 2022 14:17
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.

None yet

4 participants