https://github.com/johanli233/pytorchmetaldemo
This is a simple demo that implements a custom operation in PyTorch that uses Metal kernels in cpp.
https://github.com/johanli233/pytorchmetaldemo
metal mps pytorch
Last synced: about 1 month ago
JSON representation
This is a simple demo that implements a custom operation in PyTorch that uses Metal kernels in cpp.
- Host: GitHub
- URL: https://github.com/johanli233/pytorchmetaldemo
- Owner: JohanLi233
- License: mit
- Created: 2024-12-06T08:21:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-07T08:43:16.000Z (over 1 year ago)
- Last Synced: 2025-03-29T07:44:56.141Z (about 1 year ago)
- Topics: metal, mps, pytorch
- Language: C++
- Homepage:
- Size: 204 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyTorchMetalDemo
PyTorchMetalDemo is a demonstration project showcasing how to use Apple's Metal API with PyTorch to perform custom tensor operations on macOS devices with MPS (Metal Performance Shaders) support.
## Features
- Implements a custom tensor fill operation using Metal.
- Implements a custom tensor add operation using Metal.
- Demonstrates integration of Metal with PyTorch.
## Requirements
- macOS with Metal support
- PyTorch with MPS backend support
- Xcode command line tools
- Python 3.12
- uv package manager (https://github.com/astral-sh/uv) or any other python package manager
## Metal CPP
The metal-cpp package was downloaded from [here](https://developer.apple.com/metal/cpp/#:~:text=1.%20Prepare%20your%20Mac.). If you are not using macOS 15, please download the appropriate version from [this link](https://developer.apple.com/metal/cpp/#:~:text=1.%20Prepare%20your%20Mac.).
# Check [Real Use Cases of Customizing kernels Here](https://github.com/JohanLi233/causal-conv1d-mps)
## Usage
``` bash
git clone https://github.com/JohanLi233/PyTorchMetalDemo.git
cd PyTorchMetalDemo
# create venv
uv venv --python=3.12
source .venv/bin/activate
uv pip install -r requirements.txt
uv pip install -e .
python test.py
```