|
1 | 1 | import Foundation |
2 | 2 | import MLXLMCommon |
3 | 3 |
|
| 4 | +/// Wrap a `HubClient` as a `Downloader`. |
| 5 | +/// |
| 6 | +/// ```swift |
| 7 | +/// import MLXHuggingFace |
| 8 | +/// import HuggingFace |
| 9 | +/// |
| 10 | +/// let model = try await loadModelContainer( |
| 11 | +/// from: #hubDownloader(HubClient()), |
| 12 | +/// using: #huggingFaceTokenizerLoader(), |
| 13 | +/// configuration: modelConfiguration |
| 14 | +/// ) |
| 15 | +/// ``` |
4 | 16 | @freestanding(expression) |
5 | 17 | public macro hubDownloader(_ hub: Any) -> MLXLMCommon.Downloader = |
6 | 18 | #externalMacro(module: "MLXHuggingFaceMacros", type: "DownloaderMacro") |
7 | 19 |
|
| 20 | +/// Provide a default `HubClient` as a `Downloader`. |
| 21 | +/// |
| 22 | +/// ```swift |
| 23 | +/// import MLXHuggingFace |
| 24 | +/// import HuggingFace |
| 25 | +/// |
| 26 | +/// let model = try await loadModelContainer( |
| 27 | +/// from: #hubDownloader(), |
| 28 | +/// using: #huggingFaceTokenizerLoader(), |
| 29 | +/// configuration: modelConfiguration |
| 30 | +/// ) |
| 31 | +/// ``` |
8 | 32 | @freestanding(expression) |
9 | 33 | public macro hubDownloader() -> MLXLMCommon.Downloader = |
10 | 34 | #externalMacro(module: "MLXHuggingFaceMacros", type: "DownloaderMacro") |
11 | 35 |
|
| 36 | +/// Wrap a `Tokenizers.Tokenizer` in `Tokenizer`. |
| 37 | +/// |
| 38 | +/// This is used internally by ``huggingFaceTokenizerLoader()`` -- typically not used directly. |
| 39 | +/// |
| 40 | +/// ```swift |
| 41 | +/// import MLXHuggingFace |
| 42 | +/// import Tokenizers |
| 43 | +/// |
| 44 | +/// let t: Tokenizers.Tokenizer |
| 45 | +/// |
| 46 | +/// let tokenizer = #adaptHuggingFaceTokenizer(t) |
| 47 | +/// ``` |
12 | 48 | @freestanding(expression) |
13 | 49 | public macro adaptHuggingFaceTokenizer(_ upstream: Any) -> MLXLMCommon.Tokenizer = |
14 | 50 | #externalMacro(module: "MLXHuggingFaceMacros", type: "TokenizerAdaptorMacro") |
15 | 51 |
|
| 52 | +/// Provide a `TokenizerLoader` from `Tokenizers.AutoTokenizer`. |
| 53 | +/// |
| 54 | +/// ```swift |
| 55 | +/// import MLXHuggingFace |
| 56 | +/// import HuggingFace |
| 57 | +/// |
| 58 | +/// let model = try await loadModelContainer( |
| 59 | +/// from: #hubDownloader(), |
| 60 | +/// using: #huggingFaceTokenizerLoader(), |
| 61 | +/// configuration: modelConfiguration |
| 62 | +/// ) |
| 63 | +/// ``` |
16 | 64 | @freestanding(expression) |
17 | 65 | public macro huggingFaceTokenizerLoader() -> MLXLMCommon.TokenizerLoader = |
18 | 66 | #externalMacro(module: "MLXHuggingFaceMacros", type: "TokenizerLoaderMacro") |
19 | 67 |
|
| 68 | +/// Load a `ModelContainer` using default hub client and tokenizer loader. |
| 69 | +/// |
| 70 | +/// ```swift |
| 71 | +/// import MLXHuggingFace |
| 72 | +/// import HuggingFace |
| 73 | +/// import Tokenizers |
| 74 | +/// |
| 75 | +/// let model = try await huggingFaceLoadModelContainer( |
| 76 | +/// configuration: modelConfiguration |
| 77 | +/// ) |
| 78 | +/// ``` |
20 | 79 | @freestanding(expression) |
21 | 80 | public macro huggingFaceLoadModelContainer( |
22 | 81 | configuration: ModelConfiguration |
23 | 82 | ) -> ModelContainer = |
24 | 83 | #externalMacro(module: "MLXHuggingFaceMacros", type: "LoadContainerMacro") |
25 | 84 |
|
| 85 | +/// Load a `ModelContainer` using default hub client and tokenizer loader with progress. |
| 86 | +/// |
| 87 | +/// ```swift |
| 88 | +/// import MLXHuggingFace |
| 89 | +/// import HuggingFace |
| 90 | +/// import Tokenizers |
| 91 | +/// |
| 92 | +/// let model = try await huggingFaceLoadModelContainer( |
| 93 | +/// configuration: modelConfiguration |
| 94 | +/// ) { progres in ... } |
| 95 | +/// ``` |
26 | 96 | @freestanding(expression) |
27 | 97 | public macro huggingFaceLoadModelContainer( |
28 | 98 | configuration: ModelConfiguration, |
29 | 99 | progressHandler: @Sendable @escaping (Progress) -> Void |
30 | 100 | ) -> ModelContainer = |
31 | 101 | #externalMacro(module: "MLXHuggingFaceMacros", type: "LoadContainerMacro") |
32 | 102 |
|
| 103 | +/// Load a `ModelContext` using default hub client and tokenizer loader. |
| 104 | +/// |
| 105 | +/// ```swift |
| 106 | +/// import MLXHuggingFace |
| 107 | +/// import HuggingFace |
| 108 | +/// import Tokenizers |
| 109 | +/// |
| 110 | +/// let modelContext = try await huggingFaceLoadModel( |
| 111 | +/// configuration: modelConfiguration |
| 112 | +/// ) |
| 113 | +/// ``` |
33 | 114 | @freestanding(expression) |
34 | 115 | public macro huggingFaceLoadModel( |
35 | 116 | configuration: ModelConfiguration |
36 | 117 | ) -> ModelContext = |
37 | 118 | #externalMacro(module: "MLXHuggingFaceMacros", type: "LoadContextMacro") |
38 | 119 |
|
| 120 | +/// Load a `ModelContext` using default hub client and tokenizer loader with progress. |
| 121 | +/// |
| 122 | +/// ```swift |
| 123 | +/// import MLXHuggingFace |
| 124 | +/// import HuggingFace |
| 125 | +/// import Tokenizers |
| 126 | +/// |
| 127 | +/// let modelContext = try await huggingFaceLoadModel( |
| 128 | +/// configuration: modelConfiguration |
| 129 | +/// ) { progres in ... } |
| 130 | +/// ``` |
39 | 131 | @freestanding(expression) |
40 | 132 | public macro huggingFaceLoadModel( |
41 | 133 | configuration: ModelConfiguration, |
|
0 commit comments