Skip to content

Better Shape Function Registration#3237

Closed
jwfromm wants to merge 1 commit into
pytorch:mainfrom
jwfromm:export-D64147797
Closed

Better Shape Function Registration#3237
jwfromm wants to merge 1 commit into
pytorch:mainfrom
jwfromm:export-D64147797

Conversation

@jwfromm

@jwfromm jwfromm commented Oct 10, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@netlify

netlify Bot commented Oct 10, 2024

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 4ba523c.

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