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] Added how to write transformations section #51278

Closed
wants to merge 15 commits into from

Conversation

Chillee
Copy link
Contributor

@Chillee Chillee commented Jan 28, 2021

image

I still need to add links to vmap/grad/decomposition, but those haven't been added to the examples folder yet.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jan 28, 2021

💊 CI failures summary and remediations

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


None of the CI failures appear to be your fault 💚



🚧 1 ongoing upstream failure:

These were probably caused by upstream breakages that are not fixed yet.


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.

@Chillee Chillee requested a review from ansley January 28, 2021 10:01
Copy link

@ansley ansley left a comment

Choose a reason for hiding this comment

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

I left a lot of comments, but they're mostly just little grammar fixes that you'll be able to fix in a few seconds. I think it looks great! Thanks again for writing this. :)

docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
Copy link

@ansley ansley left a comment

Choose a reason for hiding this comment

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

Looks great!

@Chillee Chillee requested a review from ansley February 1, 2021 06:15
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Show resolved Hide resolved
- `Shape
Propagation <https://github.com/pytorch/pytorch/blob/master/torch/fx/experimental/shape_prop.py>`__
- `Roofline
Analyzer <https://github.com/pytorch/pytorch/blob/a9f88511b8155ba9620730fb175dee8c54e346d5/torch/fx/experimental/cost_model.py>`__
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should point to this pytorch/tutorials#1328

Copy link
Contributor Author

Choose a reason for hiding this comment

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

waiting for Brian to make a placeholder.

docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
fusion! <https://github.com/pytorch/pytorch/blob/ec86cec20a8a2312a2295d7bc8be6e88256a2de4/torch/fx/experimental/fuser.py>`__

For simple transformations that only consist of substitutions, you can also
make use of the `subgraph rewriter. <https://github.com/pytorch/pytorch/blob/master/torch/fx/subgraph_rewriter.py>`__
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should point this to the API reference section on replace_pattern when it lands

the shape information of tensors in your graph. In this case, instead of
looping over the FX graph and modifying it, you can write an interpreter
on top of the FX graph! As the FX IR is quite simple, it’s easy to
reimplement an interpreter that also captures your desired attributes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interpreter and Transformer are landed (https://github.com/pytorch/pytorch/blob/master/torch/fx/interpreter.py), so we should mention those here

Also I don't think the section header makes sense, you can do more than just analyses with the interpreter pattern. I'd suggest just making this section about "The Interpreter Pattern"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One somewhat awkward thing about the Interpreter/Transformer patterns are that the actual pattern itself is now hidden behind an abstraction in the shape propagation pass.

I think it's fine, so I'll just mention that you can implement the pattern using the interpreter module.

@jamesr66a jamesr66a added the fx label Feb 2, 2021
@Chillee Chillee requested a review from ansley February 2, 2021 18:58
that require a large amount of rewrite rules (such as vmap or grad),
this can often improve readability and maintainability of the rules.

TODO: Example transformations (need to be included first)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sure to update before landing

symbolic trace). This can be used for capturing shape information for
downstream passes, but it can also be used to capture other information
about execution.
TODO: Add roofline analysis pass once it gets merged.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sure to update before landing

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.

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

@jamesr66a
Copy link
Collaborator

Make sure to fix the docs build errors:

Feb 02 09:29:15 /var/lib/jenkins/workspace/docs/source/fx.rst:200: WARNING: Title level inconsistent:
Feb 02 09:29:15 
Feb 02 09:29:15 Dynamic Control Flow
Feb 02 09:29:15 ^^^^^^^^^^^^^^^^^^^^
Feb 02 09:29:15 /var/lib/jenkins/workspace/docs/source/fx.rst:173: WARNING: duplicate label fx:examples, other instance in /var/lib/jenkins/workspace/docs/source/fx.rst

@jamesr66a
Copy link
Collaborator

BTW I just tried patching this on top of master and it seems to be deleting the debugging section. You'll probably have to rebase manually

@jamesr66a
Copy link
Collaborator

Here's a patchfile of a manual rebase https://gist.github.com/jamesr66a/64c9301ccbde8cec7905818c6453689e

@Chillee
Copy link
Contributor Author

Chillee commented Feb 3, 2021

@jamesr66a Do you know why the docs builds are failing? Is it because of the warning?

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.

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

Copy link
Collaborator

@jamesr66a jamesr66a left a comment

Choose a reason for hiding this comment

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

Added a few comments while doing my full docs pass

docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
docs/source/fx.rst Outdated Show resolved Hide resolved
@jamesr66a
Copy link
Collaborator

@Chillee yes, allcaps WARNINGs will cause the docs build to fail. Really annoying how non-obvious that is

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.

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

@facebook-github-bot
Copy link
Contributor

@Chillee merged this pull request in f1a63b7.

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