<!--
{
  "availability" : [
    "iOS: 14.0.0 - 17.4.0",
    "iPadOS: 14.0.0 - 17.4.0",
    "macCatalyst: 14.0.0 - 17.4.0",
    "macOS: 11.0.0 - 14.3.0",
    "tvOS: 14.0.0 - 17.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "MLCompute",
  "identifier" : "/documentation/MLCompute/MLCTrainingGraph/compileOptimizer(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCTrainingGraph(im)compileOptimizer:"
  },
  "title" : "compileOptimizer(_:)"
}
-->

# compileOptimizer(_:)

Compiles the optimizer to use with a training graph you specify.

```
func compileOptimizer(_ optimizer: MLCOptimizer) -> Bool
```

## Parameters

`optimizer`

The optimizer.

## Return Value

`true` if the operation was successful.

## Discussion

Typically you specify the optimizer to use with a training graph when creating the training graph, using [`init(graphObjects:lossLayer:optimizer:)`](/documentation/MLCompute/MLCTrainingGraph/init(graphObjects:lossLayer:optimizer:)). The optimizer is then compiled in when you call [`compile(options:device:)`](/documentation/MLCompute/MLCTrainingGraph/compile(options:device:)).

Alternatively, if the optimizer isn’t known when the framework creates or compiles the training graph, you can use this method to associate and compile in an optimizer.

---

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)