<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "Xcode: 14.3.0 -"
  ],
  "documentType" : "article",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/training-a-neural-network-using-mps-graph",
  "metadataVersion" : "0.1.0",
  "role" : "sampleCode",
  "title" : "Training a neural network using MPSGraph"
}
-->

# Training a neural network using MPSGraph

Train a simple neural network digit classifier.

## Discussion

The sample code describes how to write a neural network using [`MPSGraph`](doc://com.apple.documentation/documentation/MetalPerformanceShadersGraph/MPSGraph) and how to train the network to recognize a digit in an image.
The sample trains a network for 300 iterations on a batch size of 40 images.
You’ll see how to set up training of weights and biases using data sources, including how to initialize and update weights.
You’ll also see how to validate the network using a test dataset.

> Note: This sample code project is associated with WWDC 2020 session [10677: Build customized ML models with the Metal Performance Shaders Graph](https://developer.apple.com/wwdc20/10677/).

You can use any dataset of your choice to train this model.  The following dataset works well for this purpose:

[MNIST Dataset](http://yann.lecun.com/exdb/mnist/)

Please note that Apple doesn’t own the copyright to this dataset nor makes any representations about the applicable terms of use for this dataset.

If you choose to use this dataset, the sample includes a script that downloads the dataset from that location and pass it as input to the model.

### Configure the sample code project

This sample requires the following system and software configuration:

- macOS 11 or later
- iOS 14 or later
- Xcode 12 or later

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)