Skip to content

fix: skip MLX BART fallback on iOS simulator#12

Open
yocontra wants to merge 6 commits into
mlalma:mainfrom
veil-labs-inc:fix/optional-mlx-fallback
Open

fix: skip MLX BART fallback on iOS simulator#12
yocontra wants to merge 6 commits into
mlalma:mainfrom
veil-labs-inc:fix/optional-mlx-fallback

Conversation

@yocontra

@yocontra yocontra commented Mar 22, 2026

Copy link
Copy Markdown

Summary

  • Make EnglishFallbackNetwork optional in EnglishG2P — on the iOS simulator there is no Metal GPU, so MLX crashes with abort() when initializing its Metal device
  • The BART fallback is only used for unknown words not in the lexicon (~5% of words). The lexicon-based phonemization handles the vast majority of English text
  • Uses #if targetEnvironment(simulator) to skip fallback creation at compile time — no API changes, same init signature
  • Removes unused MLXUtilsLibrary imports from EnglishG2P.swift and Lexicon.swift

Changes

  • EnglishG2P.fallback type changed from EnglishFallbackNetwork to EnglishFallbackNetwork?
  • Both fallback call sites guarded with if let fallback
  • Fallback set to nil on simulator, created normally on device

Also fixes a bug with missing swift-collections dep.

Add optional resourceDir: URL? parameter that threads through
EnglishG2P → Lexicon/EnglishFallbackNetwork → DataResourcesUtil.
When provided, loads dictionaries and BART weights from the given
directory instead of Bundle.module (which doesn't exist in CocoaPods).
All parameters default to nil so existing SPM usage is unchanged.
Remove the SPM resource bundle declaration and all Bundle.module
references. Resources are now loaded exclusively via the resourceDir
parameter, which avoids CodeSign failures when used in CocoaPods
projects. Also switch library type from dynamic to static.
- swift-tools-version 6.2 caused swift-collections to resolve to 1.4.x
  which requires experimental Lifetimes feature, breaking CocoaPods builds
- Remove empty resources array (resources loaded via resourceDir param)
- Switch library type from dynamic to static for CocoaPods compatibility
The EnglishFallbackNetwork uses MLX which requires Metal GPU access.
On the iOS simulator there is no Metal GPU, causing MLX to crash with
abort() when initializing its device. The BART fallback is only used
for unknown words not in the lexicon (~5% of words).

Skip fallback initialization on simulator via
#if targetEnvironment(simulator). The lexicon-based phonemization
still handles the vast majority of English words.

Also removes unused MLXUtilsLibrary imports from EnglishG2P and Lexicon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant