---
title: "compileOptimizer(_:)"
framework: ML Compute
role: symbol
role_heading: Instance Method
platforms: [iOS 14.0+, iPadOS 14.0+, Mac Catalyst 14.0+, macOS 11.0+, tvOS 14.0+]
path: "mlcompute/mlctraininggraph/compileoptimizer(_:)"
---

# compileOptimizer(_:)

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

## Declaration

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

## Parameters

- `optimizer`: The optimizer.

## Return Value

Return Value true if the operation was successful.

## Discussion

Discussion Typically you specify the optimizer to use with a training graph when creating the training graph, using init(graphObjects:lossLayer:optimizer:). The optimizer is then compiled in when you call 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.

## See Also

### Preparing Training Graphs

- [addInputs(_:lossLabels:)](mlcompute/mlctraininggraph/addinputs(_:losslabels:).md)
- [addInputs(_:lossLabels:lossLabelWeights:)](mlcompute/mlctraininggraph/addinputs(_:losslabels:losslabelweights:).md)
- [addOutputs(_:)](mlcompute/mlctraininggraph/addoutputs(_:).md)
- [stopGradient(for:)](mlcompute/mlctraininggraph/stopgradient(for:).md)
- [compile(options:device:)](mlcompute/mlctraininggraph/compile(options:device:).md)
- [compile(options:device:inputTensors:inputTensorsData:)](mlcompute/mlctraininggraph/compile(options:device:inputtensors:inputtensorsdata:).md)
- [link(with:)](mlcompute/mlctraininggraph/link(with:).md)
- [allocateUserGradient(for:)](mlcompute/mlctraininggraph/allocateusergradient(for:).md)
- [MLCGraphCompilationOptions](mlcompute/mlcgraphcompilationoptions.md)
