cupertino-sample-code/metal-customizing-a-pytorch-operation
Mihaela Mihaljevic 37fd4fb24f Initial commit: 606 Apple sample code projects
MIT License - Apple Developer sample code
Downloaded via Cupertino (https://github.com/mihaelamj/cupertino)
2025-12-03 00:19:12 +01:00
..
LICENSE Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
.gitignore Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
compiler.py Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
CustomSoftshrink.h Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
CustomSoftshrink.mm Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
README.md Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
run_sample.py Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00
softshrink.py Initial commit: 606 Apple sample code projects 2025-12-03 00:19:12 +01:00

Customizing a PyTorch operation

Implement a custom operation in PyTorch that uses Metal kernels to improve performance.

Overview

Configure the sample code project

Before you run the sample code project:

  1. Follow the instructions in Accelerated PyTorch training on Mac.

  2. Install PyTorch nightly (Python 3.7 or later is required).

    pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
    
  3. Install Ninja

    pip3 install Ninja
    
  4. Run the sample.

    python3 run_sample.py