---
title: Customizing a PyTorch operation
framework: metal
role: sampleCode
role_heading: Sample Code
path: metal/customizing-a-pytorch-operation
---

# Customizing a PyTorch operation

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

## Overview

Overview note: This sample code project is associated with WWDC23 session 10050: Optimize machine learning for Metal apps. Configure the sample code project Before you run the sample code project: Follow the instructions in Accelerated PyTorch training on Mac. Install PyTorch nightly (Python 3.7 or later is required). pip3 install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu Install Ninja pip3 install Ninja Run the sample. python3 run_sample.py

## See Also

### Compute workflows

- [Performing calculations on a GPU](metal/performing-calculations-on-a-gpu.md)
- [Selecting device objects for compute processing](metal/selecting-device-objects-for-compute-processing.md)
- [Customizing a TensorFlow operation](metal/customizing-a-tensorflow-operation.md)
