Skip to content

[Bug] Context auto-reduced: 262144 -> 4096. And llama-server forwarded --ctx-size params ignored? #5676

Closed

Description

@tdbe

According to the docs: "For context size and KV cache type, use unsloth run and pass the underlying llama-server flags. Extra flags are forwarded, including context size and cache settings."

So I tried this command:

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

Unsloth Studio starts and loads the model, but none of these settings are applied. After reading the command line output, I see it even defiantly mentions:

{"timestamp": "2026-05-21T21:01:49.903222Z", "level": "info", "event": "Context auto-reduced: 262144 -> 4096 (model: 36.4 GB, est. KV cache: 0.1 GB)"} -- "262144" must be what I manually set & reloaded from the web ui during the previous run. [Update: even after you changed the unsloth studio context size to 32768, it still prints this 4096 message, wtf?]

And then says:

"Appending user extra args to llama-server: ['-c', '128000', '--cache-type-k', 'q8_0', '--cache-type-v', 'q8_0']"}

{"timestamp": "2026-05-21T21:24:01.649844Z", "level": "info", "event": "Starting llama-server: C:\\Users\\Am1\\.unsloth\\llama.cpp\\build\\bin\\Release\\llama-server.exe -m D:\\llama.cpp\\Models\\Unsloth\\Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf --port 54281 -c 4096 --parallel 4 --flash-attn on --no-context-shift --fit on --threads -1 --jinja --spec-type draft-mtp --spec-draft-n-max 2 --chat-template-kwargs {\"enable_thinking\": false} --mmproj D:\\00-Models\\llama.cpp\\Models\\Qwen3.6-35B-A3B-UD-Q8_K_XL\\mmproj-BF16.gguf -c 128000 --cache-type-k q8_0 --cache-type-v q8_0"} -- this is so confusing, note the first -c 4096 and then my useless -c 128000 at the end?

In the UI, on the Configuretion column on the right side, under Model, it has the default values 4096 32768, and kv cache sizze f16. These forced default settings are objectively horrible and unusable. f16 is too high and 4096 32768 is not enough for most llm answers to most questions especially if they use tools and search the web.

What am I supposed to do to change the defaults? I want all clients on my network to be served a specific model with a specific context!

Activity

  1. tdbe commented on May 21, 2026

    @tdbe
    Author

    I just updated unsloth studio and now the default context size is: 32768 (32k). (Which is still too small.)

    And now if I do a unsloth studio run --model ... I get this error now: 'Studio venv missing 'unsloth' entry point. Re-run: unsloth studio setup' Apparently unsloth studio setup is deprecated now, but I "fixed" this problem by running & "$HOME\.unsloth\studio\unsloth_studio\Scripts\Activate.ps1" before I run unsloth studio run --model ....

    I still don't see a way to change the defaults.

    But I saw _DEFAULT_MAX_TOKENS_FLOOR = 32768 in C:\Users\User\.unsloth\studio\unsloth_studio\Lib\site-packages\studio\backend\core\inference\llama_cpp.py I read through its usage and changed it to 262144. But you also need to:

    • requested_ctx = requested_ctx, -> requested_ctx = _DEFAULT_MAX_TOKENS_FLOOR,
    • requested_ctx = requested_ctx, -> requested_ctx = _DEFAULT_MAX_TOKENS_FLOOR,
    • n_ctx = n_ctx, -> n_ctx = _DEFAULT_MAX_TOKENS_FLOOR,
    • effective_ctx = n_ctx if n_ctx > 0 else (self._context_length or 0) -> effective_ctx = n_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • effective_ctx = n_ctx -> effective_ctx = n_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • effective_ctx = self._context_length -> effective_ctx = self._context_length = _DEFAULT_MAX_TOKENS_FLOOR
    • effective_ctx = 0 -> effective_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • explicit_ctx = n_ctx > 0 -> explicit_ctx = n_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • effective_ctx = min(4096, effective_ctx) -> effective_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • min(4096, effective_ctx) if effective_ctx > 0 else 4096 -> _DEFAULT_MAX_TOKENS_FLOOR
    • effective_ctx = n_ctx # fall back to original -> effective_ctx = n_ctx = _DEFAULT_MAX_TOKENS_FLOOR
    • self._requested_n_ctx = int(n_ctx) -> self._requested_n_ctx = n_ctx = _DEFAULT_MAX_TOKENS_FLOOR

    (I'm not sure all these ^ changes are necessary, but some of them definitely are, otherwise the ui will say 262144 but it will actually have 1024 context size for some reason)

    Also to change the defaults for cache_type_kv and _cache_type_kv I think this is the only one you need to change:

        def cache_type_kv(self) -> Optional[str]:
            self._cache_type_kv = "q8_0"
            return self._cache_type_kv
    

    You can also edit the def _canonicalize_spec_mode(value): function to return "mtp+ngram" by default.

    So this manual edit solved my problem. Every update you need to re-apply these changes. Maybe use git and do a stash for your changes. The last time I updated and confirm it works is 2026-05-22.

    Now with these chages to llama_cpp.py, I just start my unsloth studio like this: unsloth studio run --model D:/llama.cpp/Models/Unsloth/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf (don't bother to write any other flags in hopes they get "passed to llama-server" because that shit does nothing). Now, when the ui opens it has the model already loaded and the settings are from the get-go what I want all the clients to use, instead of having to re-f'ing-load the model every time from the client:

    Image Image

    #UX #dogfood

  2. tdbe commented on May 23, 2026

    @tdbe
    Author

    NOTE: starting unsloth studio with the unsloth studio run --model ... command, will break the openai-compatible messaging, as documented but not solved in this merged pr.

    This means that you can't in this mode use Opencode. You can only use opencode if you start by unsloth studio and pick the model from the dropdown in the chat web ui. (this will still use the modified defaults I explained above, but it essentially breaks automation in a more server-like environment)

  3. rolandtannous commented on May 25, 2026

    @rolandtannous
    Contributor

    @tdbe can you be more specific on which part is broken?
    will check opencode in that mode thanks.
    any other symptoms, stack traces, you can share?

  4. tdbe commented on May 25, 2026

    @tdbe
    Author

    Hi. Ok:

    A. The path to start unsloth studio with a specific --model is broken:

    1. Any parameter sent besides the --model, is ignored by the backend:

    E.g. if you run 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:

    • unsloth studio receives the --model param, and it's supposed to forward the rest of the params to llama-server, but according to the log output, and according to actual behaviour, it still loads defaults (ignores your params)

    2. Openai compatibility

    In this --model mode, unsloth studio doesn't conform to openai-compatible messaging as described in those comments in this pr and in my comment above. So it can't be used with opencode (opencode can't parse). But it does work in the unsloth studio mode (the non --model mode).

    B. There is no way to start unsloth studio with your own defaults

    • Path 1: via web ui: there is no way to remember settings in the ui, every time you pick a model in the unsloth studio mode (not the unsloth studio --model mode) it first overrides previous settings with defaults (e.g. context length, cache type), even if you already loaded this model before. Then you have to manually change values and reload the model.
    • Path 2: via command line params? Both the unsloth studio mode and the the unsloth studio --model mode ignore any additional llama-server params you might want to give it.
    • Path 3: hax: The only option left is to hack away at various hardcoded values in llama_cpp.py.

    This makes automating unsloth studio, ie deploying it on a lan automatically and in a way that all users get the sepcific settings you can support or want to serve, impossible (unless you hack llama_cpp.py) and, actually impossible, if you want to use opencode in the automated startup unsloth studio --model mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions