We have implemented a new inference backend using huggingface/swift-transformers to provide a robust, "transformers-like" API for on-device inference, specifically targeting Core ML models.
- Protocol:
AIInferenceServiceunifiesAIInferenceManager(MLX) andTransformersInferenceManager. - Manager:
TransformersInferenceManagerhandles theswift-transformerslogic. - UI: Added an "Inference Engine" selector in the Chat tab settings menu.
To enable the Transformers backend, you must add the swift-transformers package to your project.
- Open
Offline AI&ML Playground.xcodeprojin Xcode. - Go to File > Add Package Dependencies....
- Enter the URL:
https://github.com/huggingface/swift-transformers. - Click Add Package.
- Ensure the
Transformerslibrary is added to theOffline AI&ML Playgroundtarget.
- Run the app.
- Go to the Chat tab.
- Tap the Settings (ellipsis) button in the top right.
- Select Inference Engine > Transformers (CoreML).
- Select a compatible model (Core ML format).
- Note: The current downloader fetches
.safetensors(MLX) and.gguf. You may need to manually add Core ML models or update the downloader to fetch.mlpackagemodels from Hugging Face. - Recommended models for testing:
apple/OpenELM-270M-Instruct(if available in Core ML) or other Core ML converted models.
- Note: The current downloader fetches
Shared/Core/Inference/AIInferenceService.swift: The unified protocol.Shared/Core/Inference/TransformersInferenceManager.swift: The new backend implementation.ChatTab/ViewModels/ChatViewModel.swift: Logic for switching backends.