Harden model load/cache, vendor transformers tests, fix macOS 14 segmenter (#495)
* Harden model load/cache, vendor transformers tests, fix macOS 14 segmenter Four changes: ## Guard use-after-free on `MLModel` access - Add a `Protected` property wrapper (backed by `OSAllocatedUnfairLock`) in `Sources/ArgmaxCore/ConcurrencyUtilities.swift` that can wrap `MLModel?`. - Apply `@Protected` to every `model: MLModel?` stored property so load/unload can't race inference: - **WhisperKit:** `AudioEncoder`, `TextDecoder`, `FeatureExtractor` - **SpeakerKit:** `SpeakerEmbedderModel`, `PLDAEmbedderModel`, `SpeakerPreEmbedderModel`, `SpeakerSegmenterModel` - **TTSKit:** `Qwen3SpeechDecoder`, `Qwen3CodeDecoder`, `Qwen3MultiCodeDecoder`, `Qwen3CodeEmbedder`, `Qwen3MultiCodeEmbedder`, `Qwen3TextProjector` ## Vendor swift-transformers v1.1.6 tests (new `ArgmaxCoreTests` target) - Add an `ArgmaxCoreTests` target covering the Hub + Tokenizers code vendored under `Sources/ArgmaxCore/External/`, copied from swift-transformers v1.1.6 with the same provenance header + `// Argmax-modification:` convention as the vendored sources. ## Fix Pyannote segmenter variant selection on macOS 14 / iOS 17 - Gate the default `W8A16` segmenter on `#available(iOS 18, macOS 15, *)`, falling back to `W32A32`. ## Validate the local model cache before serving it in `resolveRepo` - `resolveRepo` used to return the Hub cache as soon as each pattern's directory existed and was non-empty, so a partially-downloaded model (e.g. an `.mlmodelc` missing `model.mil` or its `.metadata` sidecar) got served from cache and failed at load time. It now runs an offline `HubApi.snapshot` first to validate each cached file's metadata and hash, falling through to a normal download when that fails. `patternsExistLocally` stays as a cheap presence check, since the offline snapshot can't detect an entirely-missing component. Adds offline `ModelDownloaderTests` covering valid, partial, corrupt, and missing-component caches plus the `resolveModel`/`ModelInfo` helpers. * documentation
A
Andrey Leonov committed
623792a83e8137ad27ec5725c662ba2eec511d81
Parent: 8bae6cd
Committed by GitHub <noreply@github.com>
on 6/29/2026, 4:39:05 AM