Skip to content

fix(models): don't pull again a model written in short form - #14532

Open
ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:fix-model-short-form-pull
Open

ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:fix-model-short-form-pull

Conversation

@ndeloof

@ndeloof ndeloof commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Stops docker compose up from pulling again a model written in short form (ai/smollm2) that the model runner already has.

Context

Before pulling, Compose checks whether the model is already available by comparing the model of the compose file, verbatim, with the tags docker model ls reports. The runner lists them in full form (docker.io/ai/smollm2:latest), so only a model written exactly that way was recognized. A short name never matched, and Pulling/Pulled showed on every up along with a call to the model runner.

What the PR brings

  • Both sides are given their full form before they are compared, as image references are: ai/smollm2, ai/smollm2:latest, docker.io/ai/smollm2 and docker.io/ai/smollm2:latest are the same model, and an available model is only configured, not pulled.
  • Hugging Face models are handled the way the runner lists them: hf.co/Org/Model-GGUF is listed as huggingface.co/org/model-gguf:latest (other host, lower case; a tag such as Q4_K_M keeps its case), so that is the form compared.
  • A different tag or a different model is still pulled. Any other reference that cannot be parsed is compared as it is, as before.
  • What is sent to the runner (pull, configure, the *_MODEL variable) is unchanged: the model is passed as written.

Fixes #14531

🤖 Generated with Claude Code

@ndeloof
ndeloof requested review from a team as code owners November 18, 2026 13:49

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/compose/model.go 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. A few remarks:

  • pkg/compose/model.go:84-89: an untagged reference that ParseNormalizedNamed rejects (uppercase repository, e.g. hf.co/Org/Model-GGUF) stays raw and gets no :latest. If the runner lists it as hf.co/Org/Model-GGUF:latest, it is still pulled on every up. Same as before the PR, so not a regression, but the hf.co/Org/Model-GGUF:Q4_K_M fixture is not taken from a real listing: do you know how the runner lists those? If it appends the tag, the fallback branch could do the same when the last segment has no : and no @.
  • pkg/compose/model.go:81-82: "A reference that is not one of an image" reads oddly; something like "A reference that cannot be parsed as an image one (uppercase repository names are rejected) is left as it is" says the actual rule.
  • pkg/compose/model_test.go:138: strings.Contains(log, "pull "+tt.model) would match ai/smollm2 inside a pull ai/smollm2:360M line if a multi-model row is ever added. Fine as is with one model per row.

Not for this PR, but while in ensureModels: err = mdlAPI.PullModel(...) at model.go:68 assigns the err declared in the outer scope from the errgroup goroutines, which is a data race as soon as two models need a pull (go test -race with three unavailable models reports it). if err := ... or returning the call directly fixes it. The ListModels error at model.go:51 is also never checked (a failure means everything is pulled again).

Comment thread pkg/compose/model_test.go Resolved
@ndeloof
ndeloof force-pushed the fix-model-short-form-pull branch from 2b4042e to 226a48e Compare November 23, 2026 07:19
@ndeloof

ndeloof commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, in 226a48e:

  • model.go fallback: I don't know how the runner lists such references, so rather than guess, both sides now get :latest when the last segment has no tag or digest. The comparison is the same whether or not the runner lists the tag; rows added for both listings, and the fallback is pinned by TestNormalizeModelReference.
  • Comment reworded as suggested.
  • The pull/configure assertions now compare whole log lines instead of substrings.
  • The err race and the unchecked ListModels error are real, but out of scope here: I'll send them in a separate PR.

@ndeloof
ndeloof requested a review from docker-agent November 23, 2026 07:20
@ndeloof
ndeloof force-pushed the fix-model-short-form-pull branch from 226a48e to 8c7a5de Compare November 23, 2026 07:24
@ndeloof

ndeloof commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the hf.co/Org/Model-GGUF question, checked against a local Docker Model Runner (v1.2.9) rather than guessed: the runner resolves Hugging Face references case-insensitively and lists them under another host in lower case, e.g. docker model pull hf.co/bartowski/SmolLM2-135M-Instruct-GGUF is listed as huggingface.co/bartowski/smollm2-135m-instruct-gguf:latest, and with :Q4_K_M as huggingface.co/bartowski/smollm2-135m-instruct-gguf:Q4_K_M (tag case kept). So neither the fallback I pushed earlier nor the original fixture could match: I replaced the fallback with that Hugging Face form, and the test rows now use the real listing. Ran docker compose up on hf.co/bartowski/SmolLM2-135M-Instruct-GGUF with the model already pulled: main prints llm Pulling/Pulled on every run, this branch only configures it.

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@ndeloof
ndeloof requested a review from docker-agent November 23, 2026 07:43

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

Comment thread pkg/compose/model.go Resolved
ensureModels compared the model of the compose file verbatim with the
tags `docker model ls` lists, which are in full form
(docker.io/ai/smollm2:latest). A model written ai/smollm2 never matched
and was pulled on every `up`, even when it was already there.

Both sides are now given their full form before they are compared, as
image references are. Hugging Face models get the form the runner lists
them under: resolved case-insensitively and listed as
huggingface.co/org/model-gguf:latest for hf.co/Org/Model-GGUF (the tag
keeps its case). Any other reference that cannot be parsed is compared
as it is.

Fixes docker#14531

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof force-pushed the fix-model-short-form-pull branch from 8c7a5de to 6a87c85 Compare November 23, 2026 07:52
@ndeloof
ndeloof requested a review from docker-agent November 23, 2026 07:52

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, nits only.

Checked the Hugging Face listing on Docker Model Runner v1.2.9: docker model pull hf.co/bartowski/SmolLM2-135M-Instruct-GGUF is listed as huggingface.co/bartowski/smollm2-135m-instruct-gguf:latest, the path is case-insensitive, and :Q4_K_M / :q4_k_m are listed as distinct tags. compose up with the model already present only configures it on this branch, where the base commit pulls it on every run (tried hf.co with and without a tag, a lower-case path, and the huggingface.co host).

Non-blocking:

  • A bare name is not resolved the way the runner does: smollm2 is listed as docker.io/ai/smollm2:latest, while normalizeModelReference gives docker.io/library/smollm2:latest, so it is still pulled on every up. Same as before the PR, fine to leave unless you want to special-case the ai/ namespace.
  • HF.co/Org/Model-GGUF:Q4_K_M in TestNormalizeModelReference: the runner rejects an upper-case host (500), so that row describes an input that can't be pulled. Harmless.

Comment thread pkg/compose/model.go
Comment on lines +87 to +93
tag := "latest"
if i := strings.LastIndex(path, ":"); i > strings.LastIndex(path, "/") {
path, tag = path[:i], path[i+1:]
if tag == "" {
tag = "latest"
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest is set twice. Defaulting once after the optional split is equivalent (all TestNormalizeModelReference rows pass, including hf.co/Org/Model:) and drops a nested branch:

Suggested change
tag := "latest"
if i := strings.LastIndex(path, ":"); i > strings.LastIndex(path, "/") {
path, tag = path[:i], path[i+1:]
if tag == "" {
tag = "latest"
}
}
var tag string
if i := strings.LastIndex(path, ":"); i > strings.LastIndex(path, "/") {
path, tag = path[:i], path[i+1:]
}
if tag == "" {
tag = "latest"
}

Comment thread pkg/compose/model_test.go
"index.docker.io/ai/smollm2": "docker.io/ai/smollm2:latest",
"hf.co/Org/Model-GGUF": "huggingface.co/org/model-gguf:latest",
"HF.co/Org/Model-GGUF:Q4_K_M": "huggingface.co/org/model-gguf:Q4_K_M",
"huggingface.co/org/model": "huggingface.co/org/model:latest",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This row passes through the generic path too (it is already lower case), so it doesn't pin the huggingface.co host check. With a mixed-case path it does: dropping huggingface.co from the host test leaves the whole suite green today, and fails with this row (checked).

Suggested change
"huggingface.co/org/model": "huggingface.co/org/model:latest",
"huggingface.co/Org/Model": "huggingface.co/org/model:latest",

This branch has not been deployed

No deployments
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.

[BUG] A model written in short form is pulled again on every up

3 participants