Use AutoTokenizer.from() for faster tokenizer loading
#33
+47
−110
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.
swift-transformers PR #303 offers significantly faster tokenizer loading when using
AutoTokenizer.from(). It also covers the tokenizer remapping and registration that is currently done in mlx-swift-lm, so we can remove that and use the fast path here after that PR is merged.Changes
loadTokenizernow usesAutoTokenizer.from()directly instead of manually loading configs and callingPreTrainedTokenizerinitAutoTokenizer.from()revisionparameter toModelConfigurationfor consistency with MLXLMCommonhub.snapshot()loadTokenizerinstead of inline config loadingAPI Changes
Deprecated:
loadTokenizerConfig: UseLanguageModelConfigurationFromHubfrom swift-transformers directly, which allows users to opt in to the fast path withstripVocabForPerformance: true.Unavailable (breaking change):
TokenizerReplacementRegistry/replacementTokenizers: UseAutoTokenizer.register(_:for:)from swift-transformers instead. These no longer function with the newAutoTokenizer.from()code path.Offline Mode
The offline fallback logic has been removed, as it's handled automatically by the swift-transformers Hub API. When offline,
HubApi.snapshot()detects the network state viaNWPathMonitorand falls back to cached files if available.