Repository navigation
update documentation and skills #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ let model = try await loadModelContainer(configuration: modelConfiguration) | |
| you would convert that like this: | ||
|
|
||
| ```swift | ||
| import Foundation | ||
| import MLXLLM | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
|
|
@@ -59,6 +60,7 @@ If you want a little more control over the downloader or the tokenizer loader, t | |
| expands to this: | ||
|
|
||
| ```swift | ||
| import Foundation | ||
| import MLXLLM | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
|
|
@@ -93,14 +95,17 @@ let model = try await loadModelContainer(configuration: modelConfiguration) | |
| becomes: | ||
|
|
||
| ```swift | ||
| import Foundation | ||
| import MLXLLM | ||
| import MLXLMCommon | ||
|
|
||
| import IntegrationPackage | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it desired to remove this? I'm a little confused by this example - with the proposed changes, it now shows a generic HuggingFace macro example (identical to the previous section) rather than an IntegrationPackage-specific example.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, when the 3.x mlx-swift-lm was cut we had an integration package to document. We no longer have that (the author stopped supporting it and retracted it). @aleroot is working on one that could be documented here when he wants to promote it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidkoski sure, after the release I will add a PR(probably after #619) with the option for https://github.com/aleroot/swift-tokenizers , on my app is working well already for awhile now. The only thing is that: I do not plan to add any downloader to that library. The library is however fully drop in replacement for the swift-transformers. |
||
| import MLXHuggingFace | ||
| import HuggingFace | ||
| import Tokenizers | ||
|
|
||
| let modelConfiguration = LLMRegistry.gemma3_1B_qat_4bit | ||
| let model = try await loadModelContainer( | ||
| from: HubClient(), | ||
| from: #hubDownloader(), | ||
| using: #huggingFaceTokenizerLoader(), | ||
| configuration: modelConfiguration | ||
| ) | ||
|
|
||
|
|
@@ -132,6 +137,7 @@ now, using the <doc:#Using-MLXHuggingFace-Macros> (see | |
| packages): | ||
|
|
||
| ```swift | ||
| import Foundation | ||
| import MLXEmbedders | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
|
|
@@ -149,7 +155,7 @@ let loader = #huggingFaceTokenizerLoader() | |
| let container = try await EmbedderModelFactory.shared.loadContainer( | ||
| from: hub, | ||
| using: loader, | ||
| configuration: configuration | ||
| configuration: defaultModelConfiguration | ||
| ) | ||
|
|
||
| // use it ... | ||
|
|
@@ -186,7 +192,12 @@ let container = try await loadModelContainer( | |
| ) | ||
|
|
||
| // After (3.x) – Using HuggingFace integration macros | ||
| import Foundation | ||
| import MLXLLM | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
| import HuggingFace | ||
| import Tokenizers | ||
|
|
||
| let model = try await #huggingFaceLoadModelContainer( | ||
| configuration: LLMRegistry.gemma3_1B_qat_4bit | ||
|
|
@@ -202,28 +213,36 @@ Loading from a local directory: | |
| let container = try await loadModelContainer(directory: modelDirectory) | ||
|
|
||
| // After (3.x) | ||
| let container = try await loadModelContainer(from: modelDirectory) | ||
| let container = try await loadModelContainer( | ||
| from: modelDirectory, | ||
| using: #huggingFaceTokenizerLoader() | ||
| ) | ||
| ``` | ||
|
|
||
| Loading with a model factory: | ||
|
|
||
| ```swift | ||
| let container = try await LLMModelFactory.shared.loadContainer( | ||
| from: HubClient.default, | ||
| from: #hubDownloader(), | ||
| using: #huggingFaceTokenizerLoader(), | ||
| configuration: modelConfiguration | ||
| ) | ||
| ``` | ||
|
|
||
| Loading an embedder: | ||
|
|
||
| ```swift | ||
| import Foundation | ||
| import MLXEmbedders | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
| import HuggingFace | ||
| import Tokenizers | ||
|
|
||
| let container = try await EmbedderModelFactory.load( | ||
| let container = try await EmbedderModelFactory.shared.loadContainer( | ||
| from: #hubDownloader(), | ||
| using: #huggingFaceTokenizerLoader(), | ||
| configuration: .configuration(id: "sentence-transformers/all-MiniLM-L6-v2") | ||
| configuration: EmbedderRegistry.minilm_l6 | ||
| ) | ||
| ``` | ||
|
|
||
|
|
@@ -243,11 +262,11 @@ let text = tokenizer.decode(tokenIds: ids) | |
|
|
||
| ### Loading API | ||
|
|
||
| The `hub` parameter (previously `HubApi`) has been replaced with `from` (any `Downloader` or `URL` for a local directory). Functions that previously defaulted to `defaultHubApi` no longer have a default – callers must either pass a `Downloader` explicitly or use the convenience methods in `MLXLMHuggingFace` / `MLXEmbeddersHuggingFace`, which default to `HubClient.default`. | ||
| The `hub` parameter (previously `HubApi`) has been replaced with `from` (any `Downloader` or `URL` for a local directory). Functions that previously defaulted to `defaultHubApi` no longer have a default – callers must pass a `Downloader` explicitly (for example the `#hubDownloader()` macro from `MLXHuggingFace`) or use the `#huggingFaceLoadModelContainer` / `#huggingFaceLoadModel` convenience macros. | ||
|
|
||
| For most users who were using the default Hub client, adding `import MLXLMHuggingFace` or `import MLXEmbeddersHuggingFace` and using the convenience overloads is sufficient. | ||
| For most users who were using the default Hub client, adding `import MLXHuggingFace` (together with `import HuggingFace` and `import Tokenizers`) and using `#hubDownloader()` + `#huggingFaceTokenizerLoader()` — or the `#huggingFaceLoadModelContainer` macro — is sufficient. | ||
|
|
||
| Users who were passing a custom `HubApi` instance should create a `HubClient` instead and pass it as the `from` parameter. `HubClient` conforms to `Downloader` via `MLXLMHuggingFace`. | ||
| Users who were passing a custom `HubApi` instance should create a `HuggingFace.HubClient` instead and wrap it with `#hubDownloader(_:)` to pass as the `from` parameter. | ||
|
|
||
| ### `ModelConfiguration` | ||
|
|
||
|
|
@@ -257,18 +276,18 @@ Users who were passing a custom `HubApi` instance should create a `HubClient` in | |
|
|
||
| ### Tokenizer loading | ||
|
|
||
| `loadTokenizer(configuration:hub:)` has been removed. Tokenizer loading now uses `AutoTokenizer.from(directory:)` from Swift Tokenizers directly. | ||
| `loadTokenizer(configuration:hub:)` has been removed. Tokenizer loading is now done by the `TokenizerLoader` passed to the load functions. `#huggingFaceTokenizerLoader()` uses `AutoTokenizer.from(modelFolder:)` from Swift Transformers. | ||
|
|
||
| `replacementTokenizers` (the `TokenizerReplacementRegistry`) has been removed. Use `AutoTokenizer.register(_:for:)` from Swift Tokenizers instead. | ||
| `replacementTokenizers` (the `TokenizerReplacementRegistry`) has been removed. To load a tokenizer class that `AutoTokenizer` does not support, pass your own `TokenizerLoader`. | ||
|
|
||
| ### `defaultHubApi` | ||
|
|
||
| The `defaultHubApi` global has been removed. Hugging Face Hub access is now provided by `HubClient.default` from the `HuggingFace` module. | ||
| The `defaultHubApi` global has been removed. Hugging Face Hub access is now provided by the `#hubDownloader()` macro from `MLXHuggingFace`, which wraps a default `HuggingFace.HubClient`. | ||
|
|
||
| ### Low-level APIs | ||
|
|
||
| - `downloadModel(hub:configuration:progressHandler:)` → `Downloader.download(id:revision:matching:useLatest:progressHandler:)` | ||
| - `loadTokenizerConfig(configuration:hub:)` → `AutoTokenizer.from(directory:)` | ||
| - `loadTokenizerConfig(configuration:hub:)` → `TokenizerLoader.load(from:)` | ||
| - `ModelFactory._load(hub:configuration:progressHandler:)` → `_load(configuration: ResolvedModelConfiguration)` | ||
| - `ModelFactory._loadContainer`: removed (base `loadContainer` now builds the container from `_load`) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some stragglers using the old API