Skip to content

Better Shape Function Registration #3237

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

Closed
wants to merge 1 commit into 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 ready!

Name Link
🔨 Latest commit bc3254c
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-fbgemm-docs/deploys/6712c0500f4d8b0008ed0576
😎 Deploy Preview https://deploy-preview-3237--pytorch-fbgemm-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@facebook-github-bot
Copy link
Contributor

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

jwfromm added a commit to jwfromm/FBGEMM that referenced this pull request Oct 17, 2024
Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh

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

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

jwfromm added a commit to jwfromm/FBGEMM that referenced this pull request Oct 17, 2024
Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

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

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

jwfromm added a commit to jwfromm/FBGEMM that referenced this pull request Oct 17, 2024
Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

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

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

jwfromm added a commit to jwfromm/FBGEMM that referenced this pull request Oct 17, 2024
Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

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

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

jwfromm added a commit to jwfromm/FBGEMM that referenced this pull request Oct 17, 2024
Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

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

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

Summary:

X-link: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

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

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 4ba523c.

q10 pushed a commit to q10/FBGEMM that referenced this pull request Apr 10, 2025
Summary:
X-link: pytorch#3237

Pull Request resolved: facebookresearch/FBGEMM#338

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.

Reviewed By: jianyuh, jiawenliu64

Differential Revision: D64147797

fbshipit-source-id: 73b25394b3d65730ddb5cb1614536c007f918638
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