feat(tts): add configurable computeUnits for Kokoro models#482
Merged
Alex-Wengg merged 4 commits intoFluidInference:mainfrom Apr 4, 2026
Merged
Conversation
Adds a `computeUnits` parameter (default: `.all`) to `TtsModels.download()`, `KokoroTtsManager.init()`, and `KokoroModelCache.init()`, allowing callers to override CoreML compute units for Kokoro model loading. This is needed because iOS 26 introduces ANE compiler regressions that cause Kokoro models to fail with "Cannot retrieve vector from IRValue format int32" when loaded with `.all` (which includes the Neural Engine). Using `.cpuAndGPU` bypasses the ANE and resolves the issue, matching the approach already used by PocketTTS to avoid ANE float16 precision artifacts. The default `.all` preserves existing behavior on iOS 17-18. Callers on iOS 26+ can pass `.cpuAndGPU` to work around the ANE regression. Example: ```swift let manager = KokoroTtsManager(computeUnits: .cpuAndGPU) try await manager.initialize() ```
When KokoroTtsManager was initialized with a custom computeUnits but no directory (the common case), the modelCache default parameter was used as-is with .all compute units, silently ignoring the caller's setting. This meant on-demand model loading could still hit the ANE, defeating the iOS 26 workaround. Make modelCache optional (nil = not user-provided) so we always create a cache with the correct computeUnits when the caller doesn't supply their own. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
computeUnitsparameter (default:.all) toTtsModels.download(),KokoroTtsManager.init(), andKokoroModelCache.init(), allowing callers to override CoreML compute units for Kokoro model loading.Problem
iOS 26 (beta, Build 23E246) introduces ANE compiler regressions that cause Kokoro models to fail with:
This is a known ecosystem-wide issue affecting CoreML models on iOS 26 (see whisper.cpp#3702, executorch#15833, Apple Developer Forums thread 799456). The root cause is changes in the ANE compiler/runtime that break models compiled with
computeUnits: .all.Solution
Exposes the
computeUnitsparameter so callers can use.cpuAndGPUon iOS 26+ to bypass the ANE, matching the approach PocketTTS already uses to avoid ANE float16 precision artifacts.Backwards compatible: The default remains
.all, preserving existing behavior on iOS 17-18.Changes
TtsModels.swift: AddedcomputeUnitsparameter todownload(), piped toDownloadUtils.loadModels()KokoroTtsManager.swift: AddedcomputeUnitsparameter toinit(), stored and passed toTtsModels.download()andKokoroModelCacheKokoroModelCache.swift: AddedcomputeUnitsparameter toinit(), piped toTtsModels.download()inloadModelsIfNeeded()Usage
Testing
.cpuAndGPUon iOS 26.4 beta (iPhone 14 Pro, A16).allbehavior unchanged on older iOS versions