Skip to content

Studio: reload an idle-unloaded GGUF with its original launch settings - #16927

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:idle-unload-reload-drops-launch
Nov 7, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:idle-unload-reload-drops-launch

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

With idle auto-unload on, a GGUF loaded through the API, the unsloth CLI, the MCP load tool or a one-off load came back from idle with default settings instead of the ones it was loaded with. A model loaded with an 8K context and a q8_0 KV cache returned with the full default context and an f16 cache, and a CPU-only load came back on the GPU. Because the launch no longer matched, the chat context saved before the unload was also thrown away, so the next message re-read the whole conversation.

Each GGUF load now remembers the settings its own request set, and the idle unload keeps them with the model it frees. The next request that reloads that model, whether it names the model or not, uses them again: context, KV cache type, cache RAM, speculative decoding, GPU layers, GPU selection and split, slots and extra llama.cpp flags. A GPU pin that no longer exists is dropped as before, and a load that had fallen back to the CPU reloads with automatic placement. Saved per-model settings are read fresh on every reload and still win. A setting that came from them is never kept with the launch, so one reset while the model is unloaded stays reset. A managed account can reload the owner's freed launch with its file path flags, as it already could while that launch was loaded. A scheduled task that swaps a model out now puts it back with these settings too. MLX models still reload as before.

@NilayYadav NilayYadav self-assigned this Nov 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T23:34:50.194966Z 89c78ee 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[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator 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: 9c966455c9

ℹ️ 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 +8210 to +8211
if "gpu_memory_mode" in override_kwargs:
kwargs.pop("gpu_layers", None)

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 Honor saved Auto memory mode over replayed manual placement

If a one-off launch used gpu_memory_mode='manual', gpu_layers=0, saving Auto memory mode while it is unloaded cannot override that launch: normalize_model_override drops 'auto', so override_kwargs has no mode key and the replayed 'manual' survives. For example, saving {'gpu_memory_mode':'auto','kv_cache_dtype':'q8_0'} reloads CPU-only, although a fresh load of the same saved configuration uses automatic GPU fitting. Preserve an explicit default/reset choice in the saved configuration or equivalent provenance so it can override replayed placement.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: saved settings never store defaults, so a row cannot say Auto, and the launch's explicit placement is what the reload is meant to keep.

@NilayYadav

Copy link
Copy Markdown
Collaborator 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: 89c78eed31

ℹ️ 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 +8197 to +8199
owned = model_override_load_kwargs(override, is_gguf = True)
fields = (request.model_fields_set & _REPLAY_LOAD_FIELDS) - owned.keys()
llama_backend.replay_launch = request.model_dump(include = fields)

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 Exclude fields promoted from saved flags from the replay

When a saved override supplies llama_extra_args=['--reasoning-budget', '128'], _load_model_impl promotes it into request.reasoning_budget before this runs. owned contains only llama_extra_args, so the promoted budget is incorrectly retained as one-off intent. Replacing the saved flags with ['--no-warmup'] while unloaded then reloads with reasoning_budget=128, even though a fresh load of that configuration gets -1. Preserve the original field provenance, or also exclude fields derived from saved extras, so removing a saved reasoning limit actually resets the runtime.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: it needs a pass-through budget flag in the saved row (the field exists for it) and an edit to those flags while the model is idle-unloaded.

)
owned = model_override_load_kwargs(override, is_gguf = True)
fields = (request.model_fields_set & _REPLAY_LOAD_FIELDS) - owned.keys()
llama_backend.replay_launch = request.model_dump(include = fields)

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 device sanitization when recording launch extras

For a launch supplying both gpu_ids and a --device or --main-gpu extra, LlamaCppBackend.load_model deliberately strips those extras from its committed requested_extra_args so they cannot return on reload. This instead stores the unstripped request. If _override_gpu_ids_still_resolve later rejects the replayed pin, the stale-pin branch removes only gpu_ids and tensor_split, leaving the previously ignored device option active again instead of restoring automatic placement. Apply the same device sanitization before saving replay extras.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: it needs a redundant --device next to a GPU pin and that GPU disappearing while the model is idle-unloaded.

@NilayYadav

Copy link
Copy Markdown
Collaborator 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: 89c78eed31

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


llama_backend._openai_gguf_companion_roots = tuple(request._gguf_companion_roots)
llama_backend._openai_gguf_companion_state = gguf_companion_state
_note_replay_launch(llama_backend, request)

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 Refresh the replayed GPU pin after an already-loaded success

