Skip to content

Conversation

@shunting314
Copy link
Contributor

@shunting314 shunting314 commented Apr 6, 2022

Stack from ghstack (oldest at bottom):

For some models in torchbench (e.g. pyhpc_isoneutral_mixing), dynamo will generate Fx graphs that has side effects . Those graphs may

  • return an empty tuple
  • change tensors passed in as forward method arguments in-place

This makes the Dynamo+LTC integration fail since we extract compiled graph based on the lazy tensors returned from the forward method. From an empty tuple, we extract nothing.

To solve this problem, we extract compile graph from union(argument lazy tensors, returned lazy tensors) instead. The inplace mutations applied to argument lazy tensors will be captured this way.

Test plan:

pytest test/lazy/test_extract_compiled_graph.py
LTC_TS_CUDA=1 gpui time python torchbench.py --speedup-ltc -dcuda --nvfuser --randomize-input --only pyhpc_isoneutral_mixing

Differential Revision: D35478799

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Apr 6, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 171ea7a (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.

shunting314 added a commit that referenced this pull request Apr 6, 2022
ghstack-source-id: ef07446
Pull Request resolved: #75359
assert len(res) == len(args_and_out)
for i, arg in enumerate(args):
# only copy those tensors that get inplace updated
if arg is not res[i]:
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this 'is' check actually check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what does this 'is' check actually check?

So we compiled a graph for union(argument lazy tensors, returned lazy tensors). That graph will return (after duplication in case some tensors are duplicated) all the argument tensors at the beginning of the list. There are 2 cases

  • some of those argument tensors may get inplace updated. In that case, the graph will return a new copy of the tensor. We need copy the content back to the argument
  • other arguments may not get any inplace update. In that case, we can skip the copying.

Removing the 'is' check should also work but make things a bit slower.

@shunting314 shunting314 requested a review from wconstab April 7, 2022 00:34
For some models in torchbench (e.g. pyhpc_isoneutral_mixing), dynamo will generate Fx graphs that has side effects . Those graphs may
- return an empty tuple
- change tensors passed in as forward method arguments in-place

This makes the Dynamo+LTC integration fail since we extract compiled graph based on the lazy tensors returned from the forward method. From an empty tuple, we extract nothing.

To solve this problem, we extract compile graph from `union(argument lazy tensors, returned lazy tensors)` instead. The inplace mutations applied to argument lazy tensors will be captured this way.


Test plan:
```
pytest test/lazy/test_extract_compiled_graph.py
```

```
LTC_TS_CUDA=1 gpui time python torchbench.py --speedup-ltc -dcuda --nvfuser --randomize-input --only pyhpc_isoneutral_mixing
```

[ghstack-poisoned]
shunting314 added a commit that referenced this pull request Apr 7, 2022
ghstack-source-id: 47bb715
Pull Request resolved: #75359
@shunting314
Copy link
Contributor Author

@shunting314 has imported 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 Apr 8, 2022
Summary:
Pull Request resolved: #75359

For some models in torchbench (e.g. pyhpc_isoneutral_mixing), dynamo will generate Fx graphs that has side effects . Those graphs may
- return an empty tuple
- change tensors passed in as forward method arguments in-place

This makes the Dynamo+LTC integration fail since we extract compiled graph based on the lazy tensors returned from the forward method. From an empty tuple, we extract nothing.

To solve this problem, we extract compile graph from `union(argument lazy tensors, returned lazy tensors)` instead. The inplace mutations applied to argument lazy tensors will be captured this way.

Test Plan:
```
pytest test/lazy/test_extract_compiled_graph.py
```

```
LTC_TS_CUDA=1 gpui time python torchbench.py --speedup-ltc -dcuda --nvfuser --randomize-input --only pyhpc_isoneutral_mixing
```

Reviewed By: ZolotukhinM

Differential Revision: D35478799

Pulled By: shunting314

fbshipit-source-id: 8116768fc50fe7630e481e6039319ddf5c6a9416
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

Hey @shunting314.
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 facebook-github-bot deleted the gh/shunting314/20/head branch April 11, 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.

4 participants