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

[FX] Add Interpreter and Transformer #50420

Closed
wants to merge 12 commits into from

Conversation

jamesr66a
Copy link
Collaborator

@jamesr66a jamesr66a commented Jan 12, 2021

Stack from ghstack:

  1. Codify the interpreter pattern that was used, for ex, in shape prop. This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

  2. Add a small Transformer class that is an Interpreter but provides a transform method that yields a GraphModule from interpreting the code

image
image

TODO:

  • Write docstrings
  • Write docs
  • Look for more places this can be used

Differential Revision: D25880330

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jan 12, 2021

💊 CI failures summary and remediations

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


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

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

jamesr66a pushed a commit that referenced this pull request Jan 12, 2021
ghstack-source-id: 9a68a477723120d2fa256450dbe8d75c3eb19a8c
Pull Request resolved: #50420
@Chillee
Copy link
Contributor

Chillee commented Jan 14, 2021

I think it might be easier to implement vmap with this.

1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

TODO:

- [ ] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
jamesr66a pushed a commit that referenced this pull request Jan 26, 2021
ghstack-source-id: 04dc1ab9f73d27ed33bae333349ef27fb2bfe126
Pull Request resolved: #50420
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

TODO:

- [ ] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

TODO:

- [ ] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
@jamesr66a jamesr66a changed the title [WIP][FX] Add Interpreter and Transformer [FX] Add Interpreter and Transformer Jan 26, 2021
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

TODO:

- [x] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [ ] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
jamesr66a pushed a commit that referenced this pull request Jan 27, 2021
ghstack-source-id: 9c449a5c6205a7e78e30bf5fb9e71e89db5d99ce
Pull Request resolved: #50420
Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks pretty reasonable. I have a few suggestions to better decompose the components into reusable parts.

torch/fx/interpreter.py Outdated Show resolved Hide resolved
torch/fx/interpreter.py Outdated Show resolved Hide resolved
torch/fx/interpreter.py Outdated Show resolved Hide resolved
.. autoclass:: torch.fx.Interpreter
:members:

.. autoclass:: torch.fx.Transformer
Copy link
Contributor

Choose a reason for hiding this comment

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

still need a different name for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't heard any good suggestions for this. Is the concern that this is the same name as the Transformer architecture? In that case, I would argue that "Transformer" is a terrible name for that architecture and I don't think we should let them squat on an English language common noun

torch/fx/interpreter.py Outdated Show resolved Hide resolved
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [x] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [x] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
jamesr66a pushed a commit that referenced this pull request Jan 29, 2021
ghstack-source-id: 9d200c9512549670d0c78e7ba86bb38cf3f79b4a
Pull Request resolved: #50420
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [x] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
jamesr66a pushed a commit that referenced this pull request Jan 30, 2021
ghstack-source-id: 67c6b316a18cfe576c0a33d64f5a376788d3189b
Pull Request resolved: #50420
1. Codify the interpreter pattern that was used, for ex, in [shape prop](https://github.com/pytorch/pytorch/blob/c3b4b2062748ed70e689f9f9ffe670e6fa20a071/torch/fx/experimental/shape_prop.py#L7). This is a pattern users will likely find repeatedly useful so it's good to have it first-class in the API. As seen in the test cases, this makes it incredibly easy to do simple analysis and transforms like swapping out individual nodes

2. Add a small `Transformer` class that is an `Interpreter` but provides a `transform` method that yields a GraphModule from interpreting the code

![image](https://user-images.githubusercontent.com/4685384/105924691-a7b0b700-5ff3-11eb-8de8-7967d6b8ac69.png)
![image](https://user-images.githubusercontent.com/4685384/105924696-abdcd480-5ff3-11eb-8454-a2bc36c3248e.png)


TODO:

- [x] Write docstrings
- [x] Write docs
- [ ] Look for more places this can be used

Differential Revision: [D25880330](https://our.internmc.facebook.com/intern/diff/D25880330)

[ghstack-poisoned]
jamesr66a pushed a commit that referenced this pull request Jan 30, 2021
ghstack-source-id: 5f2bd6fd7aeacb31455b55fa9eb3a30144583826
Pull Request resolved: #50420
@facebook-github-bot
Copy link
Contributor

@jamesr66a merged this pull request in 609f76f.

@facebook-github-bot facebook-github-bot deleted the gh/jamesr66a/350/head branch February 5, 2021 15:21
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