---
title: "execute(inputsData:lossLabelsData:lossLabelWeightsData:outputsData:batchSize:options:completionHandler:)"
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/execute(inputsdata:losslabelsdata:losslabelweightsdata:outputsdata:batchsize:options:completionhandler:)"
---

# execute(inputsData:lossLabelsData:lossLabelWeightsData:outputsData:batchSize:options:completionHandler:)

Executes the training graph with the input data, output data, batch size, execution options, and completion handler that you specify.

## Declaration

```swift
func execute(inputsData: [String : MLCTensorData], lossLabelsData: [String : MLCTensorData]?, lossLabelWeightsData: [String : MLCTensorData]?, outputsData: [String : MLCTensorData]?, batchSize: Int, options: MLCExecutionOptions = [], completionHandler: MLCGraphCompletionHandler? = nil) -> Bool
```

## Parameters

- `inputsData`: A dictionary that contains input data.
- `lossLabelsData`: A dictionary that contains loss labels data.
- `lossLabelWeightsData`: A dictionary that contains loss label weights data.
- `outputsData`: A dictionary that contains output data.
- `batchSize`: The batch size.
- `options`: The execution options.
- `completionHandler`: The completion handler.

## Return Value

Return Value true if the execution was successful.

## Discussion

Discussion When you execute a training iteration, if you specified an optimizer when you created the graph, the framework applies the optimizer update. For variable length sequences for LSTMs/RNNs, use the key “sortedSequenceLength” and pass in tensor data created by using one of the MLCTensor sequence length initializers as the value. If you include synchronous in options, the execution method only returns after the graph has finished execution. Otherwise, the execution method returns once the framework enqueues the graph for execution. However, the completion handler is still not called until after the graph has finished execution.

## See Also

### Executing Training Iterations

- [execute(inputsData:lossLabelsData:lossLabelWeightsData:batchSize:options:completionHandler:)](mlcompute/mlctraininggraph/execute(inputsdata:losslabelsdata:losslabelweightsdata:batchsize:options:completionhandler:).md)
- [synchronizeUpdates()](mlcompute/mlctraininggraph/synchronizeupdates().md)
- [setTrainingTensorParameters(_:)](mlcompute/mlctraininggraph/settrainingtensorparameters(_:).md)
- [MLCExecutionOptions](mlcompute/mlcexecutionoptions.md)
- [MLCGraphCompletionHandler](mlcompute/mlcgraphcompletionhandler.md)
