Repository navigation
add fallback links to the readme -- docs are not yet built #218
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ MLX Swift LM is a Swift package to build tools and applications with large langu | |
| > The `main` branch is a _new_ major version number: 3.x. In order | ||
| > to decouple from tokenizer and downloader packages some breaking | ||
| > changes were introduced. See [upgrading documentation](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/upgrade) for detailed instructions on upgrading. | ||
| > | ||
| > If that page shows a 404 you can view the source: | ||
| > [upgrading](https://github.com/ml-explore/mlx-swift-lm/blob/main/Libraries/MLXLMCommon/Documentation.docc/upgrade.md) | ||
| > and [using](https://github.com/ml-explore/mlx-swift-lm/blob/main/Libraries/MLXLMCommon/Documentation.docc/using.md) | ||
|
|
||
| Some key features include: | ||
|
|
||
|
|
@@ -32,98 +36,47 @@ This package integrates with a variety of tokenizer and downloader packages thro | |
|
|
||
| See documentation on [how to integrate mlx-swift-lm and downloaders/tokenizers](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using). | ||
|
|
||
| ### Installation | ||
| > [!NOTE] | ||
| > If the documentation link shows a 404, view the | ||
| > [source](https://github.com/ml-explore/mlx-swift-lm/blob/main/Libraries/MLXLMCommon/Documentation.docc/using.md). | ||
|
|
||
| ## Installation | ||
|
|
||
| Add the core package to your `Package.swift`: | ||
|
|
||
| ```swift | ||
| .package(url: "https://github.com/ml-explore/mlx-swift-lm", .upToNextMajor(from: "3.31.3")), | ||
| ``` | ||
|
|
||
| Then chose one of the methods below to select download and tokenizer implementations. | ||
|
|
||
| ### Method 1: Integration Packages | ||
|
|
||
| Then add your preferred tokenizer and downloader integrations, see [how to integrate mlx-swift-lm and downloaders/tokenizers](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#Integration-Packages): | ||
|
|
||
| ```swift | ||
| .package(url: "https://github.com/DePasqualeOrg/swift-tokenizers-mlx", from: "0.2.0", traits: ["Swift"]), | ||
| .package(url: "https://github.com/DePasqualeOrg/swift-hf-api-mlx", from: "0.2.0"), | ||
| ``` | ||
|
|
||
| And add the libraries to your target: | ||
|
|
||
| ```swift | ||
| .target( | ||
| name: "YourTargetName", | ||
| dependencies: [ | ||
| .product(name: "MLXLLM", package: "mlx-swift-lm"), | ||
| .product(name: "MLXLMTokenizers", package: "swift-tokenizers-mlx"), | ||
| .product(name: "MLXLMHFAPI", package: "swift-hf-api-mlx"), | ||
| ]), | ||
| ``` | ||
|
|
||
| ### Method 2: Macros | ||
|
|
||
| This preserves parity with mlx-swift-lm 2.x. Simply reference the huggingface packages and use the `MLXHuggingFace` macros to adapt the APIs. [Read more here](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#MLXHuggingFace-Macros). | ||
|
|
||
| Add these to your dependencies: | ||
|
|
||
| ```swift | ||
| .package(url: "https://github.com/huggingface/swift-huggingface", .upToNextMajor(from: "0.9.0")), | ||
| .package(url: "https://github.com/huggingface/swift-transformers", .upToNextMajor(from: "1.3.0")), | ||
| ``` | ||
| Then chose an [integration package for downloaders and tokenizers](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#Integration-Packages). | ||
|
|
||
| And add the libraries to your target: | ||
| > [!NOTE] | ||
| > If the documentation link shows a 404, view the | ||
| > [source](https://github.com/ml-explore/mlx-swift-lm/blob/main/Libraries/MLXLMCommon/Documentation.docc/using.md). | ||
|
|
||
| ```swift | ||
| .target( | ||
| name: "YourTargetName", | ||
| dependencies: [ | ||
| .product(name: "MLXLMCommon", package: "mlx-swift-lm"), | ||
| .product(name: "MLXLLM", package: "mlx-swift-lm"), | ||
| .product(name: "MLXHuggingFace", package: "mlx-swift-lm"), | ||
| .product(name: "HuggingFace", package: "swift-huggingface"), | ||
| .product(name: "Tokenizers", package: "swift-transformers"), | ||
| ]), | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| You can get started with a wide variety of open-weights LLMs and VLMs using this simplified API (for more details, see [MLXLMCommon](Libraries/MLXLMCommon)): | ||
| After installing the package you can use LLMs to generate content with only a few lines | ||
| of code. (Note: the exact line to load the model depends on the [integration package](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#Integration-Packages)). | ||
|
|
||
| > [!NOTE] | ||
| > If the documentation link shows a 404, view the | ||
| > [source](https://github.com/ml-explore/mlx-swift-lm/blob/main/Libraries/MLXLMCommon/Documentation.docc/using.md). | ||
|
|
||
| If using the [integration macros](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#MLXHuggingFace-Macros), you can get started with code like this: | ||
|
|
||
| ```swift | ||
| import MLXLLM | ||
| import MLXLMCommon | ||
| import MLXHuggingFace | ||
|
|
||
| import HuggingFace | ||
| import Tokenizers | ||
|
|
||
| let modelConfiguration = LLMRegistry.gemma3_1B_qat_4bit | ||
|
|
||
| let model = try await #huggingFaceLoadModelContainer( | ||
| // customize this line per the integration package | ||
| let model = try await loadModelContainer( | ||
| configuration: modelConfiguration | ||
| ) | ||
|
|
||
| let session = ChatSession(model) | ||
| print(try await session.respond(to: "What are two things to see in San Francisco?")) | ||
| print(try await session.respond(to: "How about a great place to eat?")) | ||
| ``` | ||
|
Comment on lines
68
to
82
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. @DePasqualeOrg per our earlier discussion -- point to the docs with a short snippet that is integration agnostic |
||
|
|
||
| Using the [adapter packages](https://swiftpackageindex.com/ml-explore/mlx-swift-lm/main/documentation/mlxlmcommon/using#Integration-Packages) you would have similar code -- replace the imports and the load line. | ||
|
|
||
| For example, loading from a local directory using the [DePasqualeOrg/swift-tokenizers-mlx](https://github.com/DePasqualeOrg/swift-tokenizers-mlx): | ||
|
|
||
| ```swift | ||
| import MLXLLM | ||
| import MLXLMTokenizers | ||
|
|
||
| let modelDirectory = URL(filePath: "/path/to/model") | ||
| let container = try await loadModelContainer( | ||
| from: modelDirectory, | ||
| using: TokenizersLoader() | ||
| ) | ||
| ``` | ||
Oops, something went wrong.
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.
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.
There seems to be a backlog on the SPI where the docs are built. Point to the doc source for now -- the content is good, a few of the links won't work.