Melange
API ReferenceiOS

ZeticMLangeHFModel

API reference for loading Hugging Face models on iOS with ZeticMLangeHFModel.

The ZeticMLangeHFModel class allows you to load and run models directly from Hugging Face repositories. No personal key or model key is needed: just the repository ID.

Import

import ZeticMLange

Initializer

init(_ repoId: String) async throws
ParameterTypeDescription
repoIdStringThe Hugging Face repository ID (e.g., "zetic-ai/yolov11n").
let model = try await ZeticMLangeHFModel("zetic-ai/yolov11n")

The initializer is asynchronous (async) because it downloads, compiles, and caches the model on first use. Subsequent initializations use the cached binary and are fast. Must be called within an async context.


Methods

run(inputs:)

Executes inference on the loaded model.

func run(inputs: [Tensor]) throws -> [Tensor]
ParameterTypeDescription
inputs[Tensor]Input tensors matching the model's expected shapes.

Returns: [Tensor]: The model's output tensors.

Throws: An error if input shapes do not match or inference fails.

let outputs = try model.run(inputs: [inputTensor])

Full Working Example

import ZeticMLange

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        Task {
            do {
                // Initialize from Hugging Face (downloads on first use)
                let model = try await ZeticMLangeHFModel("zetic-ai/yolov11n")

                // Prepare inputs
                let inputs: [Tensor] = [imageTensor] // Your preprocessed input

                // Run inference
                let outputs = try model.run(inputs: inputs)

                // Process outputs
                for output in outputs {
                    // Handle each output tensor
                }
            } catch {
                print("Melange error: \(error)")
            }
        }
    }
}

Comparison with ZeticMLangeModel

FeatureZeticMLangeHFModelZeticMLangeModel
AuthenticationNo keys neededRequires Personal Key
Model sourceHugging Face repo IDMelange Dashboard
Initializationasync (download + compile)Synchronous (pre-compiled)
First-run speedSlower (download + compile)Faster (pre-compiled)
Best forPrototyping, public modelsProduction, custom models

See Also