<!--
{
  "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/MLCInferenceGraph/execute(inputsData:lossLabelsData:lossLabelWeightsData:batchSize:options:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCInferenceGraph(im)executeWithInputsData:lossLabelsData:lossLabelWeightsData:batchSize:options:completionHandler:"
  },
  "title" : "execute(inputsData:lossLabelsData:lossLabelWeightsData:batchSize:options:completionHandler:)"
}
-->

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

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

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

## Parameters

`inputsData`

A dictionary that contains input data.

`lossLabelsData`

A dictionary that contains loss label data.

`lossLabelWeightsData`

A dictionary that contains loss label weight data.

`batchSize`

The batch size.

`options`

The execution options.

`completionHandler`

The completion handler.

## Return Value

`true` if the execution was successful.

## Discussion

When executing an inference graph, if an optimizer is specified, the optimizer update is applied.

For variable length sequences for LSTMs/RNNs, use the key `“sortedSequenceLengths”` and pass in tensor data created by using one of the [`MLCTensor`](/documentation/MLCompute/MLCTensor) sequence length initializers as the value.

If [`synchronous`](/documentation/MLCompute/MLCExecutionOptions/synchronous) is specified in `options`, this method returns after the graph is executed. Otherwise, this method returns after the graph is queued for execution. The completion handler is called after the graph has finished execution.

---

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)