Skip to main content
The VLM (Vision Language Model) module enables multimodal inference — feed an image and a text prompt to get descriptions, answers, or visual analysis. Models run entirely on-device using llama.cpp with multimodal projector support.

Overview

VLM handles:
  • Image encoding — Platform-aware constructors for iOS (UIImage) and macOS (raw RGB pixels)
  • Model loading — Multi-file GGUF models with multimodal projector
  • Streaming generation — Token-by-token output via AsyncSequence
  • Cancellation — Interrupt long-running generations at any time

Basic Usage

VLM loading requires a full ModelDescriptor retrieved from availableModels(), not just a model ID string. This is different from LLM loading which accepts a plain string ID.

Setup

Register a VLM Model

VLM models require two GGUF files: the main language model and a multimodal projector (mmproj). Use registerMultiFileModel to register both:
The first file is the main model GGUF, and the second is the multimodal projector. Both are required for VLM inference.

Load the Model

API Reference

VLMImage

Platform-conditional image wrapper for VLM input.

Model Operations

processImageStream

Returns a result object with a .stream property — an AsyncSequence of String tokens.

registerMultiFileModel

Platform-Specific Image Handling

VLM image creation differs between iOS and macOS. Use conditional compilation to handle both:

Examples

Complete SwiftUI App with PhotosPicker

Batch Image Analysis

Error Handling

Best Practices

VLM models always require two GGUF files — the language model and the multimodal projector (mmproj). Use registerMultiFileModel instead of registerModel. Missing the projector file will cause loading failures.
Unlike LLM loading which accepts a plain string ID, VLM loading requires a full ModelDescriptor from availableModels(). Always fetch and filter the descriptor before calling loadVLMModel.
Use #if os(iOS) and #elseif os(macOS) for VLMImage construction. iOS uses UIImage directly while macOS requires raw RGB pixel data with explicit dimensions.
Use 30–64 tokens for one-line descriptions and 128–256 for detailed analysis. Larger values increase latency on mobile devices.
Always provide a cancel button in your UI. Call cancelVLMGeneration() to immediately halt token generation and free resources.
Large images increase encoding time significantly. Resize to 256–512px on the longest edge before creating a VLMImage for optimal latency.

Supported Models

LLM Generation

Text-only generation

Tool Calling

Function calling with LLMs

Image Generation

Generate images with Stable Diffusion

Best Practices

Performance optimization