Contents

MLComputePlan

A class representing the compute plan of a model.

Declaration

class MLComputePlan

Overview

The application can use the compute plan to estimate the necessary cost and resources of the model before running the predictions.

// Load the compute plan of an ML Program model.
let computePlan = try await MLComputePlan.load(contentsOf: modelURL, configuration: configuration)
guard case let .program(program) = computePlan.modelStructure else {
   fatalError("Unexpected model type.")
}
 // Get the main function.
guard let mainFunction = program.functions["main"] else {
   fatalError("Missing main function.")
}

let operations = mainFunction.block.operations
for operation in operations {
   // Get the compute device usage for the operation.
   let computeDeviceUsage = computePlan.deviceUsage(for: operation)
   // Get the estimated cost of executing the operation.
   let estimatedCost = computePlan.estimatedCost(of: operation)
}

Topics

Loading a compute plan

Getting the model structure

Getting the device usage

Getting the estimated cost

See Also

Compute plan