Repository navigation
fix(importers): import Ollama models by name, params and projector, and verify OCI blob digests - #13384
Merged
Conversation
| } | ||
| defer func() { _ = reader.Close() }() | ||
|
|
||
| fs, err := os.Create(dst) |
| // file that does not is removed, so a wrong download is never mistaken for a | ||
| // model. | ||
| func CheckGGUF(path string) error { | ||
| f, err := os.Open(path) |
The shared blob fetch never checked the sha256 digest or the size of what it downloaded, and it created the destination file before the request, so a failed fetch left an empty or partial file behind. - Verify the size and the sha256 digest while reading, for every OCI blob download. On a mismatch or any other failure, remove the file. - Treat a non-200 manifest response, a body that is not a manifest and a manifest without a model layer as errors that name the model and tag. OllamaModelBlob no longer returns an empty digest without an error. - Add OllamaDescribeModel, which reads the params layer (size capped) and tells whether the model has a projector, and let OllamaFetchModel fetch the projector layer with a "#projector" suffix. - Add CheckGGUF, which refuses and removes a file that does not start with the GGUF magic bytes. - Add UseOllamaRegistry so tests and mirrors can point the pulls at another registry, and an in-process fake registry for tests. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
A model file that comes from an OCI or Ollama registry and is named *.gguf must start with the GGUF magic bytes after the download. If it does not, the install fails with "this model is not a GGUF file" and the file is removed, instead of leaving a file llama.cpp cannot load. Add tests for the install of a model with a projector, the refusal of a non-GGUF file, a corrupted blob, and the "#projector" layer selector of the downloader. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Importing ollama://qwen3:8b first asked Hugging Face about the URI,
named the file "qwen3__8b" without an extension, and ignored the
sampling defaults and the vision projector the model ships with.
- Skip the Hugging Face lookup for ollama:// URIs and ask the Ollama
registry instead. A missing model or weights that are not a GGUF file
fail the import with a clear error.
- Name the model <name>-<tag> ("qwen3-8b"), drop the library/ prefix and
always end the weights file in .gguf. Describe it as "Imported from
Ollama: <name>:<tag>".
- Read the params layer: temperature, top_k, top_p, min_p,
repeat_penalty, seed and num_predict (as max_tokens) become the model
defaults, and stop becomes stopwords. Other keys, num_ctx included,
are ignored, and values of the wrong type are skipped. The same keys
in the import preferences win.
- Download the projector layer as a second file and set mmproj.
- Keep the chat template of the GGUF file. The Ollama template, system
and license layers are not read.
- Make HFOwnerRepoFromURI refuse URIs with another scheme, so that
"ollama://qwen3:8b" is no longer read as owner "ollama:". Pin that
the llama-cpp importer claims every ollama:// URI.
- Document the behavior.
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
MLX, nvfp4 and mxfp8 tags of the Ollama library have no model layer. They list one tensor layer per tensor, plus json layers, so the import failed with the generic "has no model layer" error. Fail with an error that names the model and tag, says it is stored as safetensors/MLX tensors, is not a GGUF file and cannot run with llama.cpp, and tells the user to choose a GGUF tag of the same model. The import-time check raises it before any download. A manifest with neither a model layer nor tensor layers keeps the generic error. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
mudler
force-pushed
the
feat/importer-ollama-fixes
branch
from
November 21, 2026 23:41
34518bb to
946ce63
Compare
The blob fetch and the GGUF check open paths that the caller builds under its models folder, never a path taken from a request. Mark the two opens as reviewed, as the rest of the repository does. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Importing an Ollama model (
ollama://qwen3:8b) now works the way a user expects, and blob downloads from OCI and Ollama registries are verified.Why
qwen3__8bwith no extension, and ignored the sampling defaults and the vision projector that the model ships with.What changes
ollama://URIs. The Ollama registry is asked instead.qwen3:8bbecomes the modelqwen3-8band the fileqwen3-8b.gguf. Thelibrary/prefix is dropped,user/model:tagbecomesuser-model-tag, and the taglatestadds nothing to the name (qwen3). The description is "Imported from Ollama: qwen3:8b". The projector file is<name>-mmproj.gguf.temperature,top_k,top_p,min_p,repeat_penalty,seed,num_predict(asmax_tokens) andstop(asstopwords) become the defaults of the model. Other keys,num_ctxincluded, are ignored. Values of the wrong type are skipped, and the layer is read with a size cap. The same keys in the import preferences win over the params layer.mmproj. A downloader URI ending in#projectorselects that layer.*.gguffor the GGUF magic bytes and removes it on failure.HFOwnerRepoFromURIrefuses URIs with another scheme, soollama://qwen3:8bis no longer read as ownerollama:. A test pins that the llama-cpp importer claims everyollama://URI.oci.UseOllamaRegistrypoints Ollama pulls at another registry (plain HTTP optional). Tests use it with an in-process fake registry (pkg/oci/ollamatest), so the new tests need no network.How it was tested
go test -tags nosqlite,purego_utppasses forpkg/oci,core/gallery/importers,core/gallery,pkg/downloaderandcore/config.golangci-lintreports no new issues on the touched packages. The new tests cover each item above (manifest 404 and 5xx, invalid manifest, no model layer, non-GGUF refused and removed, digest mismatch, extra and truncated bytes, params with unknown keys and wrong types, user preferences winning, the name forms, projector download, and anoci://import that keeps its naming). Each behavior was broken once to check that a test fails.Not verified
oci://image imports today, because an image is extracted to a directory and the importer names that file without.gguf.Not verified: no import of a real model from the live Ollama registry end to end (the importer, downloader and gallery tests use a fake registry); the tensor-only manifests are modelled by small fixtures, not the full ~1200-layer manifests; Windows was not run; the post-download GGUF check does nothing for
oci://images, which extract to a directory.🤖 Generated with Claude Code