Skip to content

fix(importers): import Ollama models by name, params and projector, and verify OCI blob digests - #13384

Merged
mudler merged 5 commits into
masterfrom
feat/importer-ollama-fixes
Nov 22, 2026
Merged

mudler merged 5 commits into
masterfrom
feat/importer-ollama-fixes

Conversation

@mudler-agent

@mudler-agent mudler-agent commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • The import asked Hugging Face about an Ollama URI, named the file qwen3__8b with no extension, and ignored the sampling defaults and the vision projector that the model ships with.
  • A missing model, a registry error or a manifest with no model layer was not reported as an error that names the model.
  • The shared blob fetch never checked the sha256 digest or the size, and it left a 0-byte or partial file after a failed download.

What changes

  • Digest check for all OCI downloads. The shared blob fetch now verifies the size and the sha256 digest while it reads, for every OCI and Ollama blob download, not only Ollama ones. A failed download, including a digest mismatch or a truncated blob, no longer leaves a partial file: the file is removed.
  • Manifest errors. A non-200 manifest response, a body that is not a manifest and a manifest with no model layer fail with an error that names the model and tag.
  • No Hugging Face lookup for ollama:// URIs. The Ollama registry is asked instead.
  • Names. qwen3:8b becomes the model qwen3-8b and the file qwen3-8b.gguf. The library/ prefix is dropped, user/model:tag becomes user-model-tag, and the tag latest adds nothing to the name (qwen3). The description is "Imported from Ollama: qwen3:8b". The projector file is <name>-mmproj.gguf.
  • Params layer. temperature, top_k, top_p, min_p, repeat_penalty, seed, num_predict (as max_tokens) and stop (as stopwords) become the defaults of the model. Other keys, num_ctx included, 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.
  • Projector. A vision model's projector layer is downloaded as a second file and set as mmproj. A downloader URI ending in #projector selects that layer.
  • Tensor-only tags. MLX, nvfp4 and mxfp8 tags have no model layer, only tensor layers. The import fails before any download 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 asks the user to choose a GGUF tag of the same model. A manifest with neither keeps the generic "no model layer" error.
  • Chat template. The template stays the one inside the GGUF file. The Ollama template, system and license layers are not read.
  • GGUF check, in two places. The import reads the first bytes of the weights and fails with "this model is not a GGUF file" before any large download. After the download, the install checks any OCI-sourced file named *.gguf for the GGUF magic bytes and removes it on failure.
  • Importer choice. HFOwnerRepoFromURI refuses URIs with another scheme, so ollama://qwen3:8b is no longer read as owner ollama:. A test pins that the llama-cpp importer claims every ollama:// URI.
  • Test hook. oci.UseOllamaRegistry points 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_utp passes for pkg/oci, core/gallery/importers, core/gallery, pkg/downloader and core/config. golangci-lint reports 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 an oci:// import that keeps its naming). Each behavior was broken once to check that a test fails.

Not verified

  • No real model was imported from the public Ollama registry end to end. The importer, downloader and gallery tests use an in-process fake registry.
  • The post-download GGUF check does nothing for oci:// image imports today, because an image is extracted to a directory and the importer names that file without .gguf.
  • Not run on Windows.

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

Comment thread pkg/oci/blob.go Outdated
}
defer func() { _ = reader.Close() }()

fs, err := os.Create(dst)
Comment thread pkg/oci/blob.go Outdated
// 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
mudler force-pushed the feat/importer-ollama-fixes branch from 34518bb to 946ce63 Compare November 21, 2026 23:41
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>
@mudler
mudler merged commit 00ab410 into master Nov 22, 2026
12 of 28 checks passed
@mudler
mudler deleted the feat/importer-ollama-fixes branch November 22, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants