From 1f17f316ddeb56978a7312e2cb000cc00bde3be2 Mon Sep 17 00:00:00 2001 From: David Koski Date: Thu, 16 Apr 2026 19:52:42 -0700 Subject: [PATCH] add fallback links to the readme -- docs are not yet built --- README.md | 89 +++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 4c10e642b7..886a0bbfec 100644 --- a/README.md +++ b/README.md @@ -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,7 +36,11 @@ 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`: @@ -40,71 +48,31 @@ Add the core package to your `Package.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 ) @@ -112,18 +80,3 @@ 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?")) ``` - -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() -) -```