Skip to content

Studio: resolve GET /v1/models/<id>:<quant> for an on-disk quant - #12727

Merged
danielhanchen merged 4 commits into
mainfrom
studio-v1-models-retrieve-quant
Oct 5, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-v1-models-retrieve-quant

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Part of #9340.

Problem

POST /v1/chat/completions accepts "model": "<repo>:<quant>" to pin one of several downloaded quants, but GET /v1/models/<repo>:<quant> returned 404 for the same string. A client that validates a model id before using it was told the model does not exist.

Change

GET /v1/models/{id} now falls back, after the existing exact-id and legacy-path matches, to resolving <listed id>:<quant>:

  • the base id must be in the caller's own /v1/models listing, so models hidden from a managed account stay hidden;
  • the quant must be on disk, checked through the same resolver chat completions uses (case-insensitive, returned in its canonical spelling, e.g. :q8_0 -> :Q8_0);
  • a suffix that names no quant (:latest) or a quant that is not downloaded still 404s;
  • pinning the resident quant returns the loaded entry (loaded: true, context fields); any other quant returns loaded: false without the resident model's context fields.

GET /v1/models (the list) is unchanged.

Verification

Real resolver and catalog scan against an isolated HF cache holding unsloth/SmolLM2-135M-Instruct-GGUF Q8_0 + Q4_K_M:

request main this PR
GET /v1/models/unsloth/SmolLM2-135M-Instruct-GGUF:Q4_K_M 404 {"id": "...:Q4_K_M", "quant": "Q4_K_M", "loaded": false}
GET /v1/models/unsloth/SmolLM2-135M-Instruct-GGUF:q8_0 404 {"id": "...:Q8_0", "quant": "Q8_0", "loaded": false}
GET /v1/models/unsloth/SmolLM2-135M-Instruct-GGUF:Q2_K (not downloaded) 404 404
GET /v1/models/unsloth/SmolLM2-135M-Instruct-GGUF:latest 404 404
GET /v1/models/unsloth/SmolLM2-135M-Instruct-GGUF quant: Q4_K_M unchanged

Live Studio on a GPU (this branch, llama-server serving SmolLM2 Q8_0 with Q4_K_M also on disk):

request result
GET /v1/models/...GGUF:Q8_0 (resident) 200 {"quant": "Q8_0", "loaded": true, "context_length": 2048}
GET /v1/models/...GGUF:q4_k_m 200 {"id": "...:Q4_K_M", "quant": "Q4_K_M", "loaded": false}
GET /v1/models/...GGUF:Q2_K / :latest 404 model_not_found
GET /v1/models/...GGUF unchanged (quant: Q8_0, loaded: true)

The first request after a load arrives before the resolver index is rewarmed, when the loaded row carries no quant yet; the resident check falls back to the backend's loaded variant so the resident pin still reports loaded: true.

Tests: four new cases in tests/test_openai_catalog.py; the positive ones fail on main and pass here, the 404 case guards against over-matching. Failing test IDs across test_openai_catalog.py, test_openai_auto_switch.py, test_keyless_api_access_adversarial.py, test_warm_window_review_fixes.py and test_account_local_model_resolver.py are identical on main and this branch (environment only: fastmcp not installed, host HF cache rows).

Not covered here: listing each quant as its own id in GET /v1/models, which is what dropdown-only clients in #9340 need.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T09:06:58.426265Z 69cf31f Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-05T07:22:43.131121Z f113a78 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 27e8f27449

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7043f6e3e6

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Outdated
Comment on lines +34978 to +34979
resident = listed.get("quant") or getattr(get_llama_cpp_backend(), "hf_variant", None)
if listed.get("loaded") and str(resident or "").lower() == variant.lower():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the matching slot when inferring the resident quant

When the resolver index is cold and a model is resident in an extra slot, its catalog row can omit quant, but this fallback executes after _openai_model_objects() has left that slot's routing context, so get_llama_cpp_backend() returns the primary backend. If the slots use different quants, retrieving the extra slot's resident pin is reported as unloaded; if its requested quant happens to match the primary quant, it is incorrectly reported as loaded with the extra model's context fields. Preserve the originating slot/quant while building the row or otherwise query the backend associated with listed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 69cf31f: residency now comes from the slot whose backend serves the listed id, not the primary backend.

Comment thread studio/backend/routes/inference.py Outdated
Comment on lines +34962 to +34964
base, sep, quant = model_id.rpartition(":")
# ":latest" names no quant, so the resolver would answer it with the repo's default one.
if not sep or not base or not looks_like_quant(quant):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve accepted legacy pins before rejecting suffixes

For GGUFs whose previously published variant label is not quant-shaped, such as the legacy Meta-Llama-3-8B.gguf label 8B, resolve_local_gguf() deliberately accepts <id>:8B through _legacy_variant_aliases() so cached client pins continue working. This early looks_like_quant() check rejects that request before consulting the resolver, so GET /v1/models/<id>:8B still returns 404 even though chat completions accept the identical model string. Distinguish an exact legacy-alias resolution from generic non-quant fallbacks such as :latest rather than rejecting all non-quant-shaped suffixes up front.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 69cf31f: the suffix is resolved against current labels and legacy aliases, so :8B style pins resolve while :latest still 404s.

Comment on lines +34982 to +34984
shared = {
k: listed[k] for k in ("object", "created", "owned_by", "display_name") if k in listed
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the task on alternate quant objects

When a loaded GGUF is a speech model, its catalog row carries task: "text-to-speech", but retrieving another on-disk quant takes this branch and copies only the four whitelisted fields, silently dropping task. The resulting model object presents the alternate quant as an untyped model even though the base and resident-quant objects identify it as TTS; clients that interpret a missing task as a chat model can consequently route the validated pin to the wrong API. Preserve variant-independent capability fields such as task while omitting only resident-specific context fields.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 69cf31f: task is kept on alternate quant objects; only resident context fields are dropped.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 69cf31f17e

ℹ️ 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".

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.

1 participant