Fix #93: pin mlx-swift-lm to last pre-v3 commit + declare swift-transformers#95
Conversation
…transformers mlx-swift-lm v3 (PR #118 merged 2026-04-01) reshaped the loading API: removed `loadTokenizer(configuration:hub:)`, removed `Hub` parameters, moved tokenizer loading to `AutoTokenizer.from(directory:)`. LocalLLMClientMLX/ Context.swift still uses the old API, so consuming the package against mlx-swift-lm `branch: "main"` fails with `'Tokenizer' is ambiguous` and `cannot infer contextual base in reference to member 'shared'` once mlx-swift-lm advanced past PR #118. Two-line workaround keeps LocalLLMClientMLX buildable today: 1. Pin mlx-swift-lm to the last pre-v3 commit (2a296f14, 2026-03-27). 2. Declare swift-transformers as a direct dep at the same range pre-v3 mlx-swift-lm pinned (`1.2.0..<1.3.0`) so SPM resolves cleanly. The `Tokenizers` import in Context.swift was previously satisfied transitively via mlx-swift-lm, but never re-exported, so consumers silently relied on it. This is intentionally a minimal restoration — leaves the proper migration to mlx-swift-lm v3 (`AutoTokenizer.from(directory:)` etc.) as a follow-up. The two affected lines in Package.swift carry comments pointing at the migration work + this issue. Verification: swift build --target LocalLLMClientMLX # clean (was failing on main) The pin is by SHA (reproducible) rather than `branch:`. Bump the pinned revision to `branch: "main"` and `swift-transformers` to `from: "1.3.0"` in the same commit that ports Context.swift to the v3 API.
There was a problem hiding this comment.
Code Review
This pull request pins the mlx-swift-lm dependency to a specific revision and adds swift-transformers as an explicit dependency to maintain compatibility with the current codebase following API changes in the MLX backend. A review comment identifies a type mismatch in the version range specification for swift-transformers that would cause a compilation error and provides a suggestion to use the correct versioning syntax.
| // public re-export, so consumers still need to depend on it directly. | ||
| // Range matches the pre-v3 mlx-swift-lm transitive pin so SPM resolves. | ||
| // Bump to `from: "1.3.0"` once Context.swift is migrated to mlx-swift-lm v3. | ||
| .package(url: "https://github.com/huggingface/swift-transformers.git", "1.2.0"..<"1.3.0"), |
There was a problem hiding this comment.
The range literal "1.2.0"..<"1.3.0" is interpreted as a Range<String>, which will cause a compilation error because the package(url:_:) method expects a Range<Version>. To fix this and maintain consistency with the existing dependencies in this file (such as lines 11 and 12), use .upToNextMinor(from: "1.2.0").
| .package(url: "https://github.com/huggingface/swift-transformers.git", "1.2.0"..<"1.3.0"), | |
| .package(url: "https://github.com/huggingface/swift-transformers.git", .upToNextMinor(from: "1.2.0")), |
tattn
left a comment
There was a problem hiding this comment.
Thank you for pinning the MLX version!
I will merge this and leave support for the new API as a future task.
Closes #93.
Problem
mlx-swift-lmv3 (PR ml-explore/mlx-swift-lm#118 merged 2026-04-01) reshaped its loading API. Notable removals:loadTokenizer(configuration:hub:)→ moved toAutoTokenizer.from(directory:)Hub/defaultHubApiparameter → replaced with aDownloader-basedfrom:parameterModelConfiguration.modelDirectory(hub:)→ removed; passURLdirectlyLocalLLMClientMLX/Context.swift(lines 39, 61, 69, 97, 102) still uses the v2 API. Consuming this package againstmlx-swift-lmbranch: "main"fails to compile:(The "ambiguous" errors come from both
MLXLMCommonandTokenizersexposing aTokenizertype once mlx-swift-lm v3 introduces its own.)Fix
This PR is a minimum-disruption restoration — it does not port
Context.swiftto the v3 API. Instead it pins to the last pre-v3 commit so today's code compiles cleanly:mlx-swift-lmto commit2a296f14(2026-03-27 — last commit before PR #118) viarevision:. Reproducible (vsbranch:).swift-transformersas a direct dependency at1.2.0..<1.3.0(the range pre-v3mlx-swift-lmpinned). TheTokenizersimport inContext.swiftwas satisfied transitively before, butmlx-swift-lmnever re-exported it, so SPM consumers silently relied on the resolution. Making the dependency explicit removes that fragility.TokenizerstoLocalLLMClientMLX's target dependencies.Verification
(Was failing on main before this PR with the errors above.)
Follow-up
A future PR should migrate
Context.swiftto the mlx-swift-lm v3 API:loadTokenizer(configuration:hub:)withAutoTokenizer.from(directory:)hub:parameter with aDownloader(likelyHubClient.defaultfromMLXLMHuggingFace)ModelConfiguration.modelDirectory(hub:)branch: "main"1.2.0..<1.3.0→from: "1.3.0"Both pin updates are flagged with comments in
Package.swiftpointing at this migration.Downstream
OCCTSwiftPartsAgent and any other downstream consumer that hits this issue can now adopt LocalLLMClient via
revision:of this PR's branch and unblock their MLX integration paths until the proper migration lands.