<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/InferenceFunction",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime17InferenceFunctionV"
  },
  "title" : "InferenceFunction"
}
-->

# InferenceFunction

A function that performs inference on input values and produces output values.

```
struct InferenceFunction
```

## Overview

An `InferenceFunction` owns the resources needed for inference, including model weights
and intermediate buffers. You load a function from an [`AIModel`](/documentation/CoreAI/AIModel) and call
[`run(inputs:states:outputViews:)`](/documentation/CoreAI/InferenceFunction/run(inputs:states:outputViews:)-14emi) to perform inference.

This type is `Sendable`, so you can run it concurrently from multiple tasks. The function
automatically allocates additional intermediate buffers as needed to support concurrency.

## Topics

### Running inference

[`run(inputs:states:outputViews:)`](/documentation/CoreAI/InferenceFunction/run(inputs:states:outputViews:)-mqfb)

Runs the function on the provided input arrays and returns the output values.

[`run(inputs:states:outputViews:)`](/documentation/CoreAI/InferenceFunction/run(inputs:states:outputViews:)-14emi)

Runs the function on the provided input values and returns the output values.

[`encode(inputs:states:outputViews:to:)`](/documentation/CoreAI/InferenceFunction/encode(inputs:states:outputViews:to:))

Encodes the inference onto the provided compute stream, returning async values for the outputs.

### Inspecting a function

[`descriptor`](/documentation/CoreAI/InferenceFunction/descriptor)

The descriptor for this function’s inputs, outputs, and states.

### Supporting types

[`Inputs`](/documentation/CoreAI/InferenceFunction/Inputs)

A collection of named input values for an inference function.

[`Outputs`](/documentation/CoreAI/InferenceFunction/Outputs)

The output values produced by running an inference function.

[`MutableViews`](/documentation/CoreAI/InferenceFunction/MutableViews)

A collection of `InferenceValue.MutableView`s which can be updated in-place by an `InferenceFunction`.

### Asynchronous inference

[`AsyncValue`](/documentation/CoreAI/InferenceFunction/AsyncValue)

A future which will provide an inference value once any pending write is complete.

[`AsyncMutableValue`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue)

An async value which can be provided as a mutable argument to an inference function.

[`AsyncMutableViews`](/documentation/CoreAI/InferenceFunction/AsyncMutableViews)

A collection of mutable references to async states, used as the states argument to an inference function.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)