Load offline CoreML models and tokenizers
mainTo avoid network requests when bundling models with your app, you can load a compiled CoreML model and a tokenizer from local files. Use AutoTokenizer.from(modelFolder:) to initialize a tokenizer from a local directory containing tokenizer_config.json and tokenizer.json, then pass it to LanguageModel.loadCompiled(url:tokenizer:).
To download only the necessary tokenizer files via CLI for local bundling:
huggingface-cli download \
mistralai/Mistral-7B-Instruct-v0.3 \
tokenizer.json tokenizer_config.json \
--local-dir Examples/Mistral7B/local-tokenizerlet compiledURL: URL = ... // path to .mlmodelc
let tokenizerFolder: URL = ... // folder containing tokenizer_config.json and tokenizer.json
// Construct the tokenizer from local files (inside an async context)
let tokenizer = try await AutoTokenizer.from(modelFolder: tokenizerFolder)
let model = try LanguageModel.loadCompiled(
url: compiledURL,
tokenizer: tokenizer
)