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 Returns
true when a loading, unloading, downloading, or prewarming operation is in progress.true for: .loading, .prewarming, .downloading, .unloadingReturns false for: .unloaded, .loaded, .prewarmed, .downloadedState Machine
The typical state transitions follow these patterns:Download and Load Flow
When a model needs to be downloaded and loaded:unloaded- Initial statedownloading- Downloading model files from remotedownloaded- Files downloaded successfullyloading- Loading model into memoryloaded- Ready for inference
Prewarm Flow
When using the prewarm option (see WhisperKitConfig):unloaded- Initial stateprewarming- Specializing model for deviceprewarmed- Specialization completeloading- Loading model into memoryloaded- Ready for inference
Unload Flow
When unloading a model:loaded- Model in memoryunloading- Freeing memoryunloaded- 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
ModelStateis 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
isBusyto determine if the model is in a transitional state - State transitions are managed internally by WhisperKit