ZeticMLangeModel
API reference for general model inference on iOS.
This page reflects ZeticMLange iOS 1.11.0.
ZeticMLangeModel loads a general on-device model from the Melange registry and runs tensor inference on iOS.
Import
import ZeticMLangeInitializer
public init(
personalKey: String,
name: String,
version: Int? = nil,
modelMode: ModelMode = .RUN_AUTO,
cacheHandlingPolicy: ModelCacheHandlingPolicy = .REMOVE_OVERLAPPING,
onDownload: ((Float) -> Void)? = nil
) async throws| Parameter | Type | Default | Description |
|---|---|---|---|
personalKey | String | - | Personal key for accessing the model. |
name | String | - | Model name in account_name/project_name format. |
version | Int? | nil | Model version. nil loads the latest version. |
modelMode | ModelMode | .RUN_AUTO | Backend selection strategy. |
cacheHandlingPolicy | ModelCacheHandlingPolicy | .REMOVE_OVERLAPPING | Managed artifact cache cleanup policy. |
onDownload | ((Float) -> Void)? | nil | Download progress callback from 0.0 to 1.0. |
let model = try await ZeticMLangeModel(
personalKey: PERSONAL_KEY,
name: "account_name/project_name"
)run(inputs:)
Runs inference with tensors matching the model input order.
public func run(inputs: [Tensor]) throws -> [Tensor]| Parameter | Type | Description |
|---|---|---|
inputs | [Tensor] | Input tensors matching the model's expected shapes and data types. |
Returns: output tensors in model output order.
let outputs = try model.run(inputs: [inputTensor])
let firstOutput = outputs[0]Background Downloads
Schedule a general-model download without constructing a runtime instance. Await this call while the app is foregrounded so iOS can register the background URL-session task before the app moves to the background.
static func downloadInBackground(
personalKey: String,
name: String,
version: Int? = nil,
modelMode: ModelMode = .RUN_AUTO,
cacheHandlingPolicy: ModelCacheHandlingPolicy = .KEEP_EXISTING
) async throws -> BackgroundDownloadHandle
static func getBackgroundDownloadStatus(
_ handle: BackgroundDownloadHandle
) async throws -> BackgroundDownloadStatus
static func stopBackgroundDownload(
_ handle: BackgroundDownloadHandle
) async throws -> BackgroundDownloadStopResult
static func removeDownloadedModel(
name: String,
version: Int? = nil
) async throws -> ModelRemovalResultlet handle = try await ZeticMLangeModel.downloadInBackground(
personalKey: PERSONAL_KEY,
name: "account_name/project_name"
)
let status = try await ZeticMLangeModel.getBackgroundDownloadStatus(handle)
let stopResult = try await ZeticMLangeModel.stopBackgroundDownload(handle)
let removal = try await ZeticMLangeModel.removeDownloadedModel(
name: "account_name/project_name"
)Forward application(_:handleEventsForBackgroundURLSession:completionHandler:) to ZeticMLangeModel.handleBackgroundURLSessionEvents(...) so a relaunched app can finish verification and installation. See iOS advanced configuration for the host-app setup. Stopping preserves an already installed model; if removal.isInUse is true, close active instances and retry removal.
Lifecycle
public private(set) var isClosed: Bool
public func close()Call close() when the model is no longer needed.
model.close()