Skip to content

fix: honor --ctx-size and other forwarded args from unsloth studio run in Studio's context-fit logic - #5815

Merged
rolandtannous merged 4 commits into
unslothai:mainfrom
mvanhorn:fix/5676-fix-honor---ctx-size-and-other-forwarded
May 28, 2026
Merged

rolandtannous merged 4 commits into
unslothai:mainfrom
mvanhorn:fix/5676-fix-honor---ctx-size-and-other-forwarded

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

fix: honor --ctx-size and other forwarded args from unsloth studio run in Studio's context-fit logic

Closes #5676


AI was used for assistance.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@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 parsing and honoring a user-supplied context size override (-c or --ctx-size) passed via extra arguments in the llama.cpp backend. It implements a new parse_ctx_override helper function in llama_server_args.py to extract the override value, integrates this logic into the GPU selection and context fitting routines in llama_cpp.py, and adds comprehensive unit tests to validate correct parsing and behavior.

@rolandtannous

rolandtannous commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the fix! Cross-checked against the denylist from #5271 — the hard-deny groups (model identity, network, auth/TLS, single-model server flags) are intact and this PR doesn't open a path around them. The -c/--ctx-size plumbing into the fit logic looks right.

One thing worth a closer look: the original issue also calls out --cache-type-k q8_0 --cache-type-v q8_0 being unhonored. Those flags reach llama-server fine via last-wins, but Studio's pre-launch KV estimate still computes from the first-class cache_type_kv, not from extras, so GPU placement decisions can still be off when the user lowers cache precision via pass-through. _CACHE_FLAGS already exists in llama_server_args.py, so a symmetric parse_cache_override follow-up would close the loop. Could you double-check this path and update if it's a real gap?

Thanks again!

mvanhorn and others added 3 commits May 27, 2026 11:09
The test helper was reimplementing the two-line
'ctx_override = parse_ctx_override(...); requested_ctx = ctx_override
if ctx_override is not None else n_ctx' pattern locally, so the test
asserted against its own reimplementation rather than production logic.
Extract the conditional into resolve_requested_ctx and have both the
production caller and the test use it.
Studio's KV cache VRAM estimate computed from the first-class
cache_type_kv even when the user passed -ctk/--cache-type-k/-ctv/
--cache-type-v via extras. Those flags reached llama-server fine
(last-wins on the CLI) but the pre-launch estimate kept using the
default f16 bytes-per-element, so GPU placement decisions could be
off when the user lowered cache precision via pass-through.

Adds parse_cache_override + resolve_cache_type_kv in llama_server_args.py
(mirroring parse_ctx_override / resolve_requested_ctx), wires both into
load_model alongside the existing ctx resolution, and adds focused
unit tests for the parser + resolver.

Follow-up to @rolandtannous review on unslothai#5815.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Good catch. Added parse_cache_override + resolve_cache_type_kv in 7218efd - mirrors parse_ctx_override and the load_model wiring. Last-wins across -ctk / --cache-type-k / -ctv / --cache-type-v, treating them as the single cache_type_kv knob Studio already exposes. validate_extra_args now also calls parse_cache_override so invalid input (e.g. missing value) errors at the same point as -c does today. Tests in test_llama_server_args.py cover the parser + resolver edge cases (missing value, flag-as-next-token, both -ctk and -ctv).

Let me know if you'd rather have separate k/v knobs - I kept them folded into the single cache_type_kv slot to match the existing Studio model field, but splitting is a small follow-up if needed.

@rolandtannous

Copy link
Copy Markdown
Contributor

LGTM ✅

Re-checked. The follow-up commit (7218efd) addresses the cache-type gap I flagged, and there's a bonus refactor (0980602).

Cache-type fix — looks correct:

  • New parse_cache_override / resolve_cache_type_kv mirror the ctx helpers (llama_server_args.py), last-wins over -ctk/--cache-type-k/-ctv/--cache-type-v.
  • Wired at llama_cpp.py:2736, before every KV-estimate and GPU-fit consumer, so the override now drives VRAM estimation and the persisted self._cache_type_kv/UI state. Closes the loop I raised.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @rolandtannous for taking the fix that honors --ctx-size and other forwarded args.

@tdbe

tdbe commented May 30, 2026 •

Copy link
Copy Markdown

Have you tried to run something like unsloth studio run --model D:/llama.cpp/Models/Unsloth/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf --ctx-size 128000 --cache-type-k q8_0 --cache-type-v q8_0 --spec-type draft-mtp --spec-draft-n-max 3 and then open http://127.0.0.1:8888/chat? Because I just installed unsloth studio on a new windows 11 pc, and doing this will start the model, but on the right column in the web ui, the Model Configuration has default context length (4096) and devault kv cache dtype etc. In other words, the same stuff as in my ticket is still happening. Am I doing something wrong? When I modify llama_cpp.py like I mentioned in my ticket to hardcode the defaults and no longer use the params, it works and the web ui shows the correct values.

@mvanhorn

mvanhorn commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for taking this @rolandtannous. Honoring --ctx-size and the other forwarded args is one of those fixes you only notice when it's missing.

@mvanhorn

mvanhorn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @rolandtannous for merging the --ctx-size forwarding fix, the CLI args land where users expect now.

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] Context auto-reduced: 262144 -> 4096. And llama-server forwarded --ctx-size params ignored?

4 participants