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

Better Shape Function Registration #3237

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jwfromm
Copy link
Contributor

@jwfromm jwfromm commented Oct 10, 2024

Summary:
torch.compile requires that custom operators have shape functions registered, as they are needed for tracing.

In FBGEMM, we have inconsistently registered such shape functions. This diff attempts to clean up and register a good number of commonly used operators.

Notably, pytorch allows two methods of registering shape functions for custom ops. In CPP, you can use a Meta function, or in python you can use register_fake. It turns out register_fake is the recommended and more powerful approach. For example, it is needed for ops that cross devices (such as the car ops) and is needed when exporting a traced graph.

This diff thus focuses on the register_fake method and converts a handful of Meta registrations to it. My hope is that this can provide an easily extensible way of registering shape functions for other kernel authors.

Differential Revision: D64147797

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D64147797

Copy link

netlify bot commented Oct 10, 2024

Deploy Preview for pytorch-fbgemm-docs failed.

Name Link
🔨 Latest commit 5f0bfb1
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-fbgemm-docs/deploys/67086499a849800008e044a2

Summary:
With the increasing use of torch.compile both internally and in open source, I wanted to take some time to think about how to best make our FBGEMM custom ops compile compatible. This diff attempts to implement a testable and scalable way of registering custom shape functions easily.

`torch.compile` requires that custom operators have shape functions registered, as they are needed for tracing.

In FBGEMM, we have inconsistently registered such shape functions. This diff attempts to clean up and register a good number of commonly used operators.

Notably, pytorch allows two methods of registering shape functions for custom ops. In CPP, you can use a Meta function, or in python  you can use `register_fake`. It turns out `register_fake` is the recommended and more powerful approach. For example, it is needed for ops that cross devices (such as the car ops) and is needed when exporting a traced graph.

This diff thus focuses on the register_fake method and converts a handful of Meta registrations to it. My hope is that this can provide an easily extensible way of registering shape functions for other kernel authors.

Differential Revision: D64147797
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D64147797

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.

2 participants