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

Introduce lowbit quantized linear MPS kernels #954

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

manuelcandales
Copy link
Contributor

@manuelcandales manuelcandales commented Sep 26, 2024

Summary:
The following is the directory structure of the submitted code under torchao

experimental/
├── kernels/
│   └── mps/
│       ├── codegen/
│       │   └── gen_metal_shader_lib.py
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       ├── test/
│       │   └── (directly test mps kernel implementations)
│       └── metal.yaml
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)

Differential Revision: D63342895

Copy link

pytorch-bot bot commented Sep 26, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/954

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 6661971 with merge base 0f6bae5 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 26, 2024
@facebook-github-bot
Copy link

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

manuelcandales added a commit to manuelcandales/ao that referenced this pull request Sep 26, 2024
Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       └── test/
│       │   └── (directly test mps kernel implementations)
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

manuelcandales added a commit to manuelcandales/ao that referenced this pull request Sep 26, 2024
Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       └── test/
│       │   └── (directly test mps kernel implementations)
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

Left quite a few comments. Lets address those. At high level

  1. Figure out plan to how we gonna read .metal file. Likely similar to what torch does but see what MLX does too
  2. Better test cases

torchao/experimental/kernels/mps/metal/divbit.metal Outdated Show resolved Hide resolved
torchao/experimental/kernels/mps/metal/divbit.metal Outdated Show resolved Hide resolved
torchao/experimental/ops/mps/test/test_lowbit.py Outdated Show resolved Hide resolved
torchao/experimental/ops/mps/test/test_lowbit.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

Left quite a few comments. Lets address those. At high level

  1. Figure out plan to how we gonna read .metal file. Likely similar to what torch does but see what MLX does too
  2. Better test cases

manuelcandales added a commit to manuelcandales/ao that referenced this pull request Oct 9, 2024
Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       └── test/
│       │   └── (directly test mps kernel implementations)
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

manuelcandales added a commit to manuelcandales/ao that referenced this pull request Oct 10, 2024
Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       └── test/
│       │   └── (directly test mps kernel implementations)
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

torchao/experimental/kernels/mps/src/OperationUtils.h Outdated Show resolved Hide resolved
torchao/experimental/kernels/mps/src/OperationUtils.h Outdated Show resolved Hide resolved
torchao/experimental/kernels/mps/src/OperationUtils.h Outdated Show resolved Hide resolved
const std::string& source) {
NSError* error = nil;
MTLCompileOptions* options = [MTLCompileOptions new];
[options setLanguageVersion:MTLLanguageVersion3_1];
Copy link

Choose a reason for hiding this comment

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

You probably want to disable fast math here as well...

torchao/experimental/kernels/mps/src/dispatch.h Outdated Show resolved Hide resolved
torchao/experimental/kernels/mps/src/dispatch.h Outdated Show resolved Hide resolved
ext_modules=[
CppExtension(
name="torchao_mps_ops",
sources=["register.mm"],
Copy link

Choose a reason for hiding this comment

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

I think you either need to package your kernels into the wheel, or using bin2c just convert them to headers. Or convert them into a metallib

manuelcandales added a commit to manuelcandales/ao that referenced this pull request Oct 10, 2024
Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── codegen/
│       │   └── gen_metal_shader_lib.py
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       ├── test/
│       │   └── (directly test mps kernel implementations)
│       └── metal.yaml
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Reviewed By: malfet

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

Summary:

The following is the directory structure of the submitted code under torchao

```
experimental/
├── kernels/
│   └── mps/
│       ├── codegen/
│       │   └── gen_metal_shader_lib.py
│       ├── metal/
│       │   └── (metal shaders)
│       ├── src/
│       │   └── (tensor agnostic mps kernel implementations)
│       ├── test/
│       │   └── (directly test mps kernel implementations)
│       └── metal.yaml
└── ops/
    └── mps/
        ├── register.mm
        ├── setup.py
        └── test/
            └── (test torch custom ops)
```

Reviewed By: malfet

Differential Revision: D63342895
@facebook-github-bot
Copy link

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

@facebook-github-bot facebook-github-bot merged commit ad184da into pytorch:main Oct 10, 2024
18 of 19 checks passed
jainapurva pushed a commit that referenced this pull request Oct 15, 2024
Differential Revision: D63342895

Pull Request resolved: #954
yanbing-j pushed a commit to yanbing-j/ao that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants