Model and compute orchestration
VoiceStudio coordinates model discovery, local installation, model loading, memory use, and job placement. It compares the hardware visible to the host with the runtime that can use it, then routes each local engine to an effective device and gives its work a suitable resource budget. Remote GPU capacity is outside this application boundary; the model and compute path described here is local-first.
System boundaries
Model and compute layers
The model layer describes which AI models are known, supported, installed, and ready for use. The compute layer describes which local device families and memory resources can run them. This separation lets the same catalog support different hosts while each engine keeps its own device rules.
The main responsibilities are:
- Discover supported speech models and their local cache state.
- Recommend models that fit the host platform and acceleration family.
- Install model data and report incomplete or blocked installs.
- Select an engine and its effective device.
- Load only the models needed for current work.
- Budget concurrent work against available memory and execution time.
References: backend/…/models.py• L47-77 backend/…/models.py• L543-631 backend/…/model_manager.py• L168-215
Orchestration relationships
Catalog identity and host capability qualify a model before an engine is selected. The engine then owns model loading and execution, while the compute policy controls residency, queue admission, and time limits. An engine may run inside the main process, in a resident child process, or as a fresh native process for each request. These modes change how VoiceStudio can reclaim memory and recover from a stuck native call.
Native audio.cpp engines add a separate runtime boundary: VoiceStudio can use a user-installed or app-managed server binary, resolve an explicitly installed model package, and let that binary select its own runtime device. This keeps native device discovery and model readiness tied to the process that will execute the model.
This diagram shows how a local model choice becomes bounded work.
flowchart LR
A[Model catalog] --> B[Host support and install state]
C[Physical hardware] --> D[Host compute report]
E[Runtime build] --> D
D --> F[Engine routing]
B --> F
F --> G[Effective device and engine mode]
G --> H[Load or reuse model]
H --> I[Budget and queue job]
I --> J[Local result]
The model lifecycle page expands model load and release behavior. The engine routing page explains device and engine decisions. The voice generation page shows how synthesis uses the selected route. The deployment and operations page covers the runtime environment around these choices.
References: backend/…/models.py• L543-631 backend/…/model_manager.py• L3138-3227 backend/…/model_manager.py• L3316-3380 backend/…/backend.py• L894-932 backend/…/bootstrap.py• L432-517 backend/…/main.py• L1-29
Local execution gateway
The local execution gateway is the shared boundary for blocking model-load and generation work. It sends a call to the guarded local worker pool, applies queue and execution limits, and turns a first-use load timeout into a clear model-load failure. An engine that runs in a child process can also be stopped by its parent so a wedged native call does not keep the same device allocation forever.
The gateway also supports admission checks before work enters a saturated pool. This keeps local overload separate from a job that started but exceeded its compute budget. The recovery result still depends on the engine mode: a child process can be killed, while an in-process native call may keep resources until its worker returns.
References: backend/…/gpu_gateway.py• L1-5 backend/…/gpu_gateway.py• L39-74 backend/…/gpu_gateway.py• L77-118 backend/…/main.py• L1-8
Model catalog and installation
Host-aware catalog
The model catalog is the source of truth for known local AI models. Each catalog entry links a product role to a download source and can state its size, platform support, required status, recommendation class, access terms, or package identity.
The model API joins catalog data with the current host and local cache. It reports whether each model is supported, installed, incomplete, or recommended. It also reports the local cache target and disk headroom so the setup flow can warn before a large install fills the disk.
References: backend/…/models.py• L47-77 backend/…/models.py• L116-145 backend/…/models.py• L543-631
Model recommendations
Recommendations turn host tags into a practical local preset. The host is classified by operating system, architecture, and usable acceleration family, then the catalog selects supported required and optional models for that class.
The preset changes its balance for CPU, NVIDIA CUDA, AMD ROCm, and Apple Silicon hosts. A recommendation is not proof that a model is loaded; it is a guide for which local model files are worth installing.
References: backend/…/models.py• L634-709 backend/…/models.py• L710-764
Cache completeness
An installed model means that the local cache has the files needed to use the model, not only a directory or configuration file. The catalog checks required package files and weight snapshots so a partial download is shown as incomplete and can be offered again.
Some native engines separate runtime readiness from model-weight readiness. The OmniVoice GGUF engine can report a verified executable as available before its selected base and tokenizer pair is cached. It resolves an installed pair first and downloads the pinned pair only when normal generation needs it; a diagnostic self-test does not start that download. The audio.cpp engine follows the same local-first boundary for model data: it accepts an explicit GGUF path or resolves a pinned package from the local Hugging Face cache, while its executable must already be installed or supplied by the user.
This distinction keeps discovery, installation, and later loading aligned. It also prevents a failed or gated download from appearing ready because a small metadata file reached the cache. If loading still finds missing or damaged files, the load path can repair or re-fetch them before it reports a final failure.
References: backend/…/models.py• L227-275 backend/…/models.py• L556-614 backend/…/models.py• L725-742 backend/…/model_manager.py• L2734-2898 backend/…/backend.py• L1061-1072 backend/…/backend.py• L1133-1193 backend/…/backend.py• L1343-1355 backend/…/bootstrap.py• L432-468 backend/…/bootstrap.py• L798-849
Platform cache inspection
Cache inspection is best effort and remains local. When the normal cache scan cannot read a Windows cache, a direct scan of the standard cache layout preserves the installed state instead of causing a needless re-download.
The same completeness rules apply to the normal scan and the fallback scan. The model list is briefly cached for repeated UI polling, and installation or deletion clears that response cache.
References: backend/…/models.py• L278-371 backend/…/models.py• L374-397 backend/…/models.py• L543-631
Performance profiles
Installed model selection
Performance profiles provide a shared speed and quality choice across local AI work. A profile selects only supported and complete models that are already installed, so changing the profile does not start downloads or replace an explicit usable provider.
The profile can cover speech synthesis, speech recognition, dictation, speaker separation, and translation. It keeps a compatible engine family when a host depends on that family, such as MLX Whisper on Apple Silicon, and it avoids changing a model to one that cannot serve the active language.
References: backend/…/performance_profiles.py• L89-168 backend/…/performance_profiles.py• L200-337 backend/…/performance_profiles.py• L482-516
Runtime quality settings
After selection, the profile supplies runtime settings that trade speed for search effort or synthesis quality. The same plan is reconciled after restart or installation, while the actual audio paths read the applied result without repeating model inventory checks.
This keeps model installation, model selection, and per-request decoding as separate decisions. A profile can tune an installed model without implying that a new model is available or that all model families support the same controls.
References: backend/…/performance_profiles.py• L341-462 backend/…/performance_profiles.py• L568-624
Host capability and routing
Physical GPU inventory
Physical GPU inventory answers which graphics adapters the operating system sees. It stays separate from the ML runtime probe because a GPU can exist even when the installed runtime cannot drive it.
On Linux, the inventory reads the local graphics device view. On Windows, it reads installed display adapters through a dedicated registry adapter. The inventory is advisory during normal status checks and can be strict when provisioning needs a complete device identity.
References: backend/…/gpu_inventory.py• L1-14 backend/…/gpu_inventory.py• L99-148 backend/…/gpu_inventory_windows.py• L10-55
GPU diagnostics
GPU diagnostics joins three facts that must not be treated as one: physical hardware, the installed PyTorch build, and each engine's routing verdict. This explains cases such as an AMD GPU paired with an NVIDIA-only runtime instead of reporting only that the engine uses CPU.
The report returns stable state codes and parameters for the UI to translate. It distinguishes a usable accelerator, a pinned CPU choice, an unusable GPU/runtime pairing, a missing engine, and an engine that has its own runtime path.
References: backend/…/gpu_report.py• L1-19 backend/…/gpu_report.py• L90-177 backend/…/gpu_report.py• L247-345
Effective device selection
An engine's declared device support is combined with the host capability snapshot to produce an effective device and route status. CPU-only work remains CPU-only by design. CPU fallback stays available when acceleration is not safe, while an unavailable route cannot be selected.
An explicit CPU choice is honored before GPU probing. This keeps a CPU-pinned host on CPU and avoids touching a graphics driver that the user chose not to use. Native engines can apply a second capacity policy inside their own runtime. For example, the GGUF route chooses a quantization tier from the native adapter it will open, because the parent process's memory view cannot prove that adapter's capacity. The audio.cpp route instead probes the devices exposed by its selected server binary, maps them to hardware families, and falls back to CPU when automatic discovery cannot safely identify a usable accelerator. An engine with its own native or isolated runtime is not judged only by the parent process's PyTorch build. This keeps the user-facing diagnosis consistent with the component that actually executes the model.
See engine routing for the complete routing contract.
References: backend/…/gpu_report.py• L179-244 backend/…/model_manager.py• L1637-1759 backend/…/model_manager.py• L3893-3919 backend/…/backend.py• L730-743 backend/…/backend.py• L1093-1114 backend/…/bootstrap.py• L307-365 backend/…/bootstrap.py• L546-680
Runtime mismatch handling
The loader checks whether the selected runtime can use the host architecture before committing to accelerated work. If the runtime lacks the needed kernels or the real GPU check confirms a failure, the system can fall back to CPU and expose the reason instead of turning every request into an error.
Native runtime failures follow the same safety goal. If a GGUF GPU run crashes at the process level, VoiceStudio retries that request on CPU and keeps later GGUF requests on CPU for the rest of the session. This does not claim that the physical GPU is absent; it records that this native route was unsafe until the process starts again or the user pins CPU explicitly.
References: backend/…/model_manager.py• L1637-1686 backend/…/model_manager.py• L1703-1734 backend/…/gpu_report.py• L107-177 backend/…/backend.py• L264-285 backend/…/backend.py• L1712-1733
Model residency and resource budgets
Model residency
Residency means that model weights are loaded in a process and ready for work. It reduces repeated load cost but consumes memory, so the system releases idle resources and makes room before heavy loads when memory is tight. The resident process may be the main application process or a managed child process owned by an engine.
Cold loads are exclusive across the local loading paths. A second request waits for the model that is already loading or receives an explicit abandonment result; it does not start a competing native load. A timed-out in-process load can still hold memory until its worker finishes, while a timed-out isolated engine can be terminated so its child-owned device memory is reclaimed.
Some native engines keep a resident server between requests and stop it after an idle period. If that server is unavailable or rejects a request, the engine can use a per-request native process instead. The resident model records the checkpoint that actually finished loading. For a configured local folder, VoiceStudio also records a file fingerprint only after a successful load and only while that folder remains selected. This keeps a re-save from preserving stale residency when the local weights changed or an overlapping load completed for another folder.
See model lifecycle for detailed load, unload, lease, and idle-release behavior.
References: backend/…/model_manager.py• L1493-1524 backend/…/model_manager.py• L3012-3033 backend/…/model_manager.py• L3138-3227 backend/…/model_manager.py• L3316-3380 backend/…/local_model_paths.py• L347-389 backend/…/backend.py• L1252-1287 backend/…/backend.py• L1520-1607 backend/…/main.py• L213-285
Memory reclamation
Memory checks guide cleanup rather than acting as a hard promise that a load will fit. Before a tight TTS load or a warm generation, VoiceStudio can release idle speech resources, engine side caches, and allocator caches that it already owns.
This policy avoids blocking work based only on an estimate. It instead frees known idle resources when memory is low, while leaving a roomy host on the normal path.
References: backend/…/model_manager.py• L3383-3431 backend/…/model_manager.py• L3433-3479
Worker capacity
The local GPU pool sizes its workers from available memory and a conservative per-job budget of about 5 GB. It caps automatic GPU concurrency at four workers, while small or uncertain devices serialize work. An explicit CPU choice keeps worker sizing from probing the GPU runtime, and a user override can raise or lower the worker count when the host has known spare capacity.
The pool is resilient across resets. A timeout can replace its inner worker pool without leaving callers with stale pool references, while live queue and running counts support admission control and retry estimates. A separate watermark lane keeps CPU-only provenance work from consuming GPU capacity. Isolated engine processes report their own liveness and device memory to the parent, so pool state and engine state remain separate views of capacity.
References: backend/…/model_manager.py• L108-119 backend/…/model_manager.py• L169-215 backend/…/model_manager.py• L242-358 backend/…/model_manager.py• L360-381 backend/…/model_manager.py• L760-786 backend/…/model_manager.py• L1321-1330 backend/…/main.py• L126-141
Execution budgets
Queue wait and active execution use separate clocks. A request that waits too long is reported as local pool saturation and can be retried. A request that starts but exceeds its compute budget is reported as an overlong or stuck job.
The execution budget scales with input length and the effective device. CPU routes receive CPU-class timing, and an engine's sidecar timeout can extend the outer limit when the sidecar reports progress. Model-load heartbeats and completed synthesis chunks can extend the deadline while they remain fresh, but the extension has a bound. An accelerator with too little known or declared memory receives a conservative CPU-class timing budget rather than a falsely fast GPU limit. The isolated OmniVoice sidecar sends progress during cold imports, model load, reference transcription, and generation so slow work remains distinguishable from a silent wedge.
References: backend/…/model_manager.py• L448-509 backend/…/model_manager.py• L519-565 backend/…/model_manager.py• L617-732 backend/…/model_manager.py• L806-1057 backend/…/main.py• L68-95 backend/…/main.py• L213-285 backend/…/main.py• L308-389
Timeout recovery
VoiceStudio cannot safely kill a Python worker that is already inside a native model call. After an execution timeout, it abandons the caller's wait and replaces the pool for future submissions, but the old worker can keep its memory until it finishes. An engine that owns a child process has a stronger recovery boundary: the parent can stop that child and release its device allocation.
This distinction protects later requests from a dead executor without claiming that device capacity was restored. Timeout guidance therefore separates queue saturation, an internal lock wedge, CPU-bound work, and memory contention. A native child still emits a typed error when its frame channel closes or its work exceeds the hard process limit.
References: backend/…/model_manager.py• L242-294 backend/…/model_manager.py• L358-381 backend/…/model_manager.py• L1026-1053 backend/…/model_manager.py• L1229-1318 backend/…/backend.py• L165-186 backend/…/backend.py• L1668-1764 backend/…/main.py• L395-457
Compute scope
Local execution boundary
The current application manages models and runs AI work on the local machine. Its discovery and recommendation responses report local cache state, local disk space, and local platform tags. The local execution gateway sends work to this machine's guarded pool and does not inspect a remote worker inventory.
Remote GPU sharing and remote capacity selection belong to VoiceStudio Pro. The local boundary keeps installation, cache completeness, residency, memory release, and execution budgets tied to the process that will run the model.
See backend API platform for the service boundary and Electron desktop for the desktop surface that presents local setup and compute state.
References: backend/…/models.py• L543-631 backend/…/models.py• L634-764 backend/…/gpu_gateway.py• L1-5 backend/…/model_manager.py• L3316-3380
Stable identities
Catalog and engine identities
Catalog model IDs and engine IDs are control keys for discovery, selection, and scheduling. A catalog identity can refer to one package inside a shared repository, while the repository ID identifies the download source. Display labels are for people and must not replace these stable keys.
The resident model also keeps the checkpoint identity that actually completed its load. This prevents a later preference change from making status or local-folder state describe a different model than the one still in memory.
Keeping these identities distinct prevents a shared repository, a selectable package, a runtime engine, and a resident checkpoint from being treated as the same object. The distinction also lets install state remain accurate when several catalog entries use one source.
References: backend/…/models.py• L39-65 backend/…/models.py• L575-604 backend/…/model_manager.py• L3012-3028 backend/…/local_model_paths.py• L235-251
Change checklist
When these files or sections are changed, remember to consider these:
- When a catalog identity or shared repository changes, keep package install state, recommendations, engine selection, and local cache keys aligned.
- When host tags or GPU inventory rules change, keep recommendations, diagnostics, runtime classification, and fallback messages aligned.
- When an engine's device support or memory floor changes, keep effective routing, worker sizing, timeout class, and user notices aligned.
- When cache completeness rules change, keep model listing, recommendation state, installation checks, and load-time local resolution aligned.
- When queue or timeout rules change, keep gateway admission responses, retry estimates, progress extensions, and caller-facing failure types aligned.
- When GPU inventory changes on Windows, keep advisory reads and strict provisioning reads based on the same adapter identity fields.
- When local checkpoint selection or load identity changes, keep resident status, saved-folder fingerprints, engine eviction, and preference resolution aligned.
- When CPU pinning changes, keep device selection, GPU probing, worker sizing, cache release, and restart behavior on the same no-driver path.
- When performance profile targets change, keep installed-only selection, explicit user choices, effective profile state, and runtime decode settings aligned.
- When a native engine adds a resident or subprocess route, keep liveness reporting, idle release, timeout recovery, memory accounting, and per-request fallback aligned.
- When a native engine changes its runtime or quant selection, keep executable checks, pinned weight identity, device capacity rules, and self-test readiness aligned.
- When an audio.cpp package or runtime pin changes, keep binary discovery, device probing, model-cache resolution, package identity, and engine readiness aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A cache contains metadata but not usable weights | The model appears present but fails on first use | Completeness checks mark it incomplete; native engines report weight installation errors at load time |
| A physical GPU does not match the installed runtime build | PyTorch engines use CPU or fail to accelerate | The report joins hardware, build, and route state |
| A physical GPU is pinned out by an explicit CPU choice | Background checks can touch the wrong driver or report a false GPU route | The device probe and loader honor the CPU choice before GPU access |
| A GPU job waits behind a saturated pool | The caller waits without doing work or retries too late | Admission control and a separate queue clock report saturation |
| A running native job exceeds its execution budget | The caller times out while the old worker may still hold memory | The pool resets future submissions; isolated engines can stop their child process |
| A native GPU backend crashes | Repeated requests can crash the same engine or host process | GGUF retries the request on CPU and pins later GGUF runs to CPU for the session |
| Two cold-load paths reach the native loader together | The process can crash or corrupt model state | One shared load exclusion publishes the first completed model |
| A local checkpoint changes while a load is in progress | A later save can preserve or describe the wrong resident weights | Fingerprints are captured before load and recorded only after successful load for the still-selected folder |
| Windows GPU identity cannot be read completely during provisioning | Setup may choose an unsafe or unexplained device path | Strict registry reads fail closed |
| An engine ends without producing a result | An async caller can hang instead of receiving an engine error | The worker boundary converts bare generator termination into a normal runtime failure |
| A subprocess frame is mixed with library output | The parent loses protocol alignment and later requests fail | The sidecar keeps a private frame stream and redirects library output to logs |
| A slow isolated load sends no progress | The parent treats live work as a hung process and kills it | The sidecar sends ordered heartbeats through load, reference ASR, and generation |
| A profile requests a model that is not installed or ready | The profile changes some families but cannot apply the requested choice | Profile activation selects only complete ready models and preserves concurrent user choices |
| The audio.cpp server binary is missing or not executable | The native engine cannot discover devices or load its model | Binary resolution checks configured and managed locations and reports a verified install path |
| The selected native model is not in the local cache | Generation attempts a large or unavailable transfer instead of using known local data | Model resolution is local-only unless installation is started explicitly |
| A native device list is malformed or unavailable | The engine could select the wrong accelerator or hide a runtime problem | Device parsing fails closed and automatic mode can fall back to CPU |
Key files
| File | Why to read it |
|---|---|
| backend/…/models.py | Local catalog, platform tags, recommendations, cache state, and disk headroom |
| backend/…/gpu_inventory.py | Physical GPU discovery independent of the ML runtime |
| backend/…/gpu_inventory_windows.py | Windows display-adapter identity used by inventory and strict setup checks |
| backend/…/gpu_report.py | User-facing join of hardware, runtime build, and engine route state |
| backend/…/local_model_paths.py | Validated local checkpoint selection, identity, and load-state tracking |
| backend/…/model_manager.py | Local model loading, device selection, memory cleanup, worker capacity, queue admission, and execution budgets |
| backend/…/gpu_gateway.py | Shared local boundary for model prewarming, guarded execution, admission, and timeout reporting |
| backend/…/performance_profiles.py | Installed-only model selection and speed-quality settings across local AI families |
| backend/…/bootstrap.py | Native binary discovery, model-package resolution, device selection, and local-only GGUF readiness |
| backend/…/backend.py | Native runtime verification, pinned weight resolution, resident-server use, CPU fallback, and per-request process execution |
| backend/…/main.py | Killable OmniVoice sidecar lifecycle, model loading, progress heartbeats, and audio protocol |
| docs/model-lifecycle.md | Detailed model residency and release flow |
| docs/engine-routing.md | Detailed engine and device selection rules |
| docs/voice-generation.md | How synthesis requests consume the selected model and compute route |
| docs/deployment-and-operations.md | Runtime operations and the boundary around local and remote capacity |
| docs/backend-api-platform.md | API boundary for local setup and compute state |
| docs/electron-desktop.md | Desktop surface for setup, model, and device status |