If a one-off gpu_ids=[0,1] load is fitted down to GPU 0, a subsequent /load with gpu_ids=[0] can return already_loaded: _reuse_loaded_gguf calls adopt_load_intent_if_matched, which records the narrowed pin in last_load_intent. That path returns before this sole _note_replay_launch call, leaving replay_launch pinned to [0,1]. With no saved placement override, idle reloads and scheduled restores therefore restore the old placement pool instead of the accepted GPU-0-only pin. Refresh the replayed placement on successful reuse, or reconcile it with the updated load intent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: it needs a multi-GPU fit-down followed by a repeat /load naming the narrowed pin, and the reload then re-fits from the pool the user originally asked for.

@NilayYadav

Copy link
Copy Markdown
Collaborator 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: 89c78eed31

ℹ️ 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 +11889 to +11891
stored_gpu_index_kind(override)
if "gpu_ids" in override_kwargs
else None,

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 GPU index namespace when replaying a pin

When the owner changes the llama.cpp folder from a Vulkan build to a CUDA build while a pinned model is idle-unloaded, this passes None and skips the namespace check in _override_gpu_ids_still_resolve. Such changes take effect in-process through set_custom_llama_cpp_path, so process lifetime does not guarantee a stable index space. If Vulkan0 and physical GPU 0 are different devices, the old [0] pin is accepted as CUDA GPU 0 instead of being dropped, silently launching the next inference on the wrong GPU. Record the launch-time index kind with replayed pins and validate it as for saved pins.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not changing this: it needs the llama.cpp build switched between Vulkan and CUDA while a pinned model sits idle-unloaded, on a box where the two index spaces differ.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 6, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 89c78eed31

ℹ️ 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 added a commit that referenced this pull request Nov 7, 2026
…ain (#17040)

## Summary

Two tests have been red on main since this morning's merges. Every PR
based on main now inherits them: #17010, which changes only the Windows
bash tool, fails both. Both reproduce on main locally:

```
(Python 3.13, a-f)  studio/backend/tests/test_custom_provider_api_type.py::test_base_url_query_survives_native_provider_calls
    At index 0 diff: ('/v1/models/claude-sonnet-4-5', 'tenant=a') != ('/v1/messages', 'tenant=a')

Repo tests (CPU, studio)  tests/studio/test_model_picker_contracts.py::test_batch_sizes_reach_an_api_load_through_the_server_mirror
    assert 'strip_batch = "n_batch" in kwargs,' in '...openai_auto_switch_settings.py...'
```

In both cases the product change is correct and the test is out of date.

- **#16951 and #16953.** #16951 (keep the base URL query string on
provider calls) added a test that lists every request the three native
providers make. #16953 merged four minutes later. It looks up the
model's output cap with `GET /v1/models/<model>` before a Messages API
stream that sets no `max_tokens`, so that provider now makes one more
request. That request goes through `_append_provider_path`, so it keeps
`?tenant=a`, which is the invariant #16951 cares about. The test simply
predates it. Each PR was green on its own.
- **#16927.** It moved the llama.cpp flag stripping into
`strip_args_shadowed_by(args, fields)`, so the line now reads
`strip_batch = "n_batch" in fields,` and is called with the same kwargs.
What gets stripped is unchanged. The contract test grepped for the old
source line.

## Change

Tests only:

- `test_base_url_query_survives_native_provider_calls` expects the
output-cap lookup first, with its query string kept. It also empties
`_anthropic_output_caps` first, so the lookup happens whatever ran
earlier in the worker. That cache is module-global, and with an entry
already cached the request list would change with test order.
- `test_batch_sizes_reach_an_api_load_through_the_server_mirror` stops
grepping that line. It calls the real `model_override_load_kwargs`,
imported the same way as the lookup-ladder helper already in that file:
  - a stored `-b` is dropped when the override has `n_batch`;
  - a stored `-ub` is dropped when the override has `n_ubatch`;
  - both stay when neither field is set.

## Testing

| | main | this branch |
|---|---|---|
| `test_custom_provider_api_type.py` +
`test_anthropic_default_max_tokens.py` | 1 failed | 29 passed, in either
file order |
| `tests/studio/test_model_picker_contracts.py` | 1 failed | 203 passed
|
| the batch test with `strip_batch = False` planted in
`strip_args_shadowed_by` | | fails |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants