Skip to main content
ModelState is an enum that represents the current lifecycle state of a WhisperKit or TTSKit model pipeline.

Overview

Model loading and management involves several distinct states. ModelState provides a single canonical type that can be referenced across UI components, callbacks, and utilities to track where a model is in its lifecycle.

Cases

ModelState
The model is currently being unloaded from memory.Description: “Unloading”
ModelState
The model is not loaded in memory.Description: “Unloaded”
ModelState
The model is currently being loaded into memory.Description: “Loading”
ModelState
The model is fully loaded and ready for use.Description: “Loaded”
ModelState
The model is being specialized for the device (one-time compilation).Description: “Specializing”
ModelState
The model has been specialized and cached.Description: “Specialized”
ModelState
The model files are being downloaded.Description: “Downloading”
ModelState
The model files have been downloaded.Description: “Downloaded”

Properties

String
A human-readable description of the current state.
Bool
Returns true when a loading, unloading, downloading, or prewarming operation is in progress.
Returns true for: .loading, .prewarming, .downloading, .unloadingReturns false for: .unloaded, .loaded, .prewarmed, .downloaded

State Machine

The typical state transitions follow these patterns:

Download and Load Flow

When a model needs to be downloaded and loaded:
  1. unloaded - Initial state
  2. downloading - Downloading model files from remote
  3. downloaded - Files downloaded successfully
  4. loading - Loading model into memory
  5. loaded - Ready for inference

Prewarm Flow

When using the prewarm option (see WhisperKitConfig):
  1. unloaded - Initial state
  2. prewarming - Specializing model for device
  3. prewarmed - Specialization complete
  4. loading - Loading model into memory
  5. loaded - Ready for inference

Unload Flow

When unloading a model:
  1. loaded - Model in memory
  2. unloading - Freeing memory
  3. unloaded - Memory freed

Usage Examples

Observing State Changes

Using State Callbacks

UI State Binding (SwiftUI)

Checking Multiple States

Type Alias

(_ oldState: ModelState?, _ newState: ModelState) -> Void
Callback type invoked when the pipeline’s model state changes.

Notes

  • ModelState is shared between WhisperKit and TTSKit for consistent state management
  • The enum is marked @frozen, meaning no new cases will be added (guaranteed binary compatibility)
  • Use isBusy to determine if the model is in a transitional state
  • State transitions are managed internally by WhisperKit