Repository navigation
Studio: let full-scope keyless callers auto-switch models, and explain the refusal elsewhere - #11180
Conversation
A /v1 request admitted by keyless API access had model auto-switch, auto-download and idle-stash restore turned off in every scope. Under the full scope the same loopback caller is already admitted to POST /api/inference/load and POST /api/hub/download, so the block guarded nothing, while local agents that send no key or a dummy bearer (hermes-agent sends no-key-required) got 400 "No model loaded" on a cold slot and a retryable 503 on a warm one. A keyless caller is now held back only when keyless access would not also admit it to POST /api/inference/load, evaluated with the existing admission predicate for this request's transport. The inference scope keeps the current behaviour. Usage examples stay pinned to the loaded model only under the inference scope. Fixes unslothai#11140
With model auto-switch on, a keyless caller that keyless access does not also admit to POST /api/inference/load (the inference scope) is kept on the loaded model. Naming a different downloaded model answered it with 503 model_switch_failed, "could not switch... Retry shortly" and Retry-After, although nothing failed and no retry can succeed; with nothing loaded it got the generic "No model loaded. Call POST /inference/load first.", a route it cannot call. The warm case now returns 404 model_not_found, like the refusal when switching is off, saying keyless API access can only use the loaded model and that an API key switches models by request. The cold case keeps its status and says keyless access cannot load the named model. Keyed callers and callers under the full scope keep the existing responses.
c20a944 to
ea87785
Compare
|
Confirmed the gate in studio/backend/routes/inference.py still disables auto-switch for every keyless scope including full, and that deriving the rule from admission on POST /api/inference/load rather than a scope string comparison is the right shape. Will get this reviewed. |
|
Review record for #11180, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#151. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
…n the refusal elsewhere (unslothai#11180) * fix(studio): let keyless callers under the full scope auto-switch models A /v1 request admitted by keyless API access had model auto-switch, auto-download and idle-stash restore turned off in every scope. Under the full scope the same loopback caller is already admitted to POST /api/inference/load and POST /api/hub/download, so the block guarded nothing, while local agents that send no key or a dummy bearer (hermes-agent sends no-key-required) got 400 "No model loaded" on a cold slot and a retryable 503 on a warm one. A keyless caller is now held back only when keyless access would not also admit it to POST /api/inference/load, evaluated with the existing admission predicate for this request's transport. The inference scope keeps the current behaviour. Usage examples stay pinned to the loaded model only under the inference scope. Fixes unslothai#11140 * fix(studio): tell a keyless caller that cannot switch models why With model auto-switch on, a keyless caller that keyless access does not also admit to POST /api/inference/load (the inference scope) is kept on the loaded model. Naming a different downloaded model answered it with 503 model_switch_failed, "could not switch... Retry shortly" and Retry-After, although nothing failed and no retry can succeed; with nothing loaded it got the generic "No model loaded. Call POST /inference/load first.", a route it cannot call. The warm case now returns 404 model_not_found, like the refusal when switching is off, saying keyless API access can only use the loaded model and that an API key switches models by request. The cold case keeps its status and says keyless access cannot load the named model. Keyed callers and callers under the full scope keep the existing responses. * Take the keyless load-route probe off the event loop * Read the keyless load probe through the retrying settings accessor * Trim keyless auto-switch comments --------- Co-authored-by: oobabooga <[email protected]> Co-authored-by: Daniel Han <[email protected]>
Fixes #11140
Problem
With Model auto-switch on and keyless API access set to full, an OpenAI-compatible client that sends no key never got a model loaded. That includes the hermes-agent default, which sends the approved dummy bearer
no-key-required:400 No model loaded. Call POST /inference/load first., no load attempted503 model_switch_failed("could not switch… Retry shortly",Retry-After: 5), no switch attemptedSo every local agent failed its first request after Studio started, until someone loaded a model by hand.
Root cause
_maybe_auto_switch_modelturned auto-switch off for every caller admitted by keyless access, in every scope (added in #9102 so a LAN caller under theinferencescope cannot repeatedly evict the operator's model or fetch Hub repos). Under thefullscope, which is loopback-only, the same keyless caller is already admitted toPOST /api/inference/load,POST /api/inference/unloadandPOST /api/hub/download. The block therefore protected nothing there and only broke the automatic path. Because the global setting reads as enabled, the 400 also dropped the "enable auto-switch" hint, so nothing explained the failure.Changes
1.
fix(studio): let keyless callers under the full scope auto-switch modelskeyless_request_may_load_models(request)evaluates the existing keyless admission predicate forPOST /api/inference/loadusing this request's transport. It deliberately does not comparescope == "full", so the rule cannot drift from admission._keyless_caller_held_back) only when that predicate is false. It is used for both places that previously keyed off "keyless": the auto-switch gate and the idle-stash restore restriction.fullover loopback, a keyless request behaves like a keyed one, including auto-download when that setting is on. Auto-download only ever uses an HF token the caller sends itself, which is narrower than the direct download route. Theinferencescope is unchanged.inferencescope.2.
fix(studio): tell a keyless caller that cannot switch models whyFor a caller that is still held back (the
inferencescope) with auto-switch on:503 model_switch_failed, "Retry shortly",Retry-After: 5404 model_not_found: keyless API access can only use the loaded model; an API key switches models by request (same shape as the existing "switch is off" refusal)400"Call POST /inference/load first."Keyed callers, UI sessions and
full-scope keyless callers keep the existing responses.Risk / tradeoffs
full, that can be split out without affecting the switch fix.inferencescope keeps the protection from Studio: add secure keyless localhost and private-LAN API access #9102. The only change there is the refusal wording and status: a 503 that invited endless retries becomes a 404.Validation
Selected tests (the one failure also fails on
mainon a case-insensitive filesystem):python -m pytest studio/backend/tests/test_keyless_api_access.py tests/studio/test_usage_examples_model_source_contract.py studio/backend/tests/test_openai_auto_download.py studio/backend/tests/test_openai_auto_switch.py -q -n 8 # 898 passed, 1 failed (test_hf_cache_entry_stays_within_the_scanned_case_variant, pre-existing)fullkeyless loads whileinferencekeyless does not; idle-stash restore is restricted underinferencebut not underfull; held-back callers get the new cold (400) and warm (404, noRetry-After) refusals, while the same request underfullkeeps the generic text. Each new test was mutation-checked: reverting the production branch it covers makes exactly that case fail.openai_chat_completionshandler, matrix {full, inference} × {cold, warm} × {no header,no-key-required, real API key}: full keyless now loads in every case, inference keyless never loads, keyed callers are unchanged.tsc -p tsconfig.app.jsonclean.Before / after (Settings > API, keyless scope full, auto-switch on, nothing loaded)
Two isolated Studio installs (merge base
fdbc8676avs headf10893bfd), same seeded cache holding onlyunsloth/SmolLM2-135M-Instruct-GGUFQ4_K_M, keyless request sent with no Authorization and no Origin header:unsloth/SmolLM2-135M-Instruct-GGUF:Q4_K_MPOST /v1/chat/completions, scope full, no keyNo model loaded. Call POST /inference/load first.No model loaded. Call POST /inference/load first.No model is loaded, and keyless API access cannot load ... Load it in Unsloth Studio, or send an Unsloth API key.