Skip to content

Studio: forward llama-server args from unsloth studio run , activate unsloth run , and allow passing model:quant to load models - #5271

Merged
rolandtannous merged 5 commits into
mainfrom
feature/run-model-extra-args
May 4, 2026
Merged

rolandtannous merged 5 commits into
mainfrom
feature/run-model-extra-args

Conversation

@rolandtannous

@rolandtannous rolandtannous commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • unsloth studio run (and the new top-level alias unsloth run) forward any flag they don't recognize directly to the underlying llama-server subprocess (GGUF only).
  • A small denylist at the /api/inference/load boundary rejects flags Studio fundamentally cannot share with the user (model identity, the auth key, the network endpoint Studio's HTTP proxy targets, single-model server flags). Anything else passes through; llama.cpp's last-wins CLI parsing means the user's value overrides Studio's auto-set version.
  • HTTP callers can pass the same list via LoadRequest.llama_extra_args.
  • --model org/repo:variant shorthand is now accepted on the CLI, mirroring llama.cpp's -hf <repo>:<quant> and ollama's pull syntax. Local paths and Windows drive letters are preserved verbatim.
  • unsloth run is registered as a top-level alias for unsloth studio run so users can drop the studio segment.
  • -hf, -hfr, and --hf-repo are now Typer aliases for --model, matching llama-server's spelling. Typer claims these before the pass-through validator, so the HTTP-API denylist on those flags is unaffected.

Examples

# Top-level alias + repo:variant shorthand
unsloth run --model unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL

# llama-server-style spelling
unsloth run -hf unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL
unsloth run --hf-repo unsloth/gpt-oss-20b-GGUF --gguf-variant UD-Q4_K_XL

# Sampling pass-through
unsloth run --model unsloth/Qwen3-1.7B-GGUF --top-k 20 --seed 42

# Override soft-managed defaults (last-wins)
unsloth run --model X -c 131072 --parallel 1 --threads 32 --flash-attn off

# Custom chat template
unsloth studio run --model X --chat-template-file /abs/path/tpl.jinja

Hard-deny (rejected, returns HTTP 400)

Flags Studio cannot let the user override:

  • Model identity: -m/--model, -hf/-hfr/--hf-repo, -hff/--hf-file, -hft/--hf-token, -mu/--model-url, -dr/--docker-repo, -mm/--mmproj, -mmu/--mmproj-url, -hfv/-hfrv, -hffv. Note: -hf / -hfr / --hf-repo are simultaneously Typer CLI aliases for --model (see above) -- the denylist only fires for LoadRequest.llama_extra_args over HTTP, where the dedicated model_path field is the right channel.
  • Networking: --host, --port, --path, --api-prefix, --reuse-port
  • Auth/TLS: --api-key, --api-key-file, --ssl-key-file, --ssl-cert-file
  • Single-model server: --webui/--no-webui, --models-dir, --models-preset, --models-max, --models-autoload/--no-models-autoload

All short and long aliases are denied as a single group.

Pass-through (user override wins)

Everything else, including knobs Studio also auto-sets:

  • Context / batching / placement: -c/--ctx-size, -np/--parallel, -fa/--flash-attn, --no-context-shift/--context-shift, --jinja/--no-jinja, -ngl/--gpu-layers, -t/--threads, -fit/--fit, -fitt/--fit-target, -fitc/--fit-ctx
  • Sampling: --top-k, --top-p, --min-p, --temp, --repeat-penalty, --mirostat*, --xtc-*, --dry-*, --seed, etc.
  • KV cache / templates / spec: --cache-type-k, --cache-type-v, --chat-template-file, --chat-template-kwargs, --spec-type, --spec-default, --draft-*, --spec-ngram-*, --spec-draft-*
  • Reasoning: -rea/--reasoning, --reasoning-format, --reasoning-budget

User args are appended last in cmd; llama.cpp's CLI parser overwrites earlier values, so Studio's auto-set never beats an explicit user override.

Files

  • new: studio/backend/core/inference/llama_server_args.py (denylist + validator)
  • new: studio/backend/tests/test_llama_server_args.py
  • new: tests/studio/test_cli_repo_variant.py
  • new: tests/studio/test_cli_run_alias.py
  • modified: studio/backend/models/inference.py (LoadRequest.llama_extra_args field)
  • modified: studio/backend/routes/inference.py (validate + forward extra_args to both load_model call sites)
  • modified: studio/backend/core/inference/llama_cpp.py (extra_args kwarg, append to cmd after the --api-key block)
  • modified: unsloth_cli/commands/studio.py (ignore_unknown_options + allow_extra_args, capture ctx.args, repo:variant splitter, -hf Typer alias on --model)
  • modified: unsloth_cli/__init__.py (top-level run alias registration)

Test plan

  • E2E: unsloth run --model unsloth/Qwen3-0.6B-GGUF --gguf-variant Q4_K_M --chat-template-file loads and serves
  • E2E: unsloth run --model unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL loads via embedded variant
  • E2E: unsloth run --model X -c 131072 --parallel 1 --threads 32 -- llama-server picks up the override values (last-wins)
  • E2E: unsloth studio run --model X --chat-template-file /abs/path/template.jinja overrides the embedded GGUF chat template
  • E2E: unsloth run and unsloth studio run produce identical behavior
  • Unit: pytest studio/backend/tests/test_llama_server_args.py -v
  • Unit: pytest tests/studio/test_cli_repo_variant.py -v
  • Unit: pytest tests/studio/test_cli_run_alias.py -v

Roland Tannous added 2 commits May 4, 2026 14:32
`unsloth studio run --model X --top-k 20 --chat-template-file foo.jinja`
now passes the unknown flags through to the llama-server subprocess.
Adds a denylist for flags Studio manages (port, -m, -c, --api-key, -ngl,
--flash-attn, --no-context-shift, --jinja, GPU-fit, model-identity, ...)
that returns HTTP 400 on collision. HTTP callers can supply the same
list via LoadRequest.llama_extra_args.
…o run`

Mirrors llama.cpp's `-hf <repo>:<quant>` and ollama's pull syntax so
`unsloth studio run --model unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL` is
equivalent to `--model unsloth/... --gguf-variant UD-Q4_K_XL`. Local
paths and Windows drive letters are preserved verbatim. If both an
embedded variant and an explicit `--gguf-variant` are given and they
disagree, the command fails with a clear error.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces support for passing extra arguments to llama-server for GGUF models, including a validation layer with a denylist to protect managed flags. The CLI is also updated to support a repo:variant shorthand for model identifiers and to forward unknown arguments to the backend. Feedback was provided to initialize the extra_llama_args variable before its defining try-except block in the inference route to improve code safety and prevent potential reference errors.

Comment thread studio/backend/routes/inference.py Resolved
Roland Tannous added 3 commits May 4, 2026 15:24
Top-level `unsloth run --model ...` is now equivalent to
`unsloth studio run --model ...`. Same context_settings, so unknown
flags continue to pass through to llama-server.
Trims the denylist to flags Studio fundamentally cannot share with
the user (model identity, --host/--port/--path/--api-prefix,
--api-key, --ssl-*, --webui, --models-*). Soft-managed flags --
-c/--ctx-size, --parallel, --flash-attn, --no-context-shift,
--jinja, -ngl, -t/--threads, --fit* -- now pass through and override
Studio's auto-set version via llama.cpp's last-wins CLI parsing.

Lets users tune their run on the spot:
  unsloth run --model X -c 131072 --parallel 1 --threads 32
Matches llama-server's `-hf <repo>:<quant>` spelling so users coming
from llama.cpp can use the same flag. Typer claims the aliases before
the pass-through validator runs, so the HTTP-API denylist on those
flags is unaffected.

  unsloth run -hf unsloth/gpt-oss-20b-GGUF:UD-Q4_K_XL
@rolandtannous

rolandtannous commented May 4, 2026 •

Copy link
Copy Markdown
Contributor Author

tests:

Screenshot 2026-05-04 at 2 42 00 PM Screenshot 2026-05-04 at 3 26 20 PM Screenshot 2026-05-04 at 3 15 10 PM Screenshot 2026-05-04 at 3 13 05 PM Screenshot 2026-05-04 at 3 09 14 PM Screenshot 2026-05-04 at 3 09 03 PM Screenshot 2026-05-04 at 3 04 17 PM Screenshot 2026-05-04 at 2 55 16 PM Screenshot 2026-05-04 at 5 04 17 PM Screenshot 2026-05-04 at 5 05 28 PM Screenshot 2026-05-04 at 5 05 12 PM

@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: db700e530c

ℹ️ 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 on lines +47 to +53
frozenset({"-hf", "-hfr", "--hf-repo"}),
frozenset({"-hff", "--hf-file"}),
frozenset({"-hfv", "-hfrv", "--hf-repo-v"}),
frozenset({"-hffv", "--hf-file-v"}),
frozenset({"-hft", "--hf-token"}),
frozenset({"-mm", "--mmproj"}),
frozenset({"-mmu", "--mmproj-url"}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Deny draft-model identity flags in pass-through validator

The new denylist only blocks main-model selectors (-m, -hf, etc.) but it still allows draft-model selectors like -md/--model-draft and -hfd/-hfrd/--hf-repo-draft, so a caller can pass these via llama_extra_args and make llama-server load additional models outside Studio’s managed model identity. I checked the llama-server(1) option list, which documents those flags as model-selection inputs for speculative decoding; allowing them bypasses the stated model-identity boundary and can cause unexpected downloads/VRAM use while Studio still reports a single managed model.

Useful? React with 👍 / 👎.

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