Repository navigation
feat(studio): list and load Ollama MLX-format tags, with their bundled drafters - #18253
Conversation
Ollama's `*-mlx` tags store one safetensors blob per tensor with Ollama's names for the quantization companions (`.weight.scale`, `.weight.bias`, `.weight.global_scale`), a ModelOpt `quantization_config`, drafter tensors mixed in, and no chat template for Gemma 4, so neither mlx-lm nor mlx-vlm can load them as pulled, and the model picker only listed GGUF Ollama tags. On Apple Silicon these tags are now listed as chat-only safetensors rows. Loading one materializes a standard MLX checkpoint beside the tag's other links: unchanged blobs are symlinked, blobs whose companions need renaming are APFS clones with the header rewritten in place, tensors under 1 MiB are packed into one shard to stay under mlx-lm's open-file limit, and the config gets an MLX `quantization` block. Tags carrying SYSTEM or preset-message layers are not listed, since the checkpoint would drop them. Each build is keyed by the manifest. The row, the load and the loaded model all name the tag by one stable path, `<links>/<tag hash>/mlx/<repo-tag>`, where `mlx` is a symlink switched to the current build. Re-picking the loaded tag therefore does not reload it, per-model settings survive an `ollama pull`, and the "loaded" notice shows the tag's name. The scan names that path without writing anything; the load route builds it and advertises the model as `ollama/<repo>:<tag>`. A re-pull keeps the build that was current before, since a resident model reads its shards by path, and removes older ones, whose clones would keep removed blobs' bytes alive. The memory and offload probe installs the unsloth-zoo hook that reads mixed-mode and NVFP4-scaled-embedding checkpoints, so it can build these models.
Ollama's MLX tags carry their own drafters: Gemma 4 tags a Gemma 4 assistant under `draft.*` with `draft/*.json`, Qwen3.6 tags the model's MTP head under `mtp.*`. The checkpoint built for a tag dropped both. The MTP head now stays in the checkpoint, where mlx-vlm's sanitize keeps it out of the target and unsloth-zoo builds it as the built-in head. The assistant becomes a checkpoint of its own at `draft/` inside the tag's checkpoint, named as its standalone release names its tensors; dropping the `draft.` prefix shortens each header, so its large tensors are clones too. MLX speculation offers a companion bundled at `draft/` after the built-in head and before cached companions, under the same kind, shape and weights checks. A build's key now includes a layout version, so builds made before this change are rebuilt. The memory estimate's check for tensors a checkpoint's architecture has no home for skips NVFP4's `.weight_scale_2` global scales, as it already skips `.scales` and `.biases`: the unquantized model it builds has no place for any of them. Every MLX NVFP4 checkpoint with global scales, not only Ollama's, was unsizable before, so auto speculation skipped its drafter. Validated in Unsloth Studio under auto speculation: gemma4:e4b-mlx attached its assistant and accepted 136 of 186 drafted tokens; qwen3.6:35b-mlx attached its MTP head and accepted 23 of 30.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3706c7d6b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d2fe5b493
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex review converged on the current head CI (staging copy Lyxot#255, same head and base, since the upstream jobs were queued): all 75 checks pass on What changed during review (3 commits on top of the original 2):
Two findings were answered in their threads and not changed. Auto-switching the API to an unloaded MLX tag is a new feature, since MLX tags were not listed before this PR. A dangling shard after re-pulling a loaded tag and then deleting another tag that shares its blobs is a rare three-step edge case; it fails loudly and is fixed by a reload. |
…aded MLX tags for the API [skip ci]
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f700aafdce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for stale in tag_dir.iterdir(): | ||
| if stale.name.startswith(("mlx-", ".mlx-")) and stale not in (build, previous): | ||
| shutil.rmtree(stale, ignore_errors = True) |
There was a problem hiding this comment.
Reclaim builds whose Ollama manifests have been removed
If a tag is loaded, unloaded, and then its manifest and blobs are removed outside Studio, its hidden mlx-* builds are never reclaimed. This pruning only runs during materialization of an existing tag, and the other whole-tag cleanup is delete_ollama_model_ref(), which external deletion does not call. APFS clones and packed shards continue retaining the weights' disk blocks, so deleting multi-GB models can leave their storage allocated indefinitely, with no inventory row left to delete through Studio. Add orphan-tag build cleanup that protects any still-resident model.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: Studio's own delete already removes the tag's link dirs including every build. A tag removed outside Studio leaves its GGUF hardlinks behind the same way today, and sweeping a build whose manifest is gone could pull files out from under a resident model reading them lazily.
… the default executor
… MLX tags missing a blob [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
## Summary `tests/studio/test_model_picker_contracts.py::test_the_chat_picker_marks_ollama_targets_unloadable_by_the_api` fails on main: ``` AssertionError: assert 'return !isLora && !ids.some(isOllamaLinkPath);' in '...' ``` Seen in "Repo tests (CPU, studio)" on the staging run for #17742, which is on current main. ## Cause #18253 lists and loads Ollama MLX-format tags. Their checkpoint directories sit under the same `ollama_links` tree, but the resolver does index them. So `apiAutoSwitchMayLoad` and the override backfill (`migrate-model-overrides.ts`) now exclude only a materialized `.gguf` link, `isMaterializedOllamaLink`, instead of every `isOllamaLinkPath`. That change is intended and covered by `model-identity.test.ts`. The contract test still pinned the old line. ## Fix Test-only: - Pin the new predicate in `apiAutoSwitchMayLoad` and in the backfill. - Also pin `isMaterializedOllamaLink`'s definition (`isOllamaLinkPath(modelId) && !isOllamaMlxModelId(modelId)`). A materialized `.gguf` link stays unloadable, which is what this test exists to guard. ## Verification | `features/hub/lib/model-identity.ts` | Result | |---|---| | main | 205 passed (before: 1 failed) | | `isMaterializedOllamaLink` reduced back to every link (sabotage) | this test fails | ruff is clean.
Problem
Ollama's MLX-format tags (
gemma4:*-mlx,qwen3.5:*-mlx,qwen3.6:*-mlx) were not listed in the Unsloth Studio model picker, and neither mlx-lm nor mlx-vlm can load them as pulled:.weight.scale,.weight.bias,.weight.global_scale).quantization_config.What changed
Listing and loading (
feat(studio): list and load Ollama MLX-format tags)quantizationblock;clonefilerefuses the load with a clear reason rather than copying gigabytes.<links>/<tag hash>/mlx/<repo-tag>.mlxis a symlink switched atomically to the content-addressed build. As a result:ollama pull;ollama/<repo>:<tag>.Bundled drafters (
feat(studio): speculate with the drafters Ollama MLX tags bundle)mtp.*tensors stay in the checkpoint. mlx-vlm's sanitize keeps them out of the target, and unsloth-zoo builds them as the built-in head.draft.*tensors anddraft/*.jsonbecome a checkpoint of their own atdraft/inside the tag's checkpoint, with tensors named as the standalone assistant release names them. Dropping the prefix shortens each header, so the large tensors are clones too.draft/after the built-in head and before cached companions, under the same kind, shape and weights checks..weight_scale_2global scales, as it already skipped.scalesand.biases. Before, every MLX NVFP4 checkpoint with global scales was unsizable, so auto speculation silently skipped its drafter. This applies to all such checkpoints, not only Ollama's.Depends on
unslothai/unsloth-zoo#2584: loads mixed-mode and NVFP4-scaled-embedding checkpoints on the mlx-vlm path. Without it, most Gemma 4 MLX tags fail to load.
Known limits
Validation
Mutation checks. All 26 hand-written mutations of the materializer, identity round trip, prune rule, load route and bundled-drafter resolution make their test fail.
End to end in Unsloth Studio, with real tags:
gemma4:e4b-mlxloads, and/statusreports the stable path./load.gemma4:e4b-mlxattached its assistant and accepted 136 of 186 drafted tokens, at 11.7 tok/s.qwen3.6:35b-mlxattached its MTP head and accepted 23 of 30, at 12.1 tok/s.qwen3.5:4b,qwen3.6:35bandgemma4:26bmatch Ollama for 40 of 40 tokens;Model picker, before and after
Two isolated Studio installs (merge base vs this PR) on Linux.
OLLAMA_MODELSpoints at a store holdinggemma4:e2b-mlxandgemma4:e4b-mlxwith their real manifests and tensor headers and zero-filled data. The Apple Silicon check is stubbed to true on both sides, because listing only happens on Apple Silicon. Before: the search finds nothing. After: both tags are listed as MLX rows.