Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: choose Off, When they fit or Always in Model memory, and keep the chat context when an image or video model takes the GPU (#14108)
Etherl22531d3cbd5a
diff --git a/studio/backend/core/inference/chat_swap_kv.py b/studio/backend/core/inference/chat_swap_kv.pynew file mode 100644index 00000000000..208fb40dc05--- /dev/null+++ b/studio/backend/core/inference/chat_swap_kv.py@@ -0,0 +1,298 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Keep the chat context when an image or video load takes the GPU from chat.++Before the media acquire (outside every lock) the chat slots' KV is saved to disk, bounded by+``SWAP_KV_SAVE_BUDGET_S``. The manifest waits here as "pending" until ``gpu_arbiter._evict_chat``+unloads that same model; only then does it become the keep-warm stash that the next chat load+restores. If nothing was evicted, ``SwapSave.close`` drops it and deletes its files.++Lock order: gpu_arbiter._lock -> this _lock -> llama_keepwarm._lock.+"""++from __future__ import annotations++import asyncio+import contextlib+import threading+import time+from typing import Optional++from loggers import get_logger++logger = get_logger(__name__)++# Keeps the load POST far below the ~100 s a quick tunnel allows a silent request.+SWAP_KV_SAVE_BUDGET_S = 45.0+SAVING_CHAT_CONTEXT = "saving_chat_context"++_lock = threading.Lock()+# {"identity", "origin": "swap", **manifest}, waiting for _evict_chat to unload that model.+_pending: Optional[dict] = None+# The manifest a commit promoted, so the handle that saved it writes the lifecycle row.+_committed: Optional[dict] = None+# (media, account id) -> how many saves are running, for the load-progress phase.+_saving: dict[tuple[str, Optional[str]], int] = {}+++def _account_id() -> Optional[str]:+ try:+ from utils.account_context import current_account_id+ return current_account_id()+ except Exception:+ return None+++def saving_progress(media: str) -> Optional[dict]:+ """The load-progress answer while the caller's own save runs, else None."""+ with _lock:+ if _saving.get((media, _account_id())):+ return {"phase": SAVING_CHAT_CONTEXT}+ return None+++def _saving_marker(media: str, account: Optional[str]):+ key = (media, account)+ with _lock:+ _saving[key] = _saving.get(key, 0) + 1+ try:+ yield+ finally:+ with _lock:+ left = _saving.get(key, 1) - 1+ if left > 0:+ _saving[key] = left+ else:+ _saving.pop(key, None)+++def _delete(manifest) -> None:+ if manifest:+ from core.inference.llama_keepwarm import _delete_resume_files+ _delete_resume_files(manifest)+++def commit_after_chat_unload(unloaded_identity) -> bool:+ """Called by _evict_chat after the unload: the pending save becomes the reload stash."""+ global _pending, _committed+ with _lock:+ pending, _pending = _pending, None+ if pending is None:+ return False+ # "Keep chat context across unloads" may have been turned off while the save ran.+ if unloaded_identity is None or pending.get("identity") != unloaded_identity or not _keep_kv():+ # Chat swapped during the save (its KV is useless) or keep KV is off now.+ _delete(pending)+ return False+ with _lock:+ _committed = pending+ from core.inference import llama_keepwarm++ llama_keepwarm._set_kv_resume(pending)+ logger.info("Media swap: kept the chat slot KV for restore on reload")+ return True+++class SwapSave:+ """Handle the load route closes in a finally around its acquire."""++ def __init__(+ self,+ manifest: Optional[dict] = None,+ *,+ log_swap: bool = True,+ ):+ self._manifest = manifest+ # Off logs the eviction here; When they fit's residency code already logs it as "evicted".+ self._log_swap = log_swap++ def close(self) -> None:+ global _pending, _committed+ manifest, self._manifest = self._manifest, None+ if manifest is None:+ return+ try:+ dropped = committed = False+ with _lock:+ if _pending is manifest:+ # Nothing evicted chat: the save is stale the moment the load is done.+ _pending, dropped = None, True+ elif _committed is manifest:+ _committed, committed = None, True+ if dropped:+ _delete(manifest)+ elif committed and self._log_swap:+ from core.inference import llama_keepwarm+ llama_keepwarm._note_idle_unload_event(manifest.get("identity"), reason = "swap")+ except Exception as exc: # noqa: BLE001 - the load already ran+ logger.debug("chat KV swap cleanup failed: %s", exc)+++async def acquire_then_close(swap: SwapSave, acquire):+ """Run the blocking acquire on a thread and close ``swap`` only once that thread is done. A+ cancelled request leaves the thread running, and it may still evict chat and commit the save."""+ task = asyncio.ensure_future(asyncio.to_thread(acquire))++ def _done(finished) -> None:+ if not finished.cancelled():+ finished.exception() # an awaiter still there re-raises it+ swap.close()++ task.add_done_callback(_done)+ return await asyncio.shield(task)+++def _keep_kv() -> bool:+ try:+ from utils.openai_auto_switch_settings import get_auto_unload_keep_kv+ return bool(get_auto_unload_keep_kv())+ except Exception:+ return False+++def _request_counted() -> bool:+ """Whether the middleware counts this request as chat inference: a /v1 image or video call+ loading through the media auto-switch. Read it on the request's context, not the save thread."""+ from core.inference import llama_keepwarm++ scope = llama_keepwarm._current_response_scope.get()+ return isinstance(scope, dict) and bool(scope.get(llama_keepwarm._TRACKED_SCOPE_KEY))+++def _chat_busy(counted: bool = False) -> bool:+ from state import active_generations++ if active_generations.count() > 0:+ return True+ if counted:+ # The auto-switch holds chat's lifecycle gate, so a request waiting behind it can't start.+ from core.inference.media_switch_backends import chat_busy+ return chat_busy(count_pending = False)+ from core.inference import llama_keepwarm++ return llama_keepwarm.other_inference_request_count(current_request_counted = False) > 0+++def _chat_account() -> Optional[str]:+ from core.inference import gpu_arbiter+ try:+ return gpu_arbiter.owner_account(gpu_arbiter.CHAT)+ except TypeError:+ return gpu_arbiter.owner_account()+++def _save_in_thread(llama, should_abort, abort: threading.Event, loop, future) -> None:+ """Runs the blocking save on its own thread, so neither the budget nor the event loop's+ shutdown waits on it. A result nobody is waiting for any more is deleted right here."""+ try:+ manifest, error = llama.save_slots_for_resume(should_abort), None+ except BaseException as exc: # noqa: BLE001 - reported to the waiter+ manifest, error = None, exc+ if abort.is_set():+ _delete(manifest)+ return++ def _deliver():+ if future.done():+ _delete(manifest)+ elif error is not None:+ future.set_exception(error)+ else:+ future.set_result(manifest)++ try:+ loop.call_soon_threadsafe(_deliver)+ except RuntimeError: # the loop is gone+ _delete(manifest)+++async def save_chat_kv_before_swap(+ owner: str,+ media: str,+ *,+ policy: str = "off",+ need_mib: Optional[dict] = None,+ gpu_ids: Optional[list] = None,+ **_ignored,+) -> SwapSave:+ """Save the chat KV if acquiring ``owner`` will evict the chat model; never raises.++ ``policy``, ``need_mib`` and ``gpu_ids`` are the keywords the route passes to the acquire, so the peek+ predicts that exact acquire. Off passes none, and the acquire then runs as Off too."""+ global _pending+ try:+ from core.inference import gpu_arbiter+ from core.inference.llama_keepwarm import _loaded_identity+ from utils.openai_auto_switch_settings import get_auto_unload_keep_kv++ if not gpu_arbiter.would_evict(owner, policy = policy, need_mib = need_mib, gpu_ids = gpu_ids):+ return SwapSave()+ if not await asyncio.to_thread(get_auto_unload_keep_kv):+ return SwapSave()+ from routes.inference import get_llama_cpp_backend++ llama = get_llama_cpp_backend()+ identity = _loaded_identity(llama)+ if identity is None or not getattr(llama, "_gguf_path", None):+ return SwapSave()+ account = _account_id()+ counted = _request_counted()+ if _chat_account() != account or _chat_busy(counted):+ return SwapSave()+ except Exception as exc: # noqa: BLE001 - fail open: the load runs as before+ logger.debug("chat KV swap save skipped: %s", exc)+ return SwapSave()++ budget = SWAP_KV_SAVE_BUDGET_S+ abort = threading.Event()+ deadline = time.monotonic() + budget++ def should_abort() -> bool:+ return abort.is_set() or time.monotonic() >= deadline or _chat_busy(counted)++ loop = asyncio.get_running_loop()+ future = loop.create_future()+ manifest = None+ cancelled = None+ with _saving_marker(media, account):+ threading.Thread(+ target = _save_in_thread,+ args = (llama, should_abort, abort, loop, future),+ name = "chat-kv-swap-save",+ daemon = True,+ ).start()+ try:+ manifest = await asyncio.wait_for(asyncio.shield(future), budget)+ except BaseException as exc: # noqa: BLE001 - timeout, client gone, a failed save+ abort.set()+ # Both this and the thread's delivery run on the loop: a result that just landed+ # is deleted here, and one still to come finds the future cancelled and deletes itself.+ if future.done() and not future.cancelled() and future.exception() is None:+ _delete(future.result())+ future.cancel()+ if isinstance(exc, asyncio.CancelledError):+ cancelled = exc+ elif isinstance(exc, asyncio.TimeoutError):+ logger.info(+ "Media swap: the chat KV save passed %ss; continuing without it", budget+ )+ else:+ logger.debug("chat KV swap save failed: %s", exc)+ if cancelled is not None:+ raise cancelled+ try:+ if manifest and (abort.is_set() or _chat_busy(counted)):+ _delete(manifest)+ manifest = None+ except Exception:+ _delete(manifest)+ manifest = None+ if not manifest:+ return SwapSave()+ entry = {"identity": identity, "origin": "swap", **manifest}+ with _lock:+ older, _pending = _pending, entry+ _delete(older)+ return SwapSave(entry, log_swap = policy == "off")diff --git a/studio/backend/core/inference/gpu_arbiter.py b/studio/backend/core/inference/gpu_arbiter.pyindex 21ebcaae7dd..de363cdcb56 100644--- a/studio/backend/core/inference/gpu_arbiter.py+++ b/studio/backend/core/inference/gpu_arbiter.py@@ -139,7 +139,10 @@ def _evict_chat() -> None:# not healthy. chat_load_active too, since an HF load has no process until its GGUF downloaded. unload_model sets# the cancel event the download loop polls, so it aborts.if llama.is_active or chat_load_active():+ # unload_model clears the identity, so read it first for the pre-swap KV save.+ unloaded = _chat_identity(llama)llama.unload_model()+ _commit_swap_kv(unloaded)orchestrator = get_inference_backend()if orchestrator.active_model_name:orchestrator.unload_model(orchestrator.active_model_name)@@ -163,6 +166,23 @@ def _evict_chat() -> None:clear_resident(CHAT)+def _chat_identity(llama):+ try:+ from core.inference.llama_keepwarm import _loaded_identity+ return _loaded_identity(llama)+ except Exception:+ return None+++def _commit_swap_kv(unloaded) -> None:+ """Promote the chat KV saved before this media load; an eviction never fails on it."""+ try:+ from core.inference.chat_swap_kv import commit_after_chat_unload+ commit_after_chat_unload(unloaded)+ except Exception as exc: # noqa: BLE001+ logger.debug("gpu_arbiter: could not keep the chat KV: %s", exc)++def _evict_diffusion() -> None:# Unload whichever engine the router has active (diffusers or native sd.cpp).from core.inference.diffusion_engine_router import get_active_diffusion_engine@@ -691,6 +711,78 @@ def acquire_for(return result+def would_evict(+ owner: str,+ *,+ policy: str = "off",+ need_mib: Optional[dict] = None,+ gpu_ids: Optional[Iterable[int]] = None,+) -> bool:+ """Lock-free peek: will ``acquire_for(owner, policy = ..., need_mib = ..., gpu_ids = ...)`` unload+ the chat model? Never call it under ``_lock``."""+ if owner == CHAT or owner not in _EVICTORS:+ return False+ holds = globals().get("holds")+ if not (holds(CHAT) if callable(holds) else _owner == CHAT):+ return False+ if policy in ("fit", "always"):+ # Same target as gpu_residency.coreside_locked: chat on other GPUs is never touched.+ target = (+ physical_gpu_ids(gpu_ids)+ if gpu_ids is not None+ else (frozenset(need_mib) if need_mib else None)+ )+ chat_gpus = _view().get(CHAT)+ if chat_gpus is not None and target is not None and not set(chat_gpus) & set(target):+ return False+ if policy == "always":+ # Always refuses the load rather than evicting, except a claim whose load failed and holds nothing.+ try:+ from core.inference.gpu_residency import _claim_holds_anything+ return not _claim_holds_anything(CHAT)+ except Exception: # noqa: BLE001+ return False+ if policy == "fit" and need_mib:+ # An unpriced load evicts first, as Off does; a priced one joins when it fits.+ try:+ from core.inference import gpu_residency+ fits = getattr(gpu_residency, "can_load_alongside", None)+ except ImportError:+ gpu_residency, fits = None, None+ if callable(fits):+ in_flight = getattr(gpu_residency, "chat_load_in_flight", None)+ if callable(in_flight) and in_flight():+ return True # coreside_locked evicts a chat that is still loading+ answer = fits(owner, need_mib)+ ok, info = answer if isinstance(answer, tuple) else (answer, {})+ return not (ok or _idle_media_frees_room(gpu_residency, owner, info))+ return True+++def _idle_media_frees_room(gpu_residency, owner: str, info: dict) -> bool:+ """When they fit frees in gpu_residency._free_steps order and stops once the load fits: the+ idle image or video model on these GPUs goes before the active chat model. Predict that step+ with a margin, since the live re-check may find less freed than was priced; when unsure, save."""+ try:+ short = dict((info or {}).get("short_mib") or {})+ if not short or info.get("reason") != "short":+ return False+ from utils.account_context import current_account_id++ acting = current_account_id()+ for name, need in gpu_residency._media_records().items():+ if name == owner or any(gpu_residency._media_busy(name)):+ continue+ if gpu_residency.foreign_on(name, acting):+ continue+ for gpu in short:+ short[gpu] -= int(need.get(gpu, 0))+ margin = int(getattr(gpu_residency, "FIT_MARGIN_MIB", 1024))+ return all(left <= -margin for left in short.values())+ except Exception: # noqa: BLE001+ return False++def restore_owner_account(owner: str, account_id: Optional[str] = None) -> bool:"""Hand residency back to the displaced account when a claim's load never committed."""global _owner_account, _prior_accountdiff --git a/studio/backend/core/inference/llama_keepwarm.py b/studio/backend/core/inference/llama_keepwarm.pyindex d2dcf2bd972..4641d8bf3a2 100644--- a/studio/backend/core/inference/llama_keepwarm.py+++ b/studio/backend/core/inference/llama_keepwarm.py@@ -17,6 +17,7 @@ import contextvarsimport threadingimport timefrom pathlib import Path+from typing import Optionalfrom loggers import get_logger@@ -592,8 +593,15 @@ def take_kv_resume():return manifest-def purge_kv_resume() -> None:- resume = take_kv_resume()+def purge_kv_resume(*, origin: Optional[str] = None) -> None:+ """Drop the stash; with ``origin``, only one of that origin (an untagged stash is "idle")."""+ global _kv_resume+ with _lock:+ resume = _kv_resume+ if resume is not None and (origin is None or (resume.get("origin") or "idle") == origin):+ _kv_resume = None+ else:+ resume = Noneif resume:_delete_resume_files(resume)@@ -823,9 +831,9 @@ def _loaded_identity(backend):return (*identity, companion_roots) if companion_roots else identity-def _note_idle_unload_event(freed) -> None:- """Monitor row for an idle auto-unload. Best-effort; uses the stash's- advertised repo id so the row never shows the on-disk load path."""+def _note_idle_unload_event(freed, reason: str = "idle") -> None:+ """Monitor row for an idle auto-unload (or a swap, via ``reason``). Best-effort; uses the+ stash's advertised repo id so the row never shows the on-disk load path."""try:from core.inference.api_monitor import api_monitorfrom core.inference.model_ids import public_model_id@@ -834,7 +842,7 @@ def _note_idle_unload_event(freed) -> None:label = public_model_id(advertised or identifier) or "model"if variant and ":" not in label:label = f"{label}:{variant}"- api_monitor.record_lifecycle(event = "unload", model = label, reason = "idle")+ api_monitor.record_lifecycle(event = "unload", model = label, reason = reason)except Exception as exc:logger.debug("idle unload monitor event failed: %s", exc)@@ -925,7 +933,7 @@ async def idle_unload_loop(poll_seconds: float = 15.0) -> None:raise_set_last_unloaded(freed) # let an alias request reload itif manifest and freed:- _set_kv_resume({"identity": freed, **manifest})+ _set_kv_resume({"identity": freed, "origin": "idle", **manifest})logger.info("Idle auto-unload: saved slot KV for restore on reload")elif manifest:_delete_resume_files(manifest)diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.pyindex 6d374d74b9b..5c0992b2448 100644--- a/studio/backend/models/inference.py+++ b/studio/backend/models/inference.py@@ -5331,9 +5331,9 @@ class DiffusionGenerateProgressResponse(BaseModel):class DiffusionLoadProgressResponse(BaseModel):"""Download/finalize progress for an in-flight diffusion load."""- phase: Optional[Literal["downloading", "finalizing", "ready", "error"]] = Field(- None, description = "Load phase; null when idle"- )+ phase: Optional[+ Literal["downloading", "finalizing", "saving_chat_context", "ready", "error"]+ ] = Field(None, description = "Load phase; null when idle")bytes_downloaded: int = Field(0, description = "Bytes present in the HF cache so far")bytes_total: int = Field(0, description = "Estimated total bytes to download (0 = unknown)")fraction: float = Field(0.0, description = "bytes_downloaded / bytes_total, clamped to [0,1]")@@ -6893,9 +6893,9 @@ class VideoGenerateProgressResponse(BaseModel):class VideoLoadProgressResponse(BaseModel):"""Download/finalize progress for an in-flight video load."""- phase: Optional[Literal["downloading", "finalizing", "ready", "error"]] = Field(- None, description = "Load phase; null when idle"- )+ phase: Optional[+ Literal["downloading", "finalizing", "saving_chat_context", "ready", "error"]+ ] = Field(None, description = "Load phase; null when idle")downloaded_bytes: int = Field(0, description = "Bytes present in the HF cache so far")expected_bytes: Optional[int] = Field(None, description = "Estimated total bytes to download (null = unknown)"diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex 5c07e1c5530..ed9e66dbe76 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -51218,7 +51218,10 @@ async def load_diffusion_model_gated(finally:eviction_sink.reset(sink_token)- status_dict = await asyncio.to_thread(_acquire_and_begin)+ from core.inference.chat_swap_kv import acquire_then_close, save_chat_kv_before_swap++ swap = await save_chat_kv_before_swap(DIFFUSION, "image", **fit_kwargs)+ status_dict = await acquire_then_close(swap, _acquire_and_begin)else:# A CPU-only native load never touches the GPU, but switching FROM a previous GPU load leaves DIFFUSION marked as owner, so release (owner-guarded).await asyncio.to_thread(release, DIFFUSION)@@ -52681,6 +52684,11 @@ async def diffusion_load_progress(current_subject: str = Depends(get_current_subject),via_api_key: bool = Depends(authenticated_via_api_key),):+ from core.inference.chat_swap_kv import saving_progress++ saving = saving_progress("image")+ if saving is not None:+ return DiffusionLoadProgressResponse(**saving)if account_access.resident_hidden("diffusion"):return account_access.hidden_resident_response()from core.inference.diffusion_engine_router import get_active_diffusion_enginediff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.pyindex 4de2f7fdd76..e2e296fc839 100644--- a/studio/backend/routes/settings.py+++ b/studio/backend/routes/settings.py@@ -950,7 +950,8 @@ class LlamaCppPathResponse(BaseModel):class OpenAIAutoSwitchPayload(BaseModel):- enabled: bool+ # Optional too, so a row saved outside API keys (Model memory) can't resend a stale value.+ enabled: Optional[bool] = None# None leaves the stored value untouched (partial updates can't clobber it).auto_unload_idle_seconds: Optional[int] = Field(default = None, ge = 0)auto_unload_keep_kv: Optional[bool] = None@@ -2383,9 +2384,13 @@ def update_openai_auto_switch(log = logger,) from excidle_unload_active = get_auto_unload_idle_seconds() > 0- if not keep_kv or not idle_unload_is_configured():- from core.inference.llama_keepwarm import purge_kv_resume+ from core.inference.llama_keepwarm import purge_kv_resume++ if not keep_kv:purge_kv_resume()+ elif not idle_unload_is_configured():+ # Only the chat TTL's own stash; one kept across a media swap survives a TTL save.+ purge_kv_resume(origin = "idle")return OpenAIAutoSwitchResponse(enabled = enabled,auto_unload_idle_seconds = idle_seconds,diff --git a/studio/backend/routes/video.py b/studio/backend/routes/video.pyindex 08d55ab7131..a0c6d987f19 100644--- a/studio/backend/routes/video.py+++ b/studio/backend/routes/video.py@@ -527,7 +527,10 @@ async def load_video_model_gated(finally:eviction_sink.reset(token)- status_dict = await asyncio.to_thread(_acquire_and_begin)+ from core.inference.chat_swap_kv import acquire_then_close, save_chat_kv_before_swap++ swap = await save_chat_kv_before_swap(VIDEO, "video", **fit_kwargs)+ status_dict = await acquire_then_close(swap, _acquire_and_begin)else:await asyncio.to_thread(release, VIDEO)status_dict = await asyncio.to_thread(begin)@@ -569,6 +572,11 @@ async def video_load_progress(current_subject: str = Depends(get_current_subject),via_api_key: bool = Depends(authenticated_via_api_key),):+ from core.inference.chat_swap_kv import saving_progress++ saving = saving_progress("video")+ if saving is not None:+ return VideoLoadProgressResponse(**saving)if account_access.resident_hidden("video"):return account_access.hidden_resident_response()from core.inference.video import get_video_backenddiff --git a/studio/backend/tests/test_auto_switch_partial_save.py b/studio/backend/tests/test_auto_switch_partial_save.pynew file mode 100644index 00000000000..436ea4bda22--- /dev/null+++ b/studio/backend/tests/test_auto_switch_partial_save.py@@ -0,0 +1,94 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The auto-switch PUT without ``enabled`` (a row saved from Model memory) and the origin-aware+KV purge that save runs."""++from __future__ import annotations++import pytest++import routes.settings as settings_route+import storage.studio_db as db+from core.inference import llama_keepwarm as kw+from utils import openai_auto_switch_settings as settings+++def store(monkeypatch):+ stored = {settings.OPENAI_AUTO_SWITCH_SETTING_KEY: True}+ writes: list[dict] = []++ def _upsert(updates):+ writes.append(dict(updates))+ stored.update(updates)++ monkeypatch.setattr(db, "upsert_app_settings", _upsert)+ monkeypatch.setattr(settings, "_cached_setting", lambda k, d = None, *a: stored.get(k, d))+ monkeypatch.setattr(kw, "_kv_resume", None)+ return stored, writes+++def test_a_save_without_enabled_keeps_the_stored_switch(store):+ stored, writes = store+ payload = settings_route.OpenAIAutoSwitchPayload(media_auto_unload_idle_seconds = 300)+ assert payload.enabled is None+ resp = settings_route.update_openai_auto_switch(payload, "tester")+ assert resp.enabled is True+ assert resp.media_auto_unload_idle_seconds == 300+ assert stored[settings.OPENAI_AUTO_SWITCH_SETTING_KEY] is True+ assert writes == [{settings.MEDIA_AUTO_UNLOAD_IDLE_SETTING_KEY: 300}]+++def test_the_setter_treats_a_missing_enabled_as_untouched(store):+ stored, writes = store+ assert settings.set_openai_auto_switch(None, None)[0] is True+ assert writes == [{}] # upsert_app_settings({}) is a no-op on the real store+ assert settings.set_openai_auto_switch(False, None)[0] is False+ assert writes[-1] == {settings.OPENAI_AUTO_SWITCH_SETTING_KEY: False}+ with pytest.raises(ValueError) as exc:+ settings.set_openai_auto_switch("garbage", None)+ assert str(exc.value).startswith("OpenAI auto-switch must be")+++ "origin, keep_kv, configured, kept",+ [+ ("swap", True, False, True), # a media TTL save keeps the swap stash+ ("swap", False, False, False), # keep-KV off purges every stash+ ("idle", True, False, False),+ (None, True, False, False), # an untagged (older) stash counts as idle+ ("idle", True, True, True),+ ],+)+def test_the_purge_rule_follows_the_stash_origin(+ store, monkeypatch, tmp_path, origin, keep_kv, configured, kept+):+ saved = tmp_path / "resume-x-slot0.bin"+ saved.write_bytes(b"kv")+ stash = {+ "identity": ("m", None, "m"),+ "dir": str(tmp_path),+ "slots": [{"filename": saved.name}],+ }+ if origin:+ stash["origin"] = origin+ kw._kv_resume = stash+ monkeypatch.setattr(+ settings_route,+ "set_openai_auto_switch",+ lambda *a: (True, 0, keep_kv, False, False, 300, False),+ )+ monkeypatch.setattr(settings_route, "idle_unload_is_configured", lambda: configured)+ payload = settings_route.OpenAIAutoSwitchPayload(media_auto_unload_idle_seconds = 300)+ settings_route.update_openai_auto_switch(payload, "tester")+ assert (kw._kv_resume is stash) is kept+ assert saved.exists() is kept+++def test_purge_with_an_origin_leaves_another_origin_alone(tmp_path, monkeypatch):+ monkeypatch.setattr(kw, "_kv_resume", {"origin": "swap", "dir": str(tmp_path), "slots": []})+ kw.purge_kv_resume(origin = "idle")+ assert kw._kv_resume is not None+ kw.purge_kv_resume(origin = "swap")+ assert kw._kv_resume is Nonediff --git a/studio/backend/tests/test_swap_kv_resume.py b/studio/backend/tests/test_swap_kv_resume.pynew file mode 100644index 00000000000..5e1168ee594--- /dev/null+++ b/studio/backend/tests/test_swap_kv_resume.py@@ -0,0 +1,492 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The chat KV kept across a media swap: saved before the acquire, promoted to the reload stash+only when _evict_chat unloads that model, and bounded so a slow save never stalls the load POST.++The llama backend, the evictors and the settings are fakes: no llama-server, no GPU."""++from __future__ import annotations++import asyncio+import os+import sys+import threading+import time+from pathlib import Path++import pytest++import core.inference.chat_swap_kv as cs+import core.inference.gpu_arbiter as arb+import routes.inference as inference_routes+from core.inference import llama_keepwarm as kw+from utils import openai_auto_switch_settings as settings+from utils.account_context import current_account_id++_TESTS_DIR = str(Path(__file__).resolve().parent)+if _TESTS_DIR not in sys.path:+ sys.path.insert(0, _TESTS_DIR)++from test_diffusion_routes import client # noqa: E402,F401+++class _FakeLlama:+ def __init__(self, tmp_path):+ self.dir = tmp_path+ self.gguf = tmp_path / "model.gguf"+ self.gguf.write_bytes(b"gguf")+ self._slot_save_binary = ("/bin/llama-server", 111)+ self.saves: list[bool] = []+ self.restores: list[dict] = []+ self.files: list = []+ self.gate = None+ self.entered = threading.Event()+ self.reload()++ def reload(self, gguf = None):+ self.is_loaded = self.is_active = True+ self.model_identifier, self.hf_variant = "unsloth/A-GGUF", "Q4_K_M"+ self._gguf_path = str(gguf or self.gguf)++ def _gguf_file_identity(self, path):+ st = os.stat(path)+ return ((st.st_size, st.st_mtime_ns),)++ def _slot_launch_fingerprint(self):+ return ((), None, None, 1)++ def save_slots_for_resume(self, should_abort):+ self.saves.append(arb._lock.locked())+ gguf = self._gguf_path # the eviction may unload it while a slow save runs+ self.entered.set()+ if self.gate is not None:+ self.gate.wait(10)+ slot = self.dir / f"resume-{len(self.saves)}-slot0.bin"+ slot.write_bytes(b"kv")+ self.files.append(slot)+ return {+ "dir": str(self.dir),+ "binary": self._slot_save_binary,+ "gguf": gguf,+ "gguf_stat": self._gguf_file_identity(gguf),+ "launch": self._slot_launch_fingerprint(),+ "slots": [{"id": 0, "filename": slot.name, "n_saved": 1}],+ }++ def restore_slots_for_resume(self, manifest):+ self.restores.append(manifest)++ def unload_model(self):+ self.is_loaded = self.is_active = False+ self.model_identifier = self._gguf_path = None+++IDENTITY = ("unsloth/A-GGUF", "Q4_K_M", "unsloth/A-GGUF")+++def env(monkeypatch, tmp_path):+ llama = _FakeLlama(tmp_path)+ llama.calls = []+ llama.rows = []++ def _evict_chat():+ llama.calls.append(("evict-chat", list(llama.saves)))+ unloaded = arb._chat_identity(llama)+ llama.unload_model()+ arb._commit_swap_kv(unloaded)++ monkeypatch.setattr(arb, "_owner", arb.CHAT)+ monkeypatch.setattr(arb, "_owner_account", current_account_id())+ for owner in (arb.DIFFUSION, arb.VIDEO):+ monkeypatch.setitem(arb._EVICTORS, owner, lambda: None)+ monkeypatch.setitem(arb._EVICTORS, arb.CHAT, _evict_chat)+ monkeypatch.setattr(kw, "_kv_resume", None)+ monkeypatch.setattr(cs, "_pending", None)+ monkeypatch.setattr(cs, "_committed", None)+ monkeypatch.setattr(cs, "_saving", {})+ monkeypatch.setattr(settings, "get_auto_unload_keep_kv", lambda: True)+ monkeypatch.setattr(inference_routes, "get_llama_cpp_backend", lambda: llama)+ from core.inference.api_monitor import api_monitor++ monkeypatch.setattr(api_monitor, "record_lifecycle", lambda **row: llama.rows.append(row))+ return llama+++def _load(+ owner = arb.DIFFUSION,+ media = "image",+ acquire = None,+ **fit,+):+ async def _go():+ swap = await cs.save_chat_kv_before_swap(owner, media, **fit)+ await cs.acquire_then_close(swap, acquire or (lambda: arb.acquire_for(owner)))++ asyncio.run(_go())+++def _no_files(llama) -> bool:+ return not any(f.exists() for f in llama.files)+++ "policy, fits", [("off", None), ("fit", True), ("fit", False), ("always", None)]+)[email protected]("current", [None, arb.CHAT, arb.DIFFUSION, arb.VIDEO])[email protected]("target", [arb.DIFFUSION, arb.VIDEO, arb.CHAT])+def test_would_evict_matches_acquire_for(monkeypatch, policy, fits, current, target):+ calls: list[str] = []+ monkeypatch.setattr(arb, "_owner", current)+ for owner in (arb.CHAT, arb.DIFFUSION, arb.VIDEO):+ monkeypatch.setitem(arb._EVICTORS, owner, lambda o = owner: calls.append(f"evict-{o}"))+ if fits is not None:+ try:+ from core.inference import gpu_residency+ except ImportError:+ gpu_residency = None+ if hasattr(gpu_residency, "can_load_alongside"):+ monkeypatch.setattr(gpu_residency, "can_load_alongside", lambda *a, **k: (fits, {}))+ need = {0: 1024} if fits is not None else None+ predicted = arb.would_evict(target, policy = policy, need_mib = need)+ kwargs = {"policy": policy}+ if need:+ kwargs["need_mib"] = need+ try:+ arb.acquire_for(target, **kwargs)+ except RuntimeError:+ pass # a refusal evicts nothing+ assert predicted == ("evict-chat" in calls)++[email protected]("policy", ["fit", "always"])[email protected]("gpu, evicts", [(1, False), (0, True)])+def test_would_evict_honours_the_target_gpu_of_an_unpriced_load(monkeypatch, policy, gpu, evicts):+ # media_fit_kwargs passes gpu_ids even when the load can't be priced; chat on another GPU stays.+ from core.inference import gpu_residency as gr++ calls: list[str] = []+ monkeypatch.setattr(arb, "_owner", arb.CHAT)+ monkeypatch.setattr(arb, "_residents", {arb.CHAT: frozenset({0})})+ monkeypatch.setattr(+ arb, "physical_gpu_ids", lambda ids: None if ids is None else frozenset(ids)+ )+ monkeypatch.setattr(gr, "_claim_holds_anything", lambda name: False)+ for owner in (arb.CHAT, arb.DIFFUSION, arb.VIDEO):+ monkeypatch.setitem(arb._EVICTORS, owner, lambda o = owner: calls.append(f"evict-{o}"))+ predicted = arb.would_evict(arb.DIFFUSION, policy = policy, gpu_ids = [gpu])+ try:+ arb.acquire_for(arb.DIFFUSION, policy = policy, gpu_ids = [gpu])+ except RuntimeError:+ pass+ assert predicted is evicts+ assert predicted == ("evict-chat" in calls)+++_ELSEWHERE = {arb.CHAT: frozenset({1})}+_SHARED = {arb.CHAT: frozenset({0}), arb.VIDEO: frozenset({0})}+++ "residents, held, busy, loading, evicts",+ [+ (_ELSEWHERE, 0, False, True, False), # chat on other GPUs is never touched+ (_SHARED, 1600, False, False, False), # the idle video model frees room, with margin+ (_SHARED, 600, False, False, True), # freed exactly, no margin: save anyway+ (_SHARED, 100, False, False, True),+ (_SHARED, 1600, True, False, True), # a generating video model stays+ (_SHARED, 1600, False, True, True), # coreside_locked evicts a chat still loading+ ],+)+def test_would_evict_under_fit_follows_the_free_order(+ monkeypatch, residents, held, busy, loading, evicts+):+ from core.inference import gpu_residency as gr++ monkeypatch.setattr(arb, "_owner", arb.CHAT)+ monkeypatch.setattr(arb, "_residents", residents)+ short = {"reason": "short", "short_mib": {0: 500}}+ monkeypatch.setattr(gr, "can_load_alongside", lambda *a, **k: (False, dict(short)))+ monkeypatch.setattr(gr, "_media_records", lambda: {arb.VIDEO: {0: held}} if held else {})+ monkeypatch.setattr(gr, "_media_busy", lambda name: (False, busy))+ monkeypatch.setattr(gr, "foreign_on", lambda *a: 0)+ monkeypatch.setattr(gr, "chat_load_in_flight", lambda: loading)+ assert arb.would_evict(arb.DIFFUSION, policy = "fit", need_mib = {0: 4000}) is evicts++[email protected]("other_chat_requests, saved", [(0, True), (1, False)])+def test_a_v1_media_switch_does_not_count_itself_as_chat_work(+ env, monkeypatch, other_chat_requests, saved+):+ monkeypatch.setattr(kw, "_inflight", 1 + other_chat_requests) # the /v1 call itself is counted+ monkeypatch.setattr(kw, "_pending", 0)+ token = kw._current_response_scope.set({kw._TRACKED_SCOPE_KEY: True})+ try:+ _load()+ finally:+ kw._current_response_scope.reset(token)+ assert (env.saves == [False]) is saved and (kw._kv_resume is not None) is saved+++def test_keep_kv_turned_off_during_the_save_drops_it(env, monkeypatch):+ env.gate = threading.Event()++ def _turn_off_then_finish():+ env.entered.wait(10)+ monkeypatch.setattr(settings, "get_auto_unload_keep_kv", lambda: False)+ env.gate.set()++ threading.Thread(target = _turn_off_then_finish).start()+ _load()+ assert env.saves == [False] and kw._kv_resume is None and _no_files(env)+++def test_an_off_route_saves_even_if_the_mode_changes_before_the_peek(env, monkeypatch):+ from utils import multi_model_settings++ monkeypatch.setattr(multi_model_settings, "get_multi_model_mode", lambda: "always")+ _load() # media_fit_kwargs gave {} under Off, so the acquire runs as Off+ assert env.saves == [False] and kw._kv_resume["origin"] == "swap"+++def test_a_cancelled_load_keeps_the_save_until_its_acquire_thread_ends(env):+ release = threading.Event()++ def acquire():+ release.wait(10)+ arb.acquire_for(arb.DIFFUSION)++ async def _go():+ swap = await cs.save_chat_kv_before_swap(arb.DIFFUSION, "image")+ request = asyncio.ensure_future(cs.acquire_then_close(swap, acquire))+ await asyncio.sleep(0.05)+ request.cancel() # the client went away; the acquire thread runs on+ with pytest.raises(asyncio.CancelledError):+ await request+ release.set()+ for _ in range(500):+ if env.rows:+ break+ await asyncio.sleep(0.01)++ asyncio.run(_go())+ assert kw._kv_resume["origin"] == "swap" and env.files[0].exists()+ assert [(r["event"], r["reason"]) for r in env.rows] == [("unload", "swap")]+++def test_a_fit_swap_leaves_the_eviction_row_to_the_residency_code(env, monkeypatch):+ monkeypatch.setattr(arb, "would_evict", lambda *a, **k: True)+ _load(policy = "fit") # When they fit logs the eviction itself, as "evicted"+ assert kw._kv_resume["origin"] == "swap" and env.rows == []++[email protected]("owner, media", [(arb.DIFFUSION, "image"), (arb.VIDEO, "video")])+def test_the_save_runs_before_the_acquire_and_commits_on_the_eviction(env, owner, media):+ _load(owner, media)+ assert env.saves == [False] # saved with the arbiter lock free+ assert env.calls == [("evict-chat", [False])] # the eviction ran after the save returned+ stash = kw._kv_resume+ assert stash["origin"] == "swap" and stash["identity"] == IDENTITY+ assert env.files[0].exists() and cs._pending is None+ assert [(r["event"], r["reason"]) for r in env.rows] == [("unload", "swap")]+++def test_the_real_evict_chat_promotes_the_identity_read_before_unload(env, monkeypatch, tmp_path):+ import core.inference as inference_pkg+ import core.inference.llama_cpp as llama_cpp_mod+ import core.inference.model_slots as model_slots+ from hub.services.models import account_access++ class _Orchestrator:+ active_model_name = None+ loading_models = ()+ _managed_engine = None++ def _shutdown_subprocess(self, timeout):+ return True++ env._wait_for_vram_settle = lambda **k: None+ monkeypatch.setattr(model_slots, "unload_extra_models", lambda **k: None)+ monkeypatch.setattr(inference_pkg, "get_inference_backend", lambda: _Orchestrator())+ monkeypatch.setattr(llama_cpp_mod, "chat_load_active", lambda: False)+ monkeypatch.setattr(account_access, "clear_resident", lambda owner: None)+ monkeypatch.setitem(arb._EVICTORS, arb.CHAT, arb._evict_chat)+ _load()+ assert env.is_loaded is False+ assert kw._kv_resume["identity"] == IDENTITY and env.files[0].exists()+++ "case",+ ["generating", "keep_kv_off", "chat_not_resident", "not_gguf", "other_account", "chat_target"],+)+def test_no_save_without_a_chat_eviction_to_survive(env, monkeypatch, case):+ owner = arb.DIFFUSION+ if case == "generating":+ from state import active_generations+ monkeypatch.setattr(active_generations, "count", lambda *a, **k: 1)+ elif case == "keep_kv_off":+ monkeypatch.setattr(settings, "get_auto_unload_keep_kv", lambda: False)+ elif case == "chat_not_resident":+ monkeypatch.setattr(arb, "_owner", None)+ elif case == "not_gguf":+ env._gguf_path = None+ elif case == "other_account":+ monkeypatch.setattr(arb, "_owner_account", "someone-else")+ else:+ owner = arb.CHAT # would_evict is False+ _load(owner)+ assert env.saves == [] and kw._kv_resume is None and cs._pending is None+ assert cs.saving_progress("image") is None++[email protected]("same_model", [True, False])+def test_a_chat_reload_restores_the_swap_stash_only_through_the_guard(env, tmp_path, same_model):+ _load()+ other = tmp_path / "other.gguf"+ other.write_bytes(b"other")+ env.reload(None if same_model else other)+ kw.note_model_loaded(env)+ assert len(env.restores) == (1 if same_model else 0)+ assert kw._kv_resume is None and _no_files(env)++[email protected]("case", ["no_commit", "acquire_raises", "other_model"])+def test_the_pending_save_is_dropped_when_chat_was_not_evicted(env, monkeypatch, case):+ acquire = None+ if case == "no_commit":+ monkeypatch.setitem(arb._EVICTORS, arb.CHAT, lambda: None)+ elif case == "other_model":+ monkeypatch.setitem(arb._EVICTORS, arb.CHAT, lambda: arb._commit_swap_kv(("x", None, "x")))+ else:++ def acquire():+ raise arb.GpuBusyForAnotherAccountError(arb.CHAT, 1)++ try:+ _load(acquire = acquire)+ except arb.GpuBusyForAnotherAccountError:+ assert case == "acquire_raises"+ assert env.saves == [False]+ assert cs._pending is None and kw._kv_resume is None and _no_files(env)+ assert env.rows == []+++def test_the_swap_stash_survives_a_media_ttl_save_but_not_keep_kv_off(env, monkeypatch):+ import routes.settings as settings_route++ _load()+ stash = kw._kv_resume+ monkeypatch.setattr(settings_route, "idle_unload_is_configured", lambda: False)+ for keep_kv, kept in ((True, True), (False, False)):+ monkeypatch.setattr(+ settings_route,+ "set_openai_auto_switch",+ lambda *a, keep_kv = keep_kv: (True, 0, keep_kv, False, False, 300, False),+ )+ payload = settings_route.OpenAIAutoSwitchPayload(media_auto_unload_idle_seconds = 300)+ settings_route.update_openai_auto_switch(payload, "tester")+ assert (kw._kv_resume is stash) is kept and env.files[0].exists() is kept+++def test_saving_progress_is_the_callers_own():+ with cs._saving_marker("image", "someone-else"):+ assert cs.saving_progress("image") is None+ with cs._saving_marker("image", current_account_id()):+ assert cs.saving_progress("image") == {"phase": cs.SAVING_CHAT_CONTEXT}+ assert cs.saving_progress("video") is None+++def _video_client(monkeypatch):+ from fastapi import FastAPI+ from fastapi.testclient import TestClient++ import core.inference.video as video_module+ from auth.authentication import authenticated_via_api_key, get_current_subject+ from routes.video import router as video_router+ from test_video_routes import _FakeBackend++ backend = _FakeBackend()+ monkeypatch.setattr(video_module, "get_video_backend", lambda: backend)+ app = FastAPI()+ app.include_router(video_router, prefix = "/api/inference")+ app.dependency_overrides[get_current_subject] = lambda: "test-user"+ app.dependency_overrides[authenticated_via_api_key] = lambda: False+ return TestClient(app)+++def _cuda(monkeypatch, device = "cuda"):+ import types++ import core.inference.diffusion_device as devmod+ monkeypatch.setattr(+ devmod, "resolve_diffusion_device_target", lambda: types.SimpleNamespace(device = device)+ )+++_LOADS = {+ "image": ("/api/inference/images", {"model_path": "x/z-image", "gguf_filename": "q.gguf"}),+ "video": (+ "/api/inference/video",+ {"model_path": "unsloth/LTX-2.3-GGUF", "gguf_filename": "ltx-2.3-distilled-Q4_K_M.gguf"},+ ),+}++[email protected]("media", ["image", "video"])+def test_a_slow_save_is_bounded_and_its_late_files_are_deleted(+ client,+ env,+ monkeypatch,+ healthy_diffusers,+ media, # noqa: F811+):+ _cuda(monkeypatch)+ if media == "video":+ client = _video_client(monkeypatch)+ base, body = _LOADS[media]+ monkeypatch.setattr(cs, "SWAP_KV_SAVE_BUDGET_S", 0.2)+ env.gate = threading.Event()+ answer: dict = {}++ def _post():+ answer["resp"] = client.post(f"{base}/load", json = body)++ poster = threading.Thread(target = _post)+ poster.start()+ try:+ assert env.entered.wait(5)+ during = client.get(f"{base}/load-progress").json()+ poster.join(10)+ # The POST answered while the save was still blocked: the budget, not the save, ended it.+ returned_while_blocked = not poster.is_alive()+ finally:+ env.gate.set()+ poster.join(10)+ assert during["phase"] == "saving_chat_context"+ assert returned_while_blocked and answer["resp"].status_code == 200+ assert [c[0] for c in env.calls] == ["evict-chat"] # the load went on as before+ assert client.get(f"{base}/load-progress").json()["phase"] != "saving_chat_context"+ deadline = time.monotonic() + 5+ while not (env.files and _no_files(env)) and time.monotonic() < deadline:+ time.sleep(0.01)+ assert env.files and _no_files(env)+ assert kw._kv_resume is None and cs._pending is None++[email protected]("case", ["keep_kv_off", "cpu"])+def test_load_progress_is_unchanged_without_a_save(client, env, monkeypatch, case): # noqa: F811+ _cuda(monkeypatch, "cpu" if case == "cpu" else "cuda")+ if case == "keep_kv_off":+ monkeypatch.setattr(settings, "get_auto_unload_keep_kv", lambda: False)+ base, body = _LOADS["image"]+ assert client.post(f"{base}/load", json = body).status_code == 200+ assert env.saves == [] and kw._kv_resume is None+ assert client.get(f"{base}/load-progress").json() == {+ "phase": "ready",+ "bytes_downloaded": 0,+ "bytes_total": 0,+ "fraction": 1.0,+ "error": None,+ }diff --git a/studio/backend/utils/openai_auto_switch_settings.py b/studio/backend/utils/openai_auto_switch_settings.pyindex b45fb47e6d6..90c4ce9f1dc 100644--- a/studio/backend/utils/openai_auto_switch_settings.py+++ b/studio/backend/utils/openai_auto_switch_settings.py@@ -237,8 +237,8 @@ def set_openai_auto_switch(media_auto_switch: Any = None,) -> tuple[bool, int, bool, bool, bool, int, bool]:"""One-transaction write; ``None`` leaves a stored value untouched."""- parsed_enabled = _coerce_bool(enabled)- if parsed_enabled is None:+ parsed_enabled = None if enabled is None else _coerce_bool(enabled)+ if enabled is not None and parsed_enabled is None:raise ValueError("OpenAI auto-switch must be true or false.")parsed_idle = Noneif idle_seconds is not None:@@ -282,7 +282,9 @@ def set_openai_auto_switch(raise ValueError("Media auto-switch must be true or false.")from storage.studio_db import upsert_app_settings- updates: dict[str, Any] = {OPENAI_AUTO_SWITCH_SETTING_KEY: parsed_enabled}+ updates: dict[str, Any] = {}+ if parsed_enabled is not None:+ updates[OPENAI_AUTO_SWITCH_SETTING_KEY] = parsed_enabledif parsed_idle is not None:updates[AUTO_UNLOAD_IDLE_SETTING_KEY] = parsed_idleif parsed_media_idle is not None:@@ -296,7 +298,8 @@ def set_openai_auto_switch(if parsed_media_auto_switch is not None:updates[MEDIA_AUTO_SWITCH_SETTING_KEY] = parsed_media_auto_switchupsert_app_settings(updates)- _invalidate(OPENAI_AUTO_SWITCH_SETTING_KEY)+ if parsed_enabled is not None:+ _invalidate(OPENAI_AUTO_SWITCH_SETTING_KEY)if parsed_idle is not None:_invalidate(AUTO_UNLOAD_IDLE_SETTING_KEY)if parsed_media_idle is not None:@@ -310,7 +313,7 @@ def set_openai_auto_switch(if parsed_media_auto_switch is not None:_invalidate(MEDIA_AUTO_SWITCH_SETTING_KEY)return (- parsed_enabled,+ parsed_enabled if parsed_enabled is not None else get_openai_auto_switch_enabled(),parsed_idle if parsed_idle is not None else get_stored_auto_unload_idle_seconds(),parsed_keep_kv if parsed_keep_kv is not None else get_auto_unload_keep_kv(),(diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.tsindex b5d97b258f1..68206cc8aef 100644--- a/studio/frontend/scripts/check-bundle-budget.ts+++ b/studio/frontend/scripts/check-bundle-budget.ts@@ -221,8 +221,12 @@ export const BUDGET = {// transfer (6,814,532 -> 6,819,957 B raw, 2,050,886 -> 2,052,328 B transfer against 82523339bd, one machine and build,// Node 24, chunk count unchanged at 95): the local image and video cards in the eager tool UI registry and the// composer and adapter gates in the eager chat chunk. Raised by that growth.- transferBytes: 2_050_095,- rawBytes: 6_814_563,+ // Model memory modes, the refusal toasts and the chat-context save phase (#14108) add 4,315 B raw / 1,495 B+ // transfer (6,819,958 -> 6,824,273 B raw, 2,052,278 -> 2,053,773 B transfer against e2a214bc08, one machine and+ // build, Node 24, chunk count unchanged at 95): the refusal and evicted-model toast helpers are imported by the+ // eager chat, image and video chunks. Raised by that growth.+ transferBytes: 2_051_590,+ rawBytes: 6_818_878,};// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering thediff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.tsindex 54f1f3104ca..cdb28ec491a 100644--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts@@ -16,6 +16,13 @@ import {} from "../lib/server-tuning-fields";import { createElement, useCallback, useEffect, useRef, useState } from "react";import { toast } from "@/lib/toast";+import { evictedSlotsFrom, resyncEvicted, toastEvicted } from "@/lib/evicted-toast";+import {+ isMultiModelRefusal,+ MULTI_MODEL_REFUSAL_TITLE,+ refusalHeadersOf,+} from "@/lib/multi-model-refusal";+import { modelMemorySettingsAction } from "@/features/settings/lib/model-memory-action";import { createNavigationNonce } from "@/lib/navigation-nonce";import {isBackendDownForDesktopUpdate,@@ -2846,15 +2853,9 @@ export function useChatModelRuntime() {cpuFallbackReason = loadResponse.cpu_fallback_reason ?? null;mmprojFallbackReason = loadResponse.mmproj_fallback_reason ?? null;offloadCounts = offloadCountsFrom(loadResponse);- if (loadResponse.evicted?.length) {- toast.info(- `Unloaded ${loadResponse.evicted.join(", ")} to make room`,- {- description:- "Select it again to load it back.",- },- );- }+ const evictedSlots = evictedSlotsFrom(loadResponse);+ toastEvicted(evictedSlots);+ resyncEvicted(evictedSlots, "chat");// If cancelled while loading, do not show the model as active: it is being unloaded.if (abortCtrl.signal.aborted) throw new Error("Cancelled");@@ -3751,16 +3752,18 @@ export function useChatModelRuntime() {runnerLogPath,): undefined;+ // Refused by Model memory: the backend's sentence is the explanation, settings the fix.+ const refusal = isMultiModelRefusal(null, refusalHeadersOf(err), message);+ const title = refusal ? MULTI_MODEL_REFUSAL_TITLE : summary;+ const description = refusal ? message : detail || undefined;+ const action = refusal ? modelMemorySettingsAction() : logsAction;if (loadToastDismissedRef.current) {- toast.error(summary, {- description: detail || undefined,- action: logsAction,- });+ toast.error(title, { description, action });} else {- toast.error(summary, {+ toast.error(title, {id: toastId,- description: detail || undefined,- action: logsAction,+ description,+ action,cancel: undefined,classNames: undefined,closeButton: true,diff --git a/studio/frontend/src/features/images/api.ts b/studio/frontend/src/features/images/api.tsindex 9dc7052a8bc..329d4f7fdc0 100644--- a/studio/frontend/src/features/images/api.ts+++ b/studio/frontend/src/features/images/api.ts@@ -4,6 +4,7 @@import { withBackgroundLoadNotice } from "@/lib/model-lifecycle-events";import { authFetch } from "@/features/auth";import { readFastApiError } from "@/lib/format-fastapi-error";+import { parseLoadJson } from "@/lib/multi-model-refusal";import {isMemoryEstimateRefusal,MEMORY_REFUSAL_HEADER,@@ -138,7 +139,13 @@ export interface DiffusionGenerateProgress {}export interface DiffusionLoadProgress {- phase: "downloading" | "finalizing" | "ready" | "error" | null;+ phase:+ | "downloading"+ | "finalizing"+ | "saving_chat_context"+ | "ready"+ | "error"+ | null;bytes_downloaded: number;bytes_total: number;fraction: number;@@ -389,7 +396,7 @@ export async function loadDiffusionModel(body: DiffusionLoadRequest): Promise<Di"image",body.model_path,async () =>- parseJson<DiffusionStatus>(+ parseLoadJson<DiffusionStatus>(await authFetch("/api/inference/images/load", {method: "POST",headers: { "Content-Type": "application/json" },diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex 36c27e057cd..9ca25b50377 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -211,6 +211,10 @@ import {routedGgufLabel,} from "@/lib/diffusion-route-search";import { toast } from "@/lib/toast";+import { evictedSlotsFrom, evictedToastOptions, resyncEvicted, type EvictedSlot } from "@/lib/evicted-toast";+import { failureMessage, isMultiModelRefusal, MULTI_MODEL_REFUSAL_TITLE, refusalHeadersOf } from "@/lib/multi-model-refusal";+import { watchSavingPhase } from "@/lib/swap-save-phase";+import { modelMemorySettingsAction } from "@/features/settings/lib/model-memory-action";import { MAX_UPLOAD_IMAGE_SIDE, fitImageDataUrl } from "@/lib/image-fit";import { loadGalleryUntil } from "@/lib/gallery-deep-link";import { subscribeModelEjected } from "@/lib/model-lifecycle-events";@@ -661,6 +665,14 @@ const LOAD_TOAST_CLASSNAMES = {// Render the chat ModelLoadDescription for a progress poll. The base repo downloads alongside// the GGUF, so the total exceeds the quant size.function loadToastDescription(p: DiffusionLoadProgress) {+ if (p.phase === "saving_chat_context") {+ return (+ <ModelLoadDescription+ title="Saving chat context…"+ message="Saving the chat model's context so it can resume after this load."+ />+ );+ }// "Downloading" only when bytes actually remain: a cached model must not claim a download.const downloading = p.bytes_total > 0 && p.bytes_downloaded < p.bytes_total * 0.999;const title = downloading@@ -718,6 +730,9 @@ const IDLE_PROGRESS: DiffusionLoadProgress = {error: null,};+// What the load toast shows while the backend saves the chat model's context ahead of this load.+const SAVING_PROGRESS: DiffusionLoadProgress = { ...IDLE_PROGRESS, phase: "saving_chat_context" };+// One row: label, track, value. The Images sliders are Chat ParamSlider, so both pages share one// control.function SliderField({@@ -1393,10 +1408,14 @@ function LoadedBuildSummary({ status }: { status: DiffusionStatus | null }) {);}-/** Report a failed load. A refused precision is a long actionable sentence, so it becomes a- * toast description under a short title. Nothing is left half-loaded either way. */-function reportLoadFailure(message: string | null | undefined, fallback: string): void {- const text = (message || "").trim();+/** Report a failed load. A refused precision or a Model memory refusal is a long actionable+ * sentence, so it becomes a toast description under a short title. Nothing is left half-loaded. */+function reportLoadFailure(failure: unknown, fallback: string): void {+ const text = failureMessage(failure).trim();+ if (isMultiModelRefusal(null, refusalHeadersOf(failure), text)) {+ toast.error(MULTI_MODEL_REFUSAL_TITLE, { description: text || fallback, action: modelMemorySettingsAction() });+ return;+ }if (text && isPrecisionRefusal(text)) {toast.error(PRECISION_REFUSAL_TITLE, { description: text });return;@@ -1749,6 +1768,8 @@ export function ImagesPage({const pollTimer = useRef<ReturnType<typeof setTimeout> | null>(null);// The persistent load toast's id, so each poll updates it in place.const loadToastId = useRef<string | number | null>(null);+ // What the load POST unloaded to make room, shown on the "Model loaded" toast it ends with.+ const pendingEvicted = useRef<EvictedSlot[]>([]);// Last load-progress signature shown, so a tick that moved nothing skips the toast.const lastLoadSig = useRef<string | null>(null);// The quant to restore if the optimistic swap fails; `{ prev }` distinguishes "revert to@@ -2911,7 +2932,9 @@ export function ImagesPage({return;}setStatusIfNewest(ticket, loaded);- toast.success("Model loaded");+ const evicted = pendingEvicted.current;+ pendingEvicted.current = [];+ toast.success("Model loaded", evictedToastOptions(evicted));if (lastLoad.current && matchesRememberedModel(lastLoad.current, loaded)) {const remembered = withEngagedFamily(lastLoad.current, loaded);rememberImageModel(remembered);@@ -2940,6 +2963,7 @@ export function ImagesPage({}if (p.phase === "error") {pendingRecalledGeneration.current = null;+ pendingEvicted.current = [];dismissLoadToast();reportLoadFailure(p.error, "Failed to load model");setBusy(null);@@ -2961,6 +2985,7 @@ export function ImagesPage({}if (p.phase === null) {pendingRecalledGeneration.current = null;+ pendingEvicted.current = [];// No load in flight and nothing loaded: the load was cancelled or evicted. Terminal, else this// loop spins forever.dismissLoadToast();@@ -3295,6 +3320,12 @@ export function ImagesPage({setCanReapply(true);// Carry the prior target so the async poll can restore it if the background load fails after starting.lastLoadRevert.current = { prev: prevLastLoad };+ // The POST may first save the chat model's context; show that on this load's toast meanwhile.+ const savePoll = watchSavingPhase(getDiffusionLoadProgress, () => {+ if (startSeq === cancelSeq.current && startLoad === loadSeq.current && loadToastId.current != null) {+ toast(null, loadToastArgs(SAVING_PROGRESS, loadToastId.current, cancelLoadFromToast));+ }+ });try {// Returns immediately; the load runs in the background and we poll. The backend infers the// family and base repo from the id, and the saved HF token covers gated bases.@@ -3319,18 +3350,24 @@ export function ImagesPage({gpu_ids: advanced.gpu_ids,...componentFiles,});- await startRequest;+ const answer = await startRequest;+ pendingEvicted.current = evictedSlotsFrom(answer);+ resyncEvicted(pendingEvicted.current, "image");} catch (err) {+ pendingEvicted.current = [];lastLoad.current = prevLastLoad;setCanReapply(prevLastLoad != null);lastLoadRevert.current = null;dismissLoadToast();- reportLoadFailure(err instanceof Error ? err.message : "", "Failed to start load");+ reportLoadFailure(err, "Failed to start load");setBusy(null);void refreshStatus();return settle(false);+ } finally {+ savePoll.stop();}if (startSeq !== cancelSeq.current) {+ pendingEvicted.current = [];// Cancelled during the start request: the unload it sent may have landed before this load// registered, leaving it running with no toast and no Cancel. The load exists as of this// line, so unload once more, unless a NEWER load has taken the page.diff --git a/studio/frontend/src/features/settings/api/multi-model.ts b/studio/frontend/src/features/settings/api/multi-model.tsindex 746ae6704c1..6164bce98b6 100644--- a/studio/frontend/src/features/settings/api/multi-model.ts+++ b/studio/frontend/src/features/settings/api/multi-model.ts@@ -28,3 +28,48 @@ export async function updateMultiModelEnabled(}return Boolean((await res.json()).enabled);}++export const MULTI_MODEL_MODES = ["off", "fit", "always"] as const;+export type MultiModelMode = (typeof MULTI_MODEL_MODES)[number];++export function isMultiModelMode(value: unknown): value is MultiModelMode {+ return (MULTI_MODEL_MODES as readonly unknown[]).includes(value);+}++/** R1 response {enabled, default_enabled, mode, default_mode}; pre-R1 {enabled, default_enabled}. */+export function normaliseMultiModelMode(json: unknown): MultiModelMode {+ const body = (json ?? {}) as { mode?: unknown; enabled?: unknown };+ if (isMultiModelMode(body.mode)) {+ return body.mode;+ }+ // An older backend, or a mode this build does not know: the bool still decides on or off.+ return body.enabled === true ? "fit" : "off";+}++export const keepsModelsLoaded = (mode: MultiModelMode): boolean =>+ mode !== "off";++export async function loadMultiModelMode(+ fallbackMessage: string,+): Promise<MultiModelMode> {+ const res = await authFetch("/api/settings/multi-model");+ if (!res.ok) {+ throw new Error(await readFastApiError(res, fallbackMessage));+ }+ return normaliseMultiModelMode(await res.json());+}++export async function updateMultiModelMode(+ mode: MultiModelMode,+ fallbackMessage: string,+): Promise<MultiModelMode> {+ const res = await authFetch("/api/settings/multi-model", {+ method: "PUT",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ mode }),+ });+ if (!res.ok) {+ throw new Error(await readFastApiError(res, fallbackMessage));+ }+ return normaliseMultiModelMode(await res.json());+}diff --git a/studio/frontend/src/features/settings/api/openai-auto-switch.ts b/studio/frontend/src/features/settings/api/openai-auto-switch.tsindex ab38e9a771e..5d9f6c0357a 100644--- a/studio/frontend/src/features/settings/api/openai-auto-switch.ts+++ b/studio/frontend/src/features/settings/api/openai-auto-switch.ts@@ -158,9 +158,9 @@ export async function loadOpenAIAutoSwitchSettings() {return settings as OpenAIAutoSwitchSettings;}-/** A partial write: `enabled` is always sent, and an omitted field keeps its stored value. */+/** A partial write: omitted fields, `enabled` included, keep their stored value. */export type OpenAIAutoSwitchUpdate = {- enabled: boolean;+ enabled?: boolean;autoUnloadIdleSeconds?: number;autoUnloadKeepKv?: boolean;autoDownloadModel?: boolean;@@ -182,7 +182,8 @@ const UPDATE_KEYS = {export async function updateOpenAIAutoSwitchSettings(update: OpenAIAutoSwitchUpdate,): Promise<OpenAIAutoSwitchSettings> {- const body: Record<string, unknown> = { enabled: update.enabled };+ const body: Record<string, unknown> = {};+ if (update.enabled !== undefined) body.enabled = update.enabled;for (const [field, key] of Object.entries(UPDATE_KEYS)) {const value = update[field as keyof typeof UPDATE_KEYS];if (value !== undefined) {diff --git a/studio/frontend/src/features/settings/components/model-auto-switch-section.tsx b/studio/frontend/src/features/settings/components/model-auto-switch-section.tsxindex b6850ebddf4..26eafba8fa3 100644--- a/studio/frontend/src/features/settings/components/model-auto-switch-section.tsx+++ b/studio/frontend/src/features/settings/components/model-auto-switch-section.tsx@@ -16,11 +16,23 @@ import { SettingsRow } from "./settings-row";import { SettingsSection } from "./settings-section";// Mirrors MIN_AUTO_UNLOAD_IDLE_SECONDS in the backend settings store.-const MIN_IDLE_SECONDS = 60;+export const MIN_IDLE_SECONDS = 60;-// Its own row so the section keeps one job per control: this TTL has no enable-// toggle in front of it, unlike the chat one above.-function MediaIdleUnloadRow({+// Parse an idle-seconds draft: 0 (off) or >= MIN_IDLE_SECONDS; else null.+export const parseIdleSeconds = (draft: string): number | null => {+ if (!draft.trim()) {+ return null;+ }+ const parsed = Number(draft);+ if (!Number.isInteger(parsed)) {+ return null;+ }+ return parsed === 0 || parsed >= MIN_IDLE_SECONDS ? parsed : null;+};++// The image/video TTL, shown under Model memory: no enable toggle gates it, so+// it lives beside the other memory settings rather than the chat TTL.+export function MediaIdleUnloadRow({draftSeconds,onDraftChange,onSave,@@ -47,9 +59,7 @@ function MediaIdleUnloadRow({return (<SettingsRowlabel={t("settings.general.modelAutoSwitch.mediaIdleUnload")}- description={t(- "settings.general.modelAutoSwitch.mediaIdleUnloadDescription",- )}+ description={t("settings.resources.modelMemory.mediaIdleUnloadDescription")}below={error ? (<span className="max-w-[calc(260px*var(--ui-space-scale,1))] text-right text-xs text-destructive">@@ -91,26 +101,27 @@ function MediaIdleUnloadRow({);}-export function ModelAutoSwitchSection() {+// Saves the media TTL alone, with no `enabled`, so a stale chat toggle is never+// written back. Re-reads when residency changes: that decides the paused note.+export function MediaIdleUnloadSetting({+ residencyKey,+}: { residencyKey?: unknown }) {const t = useT();const [settings, setSettings] = useState<OpenAIAutoSwitchSettings | null>(null,);- const [draftIdleSeconds, setDraftIdleSeconds] = useState("0");- const [draftMediaIdleSeconds, setDraftMediaIdleSeconds] = useState("0");+ const [draft, setDraft] = useState("0");const [error, setError] = useState<string | null>(null);- // The media row validates its own input, so its message belongs beside it.- const [mediaError, setMediaError] = useState<string | null>(null);const [isSaving, setIsSaving] = useState(false);+ // biome-ignore lint/correctness/useExhaustiveDependencies: residencyKey only triggers the re-readuseEffect(() => {let cancelled = false;void loadOpenAIAutoSwitchSettings().then((loaded) => {if (cancelled) return;setSettings(loaded);- setDraftIdleSeconds(String(loaded.autoUnloadIdleSeconds));- setDraftMediaIdleSeconds(String(loaded.mediaAutoUnloadIdleSeconds));+ setDraft(String(loaded.mediaAutoUnloadIdleSeconds));setError(null);}).catch((loadError) => {@@ -124,20 +135,76 @@ export function ModelAutoSwitchSection() {return () => {cancelled = true;};- }, [t]);+ }, [t, residencyKey]);- // Parse an idle-seconds draft: 0 (off) or >= MIN_IDLE_SECONDS; else null.- const parseIdleSeconds = (draft: string): number | null => {- if (!draft.trim()) {- return null;+ const handleSave = async () => {+ const mediaAutoUnloadIdleSeconds = parseIdleSeconds(draft);+ if (mediaAutoUnloadIdleSeconds === null) {+ setError(t("settings.general.modelAutoSwitch.idleError"));+ return;}- const parsed = Number(draft);- if (!Number.isInteger(parsed)) {- return null;+ setIsSaving(true);+ setError(null);+ try {+ const saved = await updateOpenAIAutoSwitchSettings({+ mediaAutoUnloadIdleSeconds,+ });+ setSettings(saved);+ setDraft(String(saved.mediaAutoUnloadIdleSeconds));+ } catch (saveError) {+ setError(+ saveError instanceof Error+ ? saveError.message+ : t("settings.general.modelAutoSwitch.saveError"),+ );+ } finally {+ setIsSaving(false);}- return parsed === 0 || parsed >= MIN_IDLE_SECONDS ? parsed : null;};+ return (+ <MediaIdleUnloadRow+ draftSeconds={draft}+ onDraftChange={setDraft}+ onSave={() => void handleSave()}+ settings={settings}+ isSaving={isSaving}+ error={error}+ />+ );+}++export function ModelAutoSwitchSection() {+ const t = useT();+ const [settings, setSettings] = useState<OpenAIAutoSwitchSettings | null>(+ null,+ );+ const [draftIdleSeconds, setDraftIdleSeconds] = useState("0");+ const [error, setError] = useState<string | null>(null);+ const [isSaving, setIsSaving] = useState(false);++ useEffect(() => {+ let cancelled = false;+ void loadOpenAIAutoSwitchSettings()+ .then((loaded) => {+ if (cancelled) return;+ setSettings(loaded);+ setDraftIdleSeconds(String(loaded.autoUnloadIdleSeconds));+ setError(null);+ })+ .catch((loadError) => {+ if (cancelled) return;+ setError(+ loadError instanceof Error+ ? loadError.message+ : t("settings.general.modelAutoSwitch.loadError"),+ );+ });+ return () => {+ cancelled = true;+ };+ }, [t]);+// syncDraft only for a write the chat idle-seconds input owns; every other row// leaves that draft alone so a save elsewhere cannot discard what is typed there.const persist = async (@@ -149,9 +216,6 @@ export function ModelAutoSwitchSection() {try {const saved = await updateOpenAIAutoSwitchSettings(update);setSettings(saved);- if (update.mediaAutoUnloadIdleSeconds !== undefined) {- setDraftMediaIdleSeconds(String(saved.mediaAutoUnloadIdleSeconds));- }if (syncDraft) {setDraftIdleSeconds(String(saved.autoUnloadIdleSeconds));}@@ -198,23 +262,6 @@ export function ModelAutoSwitchSection() {);};- // The image/video TTL is its own setting, so it saves on its own: no enable- // toggle gates it, and the chat seconds are left untouched.- const handleSaveMediaIdle = () => {- if (!settings) return;- const mediaIdleSeconds = parseIdleSeconds(draftMediaIdleSeconds);- setMediaError(- mediaIdleSeconds === null- ? t("settings.general.modelAutoSwitch.idleError")- : null,- );- if (mediaIdleSeconds === null) return;- void persist({- enabled: settings.enabled,- mediaAutoUnloadIdleSeconds: mediaIdleSeconds,- });- };-const handleKeepKvToggle = (keepKv: boolean) => {if (!settings) return;void persist({ enabled: settings.enabled, autoUnloadKeepKv: keepKv });@@ -325,26 +372,18 @@ export function ModelAutoSwitchSection() {onCheckedChange={handleMediaAutoSwitchToggle}/></SettingsRow>- <MediaIdleUnloadRow- draftSeconds={draftMediaIdleSeconds}- onDraftChange={setDraftMediaIdleSeconds}- onSave={handleSaveMediaIdle}- settings={settings}- isSaving={isSaving}- error={mediaError}- />- {settings?.idleUnloadActive ? (- <SettingsRow- label={t("settings.general.modelAutoSwitch.keepKv")}- description={t("settings.general.modelAutoSwitch.keepKvDescription")}- >- <Switch- checked={settings.autoUnloadKeepKv}- disabled={isSaving}- onCheckedChange={handleKeepKvToggle}- />- </SettingsRow>- ) : null}+ {/* Ungated: the KV save also runs before an image or video model takes the GPU. */}+ <SettingsRow+ label={t("settings.general.modelAutoSwitch.keepKv")}+ description={t("settings.general.modelAutoSwitch.keepKvDescription")}+ >+ <Switch+ aria-label={t("settings.general.modelAutoSwitch.keepKv")}+ checked={settings?.autoUnloadKeepKv ?? true}+ disabled={!settings || isSaving}+ onCheckedChange={handleKeepKvToggle}+ />+ </SettingsRow>{/* Also whenever a media TTL is saved: this switch decides which media models thatTTL may free, so it has to be reachable without re-enabling chat unloading first. */}{settings &&diff --git a/studio/frontend/src/features/settings/components/model-memory-section.tsx b/studio/frontend/src/features/settings/components/model-memory-section.tsxindex 3bef4a9c212..f2bedfce7e2 100644--- a/studio/frontend/src/features/settings/components/model-memory-section.tsx+++ b/studio/frontend/src/features/settings/components/model-memory-section.tsx@@ -1,21 +1,32 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";import { Switch } from "@/components/ui/switch";import { useChatRuntimeStore } from "@/features/chat";import { formatBytes } from "@/features/hub/lib/format";import { useT } from "@/i18n";import { subscribeModelLifecycle } from "@/lib/model-lifecycle-events";-import { useEffect, useRef, useState } from "react";+import { type Ref, useEffect, useRef, useState } from "react";import {type ModelMemorySettings,loadModelMemorySettings,updateModelMemorySettings,} from "../api/model-memory";import {- loadMultiModelEnabled,- updateMultiModelEnabled,+ type MultiModelMode,+ isMultiModelMode,+ keepsModelsLoaded,+ loadMultiModelMode,+ updateMultiModelMode,} from "../api/multi-model";+import { MediaIdleUnloadSetting } from "./model-auto-switch-section";import { SettingsRow } from "./settings-row";import { SettingsSection } from "./settings-section";@@ -59,23 +70,35 @@ async function refreshModelMemory(}}-export function ModelMemorySection() {+const MULTI_MODEL_DESCRIPTION = {+ off: "settings.resources.modelMemory.multiModelDescription",+ fit: "settings.resources.modelMemory.multiModelDescriptionFit",+ always: "settings.resources.modelMemory.multiModelDescriptionAlways",+} as const;++export function ModelMemorySection({ ref }: { ref?: Ref<HTMLElement> }) {const t = useT();const [settings, setSettings] = useState<ModelMemorySettings | null>(null);const [error, setError] = useState<string | null>(null);const [isSaving, setIsSaving] = useState(false);// Bumped by every refresh and save: a read that resolves after either no longer describes the panel.const latestRef = useRef(0);- const multiModel = useChatRuntimeStore((s) => s.keepModelsLoaded);+ // Seeded from the chat store so the description does not flash before the read.+ const [mode, setMode] = useState<MultiModelMode>(() =>+ useChatRuntimeStore.getState().keepModelsLoaded ? "fit" : "off",+ );const [multiModelRead, setMultiModelRead] = useState(false);const [isSavingMultiModel, setIsSavingMultiModel] = useState(false);useEffect(() => {let cancelled = false;- loadMultiModelEnabled(t("settings.resources.modelMemory.loadError")).then(- (enabled) => {+ loadMultiModelMode(t("settings.resources.modelMemory.loadError")).then(+ (loaded) => {if (!cancelled) {- useChatRuntimeStore.getState().setKeepModelsLoaded(enabled);+ setMode(loaded);+ useChatRuntimeStore+ .getState()+ .setKeepModelsLoaded(keepsModelsLoaded(loaded));setMultiModelRead(true);}},@@ -94,18 +117,18 @@ export function ModelMemorySection() {};}, [t]);- const persistMultiModel = async (enabled: boolean) => {+ const persistMultiModel = async (next: MultiModelMode) => {setIsSavingMultiModel(true);setError(null);try {+ const saved = await updateMultiModelMode(+ next,+ t("settings.resources.modelMemory.saveError"),+ );+ setMode(saved);useChatRuntimeStore.getState()- .setKeepModelsLoaded(- await updateMultiModelEnabled(- enabled,- t("settings.resources.modelMemory.saveError"),- ),- );+ .setKeepModelsLoaded(keepsModelsLoaded(saved));} catch (saveError) {setError(saveError instanceof Error@@ -172,7 +195,7 @@ export function ModelMemorySection() {: null;return (- <SettingsSection title={t("settings.resources.modelMemory.title")}>+ <SettingsSection title={t("settings.resources.modelMemory.title")} ref={ref}><SettingsRowlabel={t("settings.resources.modelMemory.keepResident")}description={t(@@ -203,15 +226,38 @@ export function ModelMemorySection() {</SettingsRow><SettingsRowlabel={t("settings.resources.modelMemory.multiModel")}- description={t("settings.resources.modelMemory.multiModelDescription")}+ description={t(MULTI_MODEL_DESCRIPTION[mode])}hint={t("settings.resources.modelMemory.multiModelHint")}>- <Switch- aria-label={t("settings.resources.modelMemory.multiModel")}- checked={multiModel}+ <Select+ value={mode}disabled={!multiModelRead || isSavingMultiModel}- onCheckedChange={(enabled) => void persistMultiModel(enabled)}- />+ onValueChange={(next) => {+ if (isMultiModelMode(next)) {+ void persistMultiModel(next);+ }+ }}+ >+ <SelectTrigger+ aria-label={t("settings.resources.modelMemory.multiModel")}+ className="w-48"+ size="sm"+ data-testid="multi-model-mode-select"+ >+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="off">+ {t("settings.resources.modelMemory.multiModelOff")}+ </SelectItem>+ <SelectItem value="fit">+ {t("settings.resources.modelMemory.multiModelFit")}+ </SelectItem>+ <SelectItem value="always">+ {t("settings.resources.modelMemory.multiModelAlways")}+ </SelectItem>+ </SelectContent>+ </Select></SettingsRow>{error ? (<p className="pb-3 text-xs text-destructive">{error}</p>@@ -237,6 +283,7 @@ export function ModelMemorySection() {) : null}</>)}+ <MediaIdleUnloadSetting residencyKey={settings?.keepResident} /></SettingsSection>);}diff --git a/studio/frontend/src/features/settings/lib/model-memory-action.ts b/studio/frontend/src/features/settings/lib/model-memory-action.tsnew file mode 100644index 00000000000..6c67545133f--- /dev/null+++ b/studio/frontend/src/features/settings/lib/model-memory-action.ts@@ -0,0 +1,19 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import { isAccountOwner } from "@/features/auth/account-session";+import { useSettingsDialogStore } from "../stores/settings-dialog-store";++/** "Open settings" on a load refused by Model memory. Owner only: Resources is an owner tab. */+export function modelMemorySettingsAction():+ | { label: string; onClick: () => void }+ | undefined {+ if (!isAccountOwner()) return undefined;+ return {+ label: "Open settings",+ onClick: () =>+ useSettingsDialogStore+ .getState()+ .openDialog("resources", { scrollTarget: "resources-model-memory" }),+ };+}diff --git a/studio/frontend/src/features/settings/settings-search.ts b/studio/frontend/src/features/settings/settings-search.tsindex 39703f069a5..e1cba31b38f 100644--- a/studio/frontend/src/features/settings/settings-search.ts+++ b/studio/frontend/src/features/settings/settings-search.ts@@ -99,6 +99,8 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {"settings.resources.modelMemory.title","settings.resources.modelMemory.keepResident","settings.resources.modelMemory.noRamReserve",+ "settings.resources.modelMemory.multiModel",+ "settings.general.modelAutoSwitch.mediaIdleUnload","settings.resources.storage.title","settings.resources.storage.modelsFolder","settings.resources.storage.futureDownloads",@@ -230,6 +232,7 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {"settings.apiKeys.audioApi.title","settings.apiKeys.decisionApi.title","settings.apiKeys.mcp.title",+ "settings.general.modelAutoSwitch.keepKv",],// the English card labels cannot match localized keys, so the header carries both entries."remote-lan": ["settings.remoteLan.title", "settings.remoteLan.description"],@@ -398,6 +401,7 @@ const OWNER_ONLY_ENTRIES: ReadonlySet<TranslationKey> = new Set(["settings.sandbox.python","settings.sandbox.terminal","settings.apiKeys.mcp.title",+ "settings.general.modelAutoSwitch.keepKv","settings.chat.toolResultLimit","settings.chat.firstTokenLabel",]);@@ -437,6 +441,13 @@ export const SETTINGS_SEARCH_KEYWORDS: Partial<"settings.resources.modelMemory.modelMemoryKeywords","settings.resources.modelMemory.noRamReserve":"settings.resources.modelMemory.modelMemoryKeywords",+ // match swap, fit, evict and the model kinds the multi-model labels omit.+ "settings.resources.modelMemory.multiModel":+ "settings.resources.modelMemory.multiModelKeywords",+ "settings.general.modelAutoSwitch.mediaIdleUnload":+ "settings.resources.modelMemory.mediaIdleUnloadKeywords",+ "settings.general.modelAutoSwitch.keepKv":+ "settings.general.modelAutoSwitch.keepKvKeywords","settings.chat.autoCompact": "settings.chat.autoCompactKeywords","settings.chat.keepRunningWhenTabClosed":"settings.chat.keepRunningWhenTabClosedKeywords",diff --git a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts b/studio/frontend/src/features/settings/stores/settings-dialog-store.tsindex b9573bc49a2..93961dc13e3 100644--- a/studio/frontend/src/features/settings/stores/settings-dialog-store.ts+++ b/studio/frontend/src/features/settings/stores/settings-dialog-store.ts@@ -43,6 +43,7 @@ export type SettingsScrollTarget =| "general-permissions"| "library-storage"| "resources-caches"+ | "resources-model-memory"| "sandbox-os"| "sandbox-permissions";@@ -169,6 +170,7 @@ const SCROLL_TARGET_TAB: Record<SettingsScrollTarget, SettingsTab> = {"general-permissions": "sandbox","library-storage": "library","resources-caches": "resources",+ "resources-model-memory": "resources","sandbox-os": "sandbox","sandbox-permissions": "sandbox",};diff --git a/studio/frontend/src/features/settings/tabs/resources-tab.tsx b/studio/frontend/src/features/settings/tabs/resources-tab.tsxindex ef80adefb07..8af18607592 100644--- a/studio/frontend/src/features/settings/tabs/resources-tab.tsx+++ b/studio/frontend/src/features/settings/tabs/resources-tab.tsx@@ -292,6 +292,7 @@ export function ResourcesTab() {pollMs: liveUpdates ? POLL_MS : undefined,});const storageSectionRef = useRef<HTMLElement | null>(null);+ const modelMemoryRef = useRef<HTMLElement | null>(null);const scrollTarget = useSettingsDialogStore((s) => s.scrollTarget);const consumeScrollTarget = useSettingsDialogStore((s) => s.consumeScrollTarget,@@ -338,13 +339,20 @@ export function ResourcesTab() {}, []);useEffect(() => {- if (scrollTarget !== "resources-caches") return;+ const target = scrollTarget;+ const sectionRef =+ target === "resources-caches"+ ? storageSectionRef+ : target === "resources-model-memory"+ ? modelMemoryRef+ : null;+ if (!target || !sectionRef) return;const frame = window.requestAnimationFrame(() => {- storageSectionRef.current?.scrollIntoView({+ sectionRef.current?.scrollIntoView({block: "start",behavior: "smooth",});- consumeScrollTarget("resources-caches");+ consumeScrollTarget(target);});return () => window.cancelAnimationFrame(frame);}, [consumeScrollTarget, scrollTarget]);@@ -1045,7 +1053,7 @@ export function ResourcesTab() {<LlamaBackendSection /><InferenceEnginesSection />- <ModelMemorySection />+ <ModelMemorySection ref={modelMemoryRef} /><SettingsSectionref={storageSectionRef}diff --git a/studio/frontend/src/features/video/api.ts b/studio/frontend/src/features/video/api.tsindex 542e2893c9a..5a5092f74a3 100644--- a/studio/frontend/src/features/video/api.ts+++ b/studio/frontend/src/features/video/api.ts@@ -7,6 +7,7 @@ import { authFetch } from "@/features/auth";import type { DiffusionDownloadPlan } from "@/features/images/api";import { apiUrl } from "@/lib/api-base";import { readFastApiError } from "@/lib/format-fastapi-error";+import { parseLoadJson } from "@/lib/multi-model-refusal";// One Advanced control's resolved value plus provenance, same shape as the diffusion status.// `value` is engaged, `requested` is what the caller asked for (null = left to the backend),@@ -133,7 +134,13 @@ export interface VideoGenerateProgress {}export interface VideoLoadProgress {- phase: "downloading" | "finalizing" | "ready" | "error" | null;+ phase:+ | "downloading"+ | "finalizing"+ | "saving_chat_context"+ | "ready"+ | "error"+ | null;downloaded_bytes: number;// null when the total isn't known yet.expected_bytes?: number | null;@@ -301,7 +308,7 @@ export async function loadVideoModel(body: VideoLoadRequest): Promise<VideoStatu"video",body.model_path,async () =>- parseJson<VideoStatus>(+ parseLoadJson<VideoStatus>(await authFetch("/api/inference/video/load", {method: "POST",headers: { "Content-Type": "application/json" },diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsxindex f5f2e464695..e68795c1794 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -193,6 +193,10 @@ import {isDownloadCancelled,} from "@/lib/native-files";import { toast } from "@/lib/toast";+import { evictedSlotsFrom, evictedToastOptions, resyncEvicted, type EvictedSlot } from "@/lib/evicted-toast";+import { failureMessage, isMultiModelRefusal, MULTI_MODEL_REFUSAL_TITLE, refusalHeadersOf } from "@/lib/multi-model-refusal";+import { watchSavingPhase } from "@/lib/swap-save-phase";+import { modelMemorySettingsAction } from "@/features/settings/lib/model-memory-action";import { loadGalleryUntil } from "@/lib/gallery-deep-link";import { subscribeModelEjected } from "@/lib/model-lifecycle-events";import { BlobUrlCache } from "@/lib/blob-url-cache";@@ -471,6 +475,14 @@ function loadFraction(p: VideoLoadProgress): number | null {}function loadToastDescription(p: VideoLoadProgress) {+ if (p.phase === "saving_chat_context") {+ return (+ <ModelLoadDescription+ title="Saving chat context…"+ message="Saving the chat model's context so it can resume after this load."+ />+ );+ }const frac = loadFraction(p);const downloading =p.phase === "downloading" && (frac === null || frac < 0.999);@@ -520,6 +532,9 @@ const IDLE_PROGRESS: VideoLoadProgress = {error: null,};+// What the load toast shows while the backend saves the chat model's context ahead of this load.+const SAVING_PROGRESS: VideoLoadProgress = { ...IDLE_PROGRESS, phase: "saving_chat_context" };+// Chat's slider, shared with Create. Signature kept for the call sites below.function SliderField({label,@@ -675,10 +690,14 @@ function LoadedBuildSummary({ status }: { status: VideoStatus | null }) {);}-/** Report a failed load. A refused precision is a long actionable sentence, so it becomes a- * toast description under a short title. Mirrors the images page. */-function reportLoadFailure(message: string | null | undefined, fallback: string): void {- const text = (message || "").trim();+/** Report a failed load. A refused precision or a Model memory refusal is a long actionable+ * sentence, so it becomes a toast description under a short title. Mirrors the images page. */+function reportLoadFailure(failure: unknown, fallback: string): void {+ const text = failureMessage(failure).trim();+ if (isMultiModelRefusal(null, refusalHeadersOf(failure), text)) {+ toast.error(MULTI_MODEL_REFUSAL_TITLE, { description: text || fallback, action: modelMemorySettingsAction() });+ return;+ }if (text && isPrecisionRefusal(text)) {toast.error(PRECISION_REFUSAL_TITLE, { description: text });return;@@ -1193,6 +1212,8 @@ function VideoGenerator({const pollTimer = useRef<ReturnType<typeof setTimeout> | null>(null);// The persistent load toast's id, so each poll updates it in place.const loadToastId = useRef<string | number | null>(null);+ // What the load POST unloaded to make room, shown on the "Model loaded" toast it ends with.+ const pendingEvicted = useRef<EvictedSlot[]>([]);// Last load-progress signature shown, so a tick that moved nothing skips the toast.const lastLoadSig = useRef<string | null>(null);// The quant to restore if the current optimistic swap fails. A pick also applies its own@@ -2405,7 +2426,9 @@ function VideoGenerator({return;}setStatusIfNewest(ticket, loaded);- toast.success("Model loaded");+ const evicted = pendingEvicted.current;+ pendingEvicted.current = [];+ toast.success("Model loaded", evictedToastOptions(evicted));setBusy(null);quantRevert.current?.commitRecipeClaim?.();quantRevert.current = null;@@ -2414,6 +2437,7 @@ function VideoGenerator({return;}if (p.phase === "error") {+ pendingEvicted.current = [];dismissLoadToast();reportLoadFailure(p.error, "Failed to load model");setBusy(null);@@ -2431,6 +2455,7 @@ function VideoGenerator({return;}if (p.phase === null) {+ pendingEvicted.current = [];// No load in flight and nothing loaded: the load was cancelled or evicted. Terminal, else this// loop spins forever.dismissLoadToast();@@ -2704,6 +2729,12 @@ function VideoGenerator({setCanReapply(true);// Carry the prior target so the async poll can restore it if the background load fails after starting.lastLoadRevert.current = { prev: prevLastLoad, canReapply: prevCanReapply };+ // The POST may first save the chat model's context; show that on this load's toast meanwhile.+ const savePoll = watchSavingPhase(getVideoLoadProgress, () => {+ if (startSeq === cancelSeq.current && startLoad === loadSeq.current && loadToastId.current != null) {+ toast(null, loadToastArgs(SAVING_PROGRESS, loadToastId.current, cancelLoadFromToast));+ }+ });try {// Returns immediately; the load runs in the background and we poll.const startRequest = loadVideoModel({@@ -2723,18 +2754,24 @@ function VideoGenerator({h3_task: opts.h3Task,gpu_ids: advanced.gpu_ids,});- await startRequest;+ const answer = await startRequest;+ pendingEvicted.current = evictedSlotsFrom(answer);+ resyncEvicted(pendingEvicted.current, "video");} catch (err) {+ pendingEvicted.current = [];lastLoad.current = prevLastLoad;setCanReapply(prevCanReapply);lastLoadRevert.current = null;dismissLoadToast();- reportLoadFailure(err instanceof Error ? err.message : "", "Failed to start load");+ reportLoadFailure(err, "Failed to start load");setBusy(null);void refreshStatus();return settle(false);+ } finally {+ savePoll.stop();}if (startSeq !== cancelSeq.current) {+ pendingEvicted.current = [];// Cancelled during the start request: the unload it sent may have landed before this load// registered, leaving it running with no toast and no Cancel. The load exists as of this// line, so unload once more, unless a NEWER load has taken the page.diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex 338a4c6fb1a..01dcaa5017b 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -1730,9 +1730,10 @@ export const ar = {autoDownload: "تنزيل النماذج غير المنزَّلة",autoDownloadDescription:"يجلب ملف GGUF المذكور في طلب واجهة API إذا لم يكن منزَّلًا بعد. عندئذٍ يمكن لأي شخص لديه مفتاح API استهلاك مساحة القرص وعرض النطاق.",- keepKv: "الاحتفاظ بسياق المحادثة عند التفريغ التلقائي بسبب الخمول",+ keepKv: "الاحتفاظ بسياق المحادثة عبر عمليات التفريغ",keepKvDescription:- "يحفظ ذاكرة KV المؤقتة قبل التفريغ التلقائي عند الخمول، حتى لا تعيد المحادثات المستأنفة قراءة السجل. بحد أقصى 10 جيجابايت على القرص.",+ "يحفظ ذاكرة KV المؤقتة قبل التفريغ التلقائي عند الخمول، أو قبل أن يشغل نموذج صور أو فيديو كرت الرسوميات، حتى لا تعيد المحادثات المستأنفة قراءة السجل. بحد أقصى 10 جيجابايت على القرص.",+ keepKvKeywords: "kv ذاكرة مؤقتة سياق تبديل استئناف صور فيديو",apiOnly: "تفريغ النماذج التي حمّلتها واجهة API فقط",apiOnlyDescription:"يُبقي التفريغ التلقائي عند الخمول النموذج الذي حمّلته من Unsloth في الذاكرة، ولا يفرّغ سوى النماذج التي حمّلها طلب عبر واجهة API.",@@ -2353,8 +2354,17 @@ export const ar = {noRamReserveDescription: "يقلل ذاكرة النظام المحجوزة لأوزان النموذج.",noRamReserveHint: "يتخطى التحميل المعتمد على تعيين الذاكرة في إصدارات ويندوز المدعومة عندما يكون النموذج محمّلاً بالكامل على كرت الرسوميات، فلا تبقى صفحاته مقيمة. وإلا يُبقي التحميل المعتمد على تعيين الذاكرة. قد تستهلك مخازن المعالج المطلوبة ذاكرة النظام. ويحذف --no-mmap و--mlock.",multiModel: "إبقاء عدة نماذج محمّلة",- multiModelDescription: "عند تحميل نموذج تبقى النماذج الأخرى في الذاكرة.",- multiModelHint: "يجيب كل نموذج محمّل عن الطلبات التي تذكره بالاسم. مع عدة كروت رسوميات، يوضع النموذج الجديد على كرت لا يستخدمه نموذج آخر إن كان فيه متسع. وإن لم يتسع بجانب النماذج الأخرى، تُزال أولًا النماذج غير المستخدمة، ثم يحل محل النموذج النشط. ويزيل التدريب النماذج الإضافية قبل النموذج النشط.",+ multiModelOff: "إيقاف",+ multiModelFit: "عندما تتسع",+ multiModelAlways: "دائمًا",+ multiModelDescription: "عند تحميل نموذج محادثة أو صور أو فيديو تُفرَّغ النماذج الأخرى.",+ multiModelDescriptionFit:+ "عند تحميل نموذج تبقى النماذج الأخرى إن اتسعت لها الذاكرة. وإن لم تتسع، تُفرَّغ أولًا النماذج غير المستخدمة، ثم النموذج النشط.",+ multiModelDescriptionAlways:+ "لا يفرّغ تحميل نموذج أي نموذج آخر أبدًا. النموذج الذي لا يتسع لا يُحمَّل. ولا يزال التفريغ التلقائي عند الخمول والتدريب يحرّران الذاكرة.",+ multiModelHint: "يشمل نماذج المحادثة والصور والفيديو. يجيب كل نموذج محادثة محمّل عن الطلبات التي تذكره بالاسم. مع عدة كروت رسوميات، يحاول Unsloth وضع النموذج الجديد على كرت لا يستخدمه نموذج آخر. يترك خيار «عندما تتسع» نحو 1 جيجابايت فارغة. ولا يفرّغ الخياران «عندما تتسع» و«دائمًا» أبدًا نموذجًا على كرت آخر.",+ mediaIdleUnloadDescription:+ "حرّر ذاكرة VRAM بتفريغ نموذجَي الصور والفيديو بعد هذا العدد من ثواني الخمول. تُبقي القيمة 0 النموذجين محمَّلين، والحد الأدنى 60 ثانية.",mlockVetoed: "يبقى --mlock معطَّلاً: تثبيت النموذج سيحجز ذاكرة تكفي حجمه كاملاً. ولا يزال التفريغ التلقائي عند الخمول معطَّلاً.",mlockNotApplicable: "بالكامل على وحدة GPU: لا شيء في ذاكرة النظام لقفله. يبقى التفريغ التلقائي عند الخمول معطَّلاً.",memlockCapped: "يحدّ هذا النظام الذاكرة المقفلة عند {limit}. لن يُثبَّت نموذج أكبر بالكامل؛ ارفع الحد باستخدام ulimit -l.",@@ -2364,6 +2374,10 @@ export const ar = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu ذاكرة رام مقيم تثبيت قفل إبقاء محمل تفريغ خامل mmap no-mmap load-mode تبديل ترحيل",+ multiModelKeywords:+ "عدة نماذج متعددة معًا تبديل تتسع تفريغ إخلاء vram gpu صور فيديو محادثة دائمًا خامل",+ mediaIdleUnloadKeywords:+ "صور فيديو انتشار خامل تفريغ ttl مهلة ثواني تحرير vram gpu ذاكرة",},storage: {title: "التخزين",diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex 91fc268038e..afec35e6200 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -1747,9 +1747,10 @@ export const de = {autoDownload: "Fehlende Modelle herunterladen",autoDownloadDescription:"Lädt ein in einer API-Anfrage genanntes GGUF herunter, das noch nicht vorhanden ist. Wer einen API-Schlüssel hat, kann dann Speicherplatz und Bandbreite verbrauchen.",- keepKv: "Chat-Kontext beim automatischen Entladen behalten",+ keepKv: "Chat-Kontext über Entladungen hinweg behalten",keepKvDescription:- "Speichert den KV-Cache vor dem Entladen bei Inaktivität, damit der Verlauf bei fortgesetzten Chats nicht erneut eingelesen werden muss. Bis zu 10 GB auf der Festplatte.",+ "Speichert den KV-Cache vor dem Entladen bei Inaktivität oder bevor ein Bild- oder Videomodell die GPU übernimmt, damit der Verlauf bei fortgesetzten Chats nicht erneut eingelesen werden muss. Bis zu 10 GB auf der Festplatte.",+ keepKvKeywords: "kv cache kontext wechsel fortsetzen bild video",apiOnly: "Nur über die API geladene Modelle entladen",apiOnlyDescription:"Das automatische Entladen bei Inaktivität lässt ein von dir in Unsloth geladenes Modell im Speicher und gibt nur solche frei, die eine API-Anfrage geladen hat.",@@ -2384,8 +2385,17 @@ export const de = {noRamReserveDescription: "Weniger RAM für die Modellgewichte belegen.",noRamReserveHint: "Überspringt auf unterstützten Windows-Builds das speicherabgebildete Laden, wenn das Modell vollständig auf die GPU ausgelagert ist, sodass dessen Seiten nicht im Speicher gehalten werden. Andernfalls bleibt das speicherabgebildete Laden erhalten. Erforderliche CPU-Puffer können weiterhin RAM belegen. Entfernt --no-mmap und --mlock.",multiModel: "Mehrere Modelle geladen lassen",- multiModelDescription: "Beim Laden eines Modells bleiben die anderen im Speicher.",- multiModelHint: "Jedes geladene Modell beantwortet die Anfragen, die es nennen. Bei mehreren GPUs kommt ein neues Modell auf eine GPU, die kein anderes Modell nutzt, sofern dort Platz ist. Passt es nicht neben die anderen, werden zuerst die nicht genutzten Modelle entladen, danach ersetzt es das aktive Modell. Training entlädt die zusätzlichen Modelle vor dem aktiven.",+ multiModelOff: "Aus",+ multiModelFit: "Wenn sie passen",+ multiModelAlways: "Immer",+ multiModelDescription: "Beim Laden eines Chat-, Bild- oder Videomodells werden die anderen entladen.",+ multiModelDescriptionFit:+ "Beim Laden eines Modells bleiben die anderen geladen, wenn sie passen. Wenn nicht, werden zuerst die nicht genutzten entladen, danach das aktive.",+ multiModelDescriptionAlways:+ "Beim Laden eines Modells wird nie ein anderes entladen. Ein Modell, das nicht passt, wird nicht geladen. Das automatische Entladen im Leerlauf und das Training geben weiterhin Speicher frei.",+ multiModelHint: "Gilt für Chat-, Bild- und Videomodelle. Jedes geladene Chat-Modell beantwortet die Anfragen, die es nennen. Bei mehreren GPUs versucht Unsloth, ein neues Modell auf eine GPU zu legen, die kein anderes Modell nutzt. „Wenn sie passen“ lässt etwa 1 GB frei. „Wenn sie passen“ und „Immer“ entladen nie ein Modell auf einer anderen GPU.",+ mediaIdleUnloadDescription:+ "Gibt VRAM frei, indem die Bild- und Videomodelle nach der angegebenen Anzahl von Sekunden ohne Aktivität entladen werden. Bei 0 bleiben sie geladen; der Mindestwert ist 60.",mlockVetoed: "--mlock bleibt aus: das Fixieren des Modells würde RAM für das gesamte Modell reservieren. Das automatische Entladen im Leerlauf bleibt deaktiviert.",mlockNotApplicable: "Vollständig auf der GPU: nichts im System-RAM zu sperren. Automatisches Entladen im Leerlauf bleibt aus.",memlockCapped: "Dieses System begrenzt gesperrten Speicher auf {limit}. Ein größeres Modell wird nicht vollständig fixiert; erhöhen Sie das Limit mit ulimit -l.",@@ -2395,6 +2405,10 @@ export const de = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu speicher arbeitsspeicher ram resident anheften fixieren sperren geladen halten entladen leerlauf mmap no-mmap load-mode auslagern",+ multiModelKeywords:+ "mehrere modelle gleichzeitig zusammen nebeneinander wechseln passen entladen verdrängen vram gpu bild video chat immer leerlauf",+ mediaIdleUnloadKeywords:+ "bild video diffusion leerlauf entladen ttl timeout sekunden freigeben vram gpu speicher",},storage: {title: "Speicher",diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 85f2aac0bc2..ceea9374525 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -1781,9 +1781,10 @@ export const en = {loadError: "Failed to load model auto-switch settings.",saveError: "Failed to save model auto-switch settings.",idleError: "Enter 0 to keep the model loaded, or at least 60 seconds.",- keepKv: "Keep chat context across idle unload",+ keepKv: "Keep chat context across unloads",keepKvDescription:- "Save the KV cache before an idle unload so resumed chats skip re-reading history. Up to 10 GB on disk.",+ "Save the KV cache before an idle unload, or before an image or video model takes the GPU, so resumed chats skip re-reading history. Up to 10 GB on disk.",+ keepKvKeywords: "kv cache context swap resume image video",apiOnly: "Only unload models loaded by the API",apiOnlyDescription:"Idle unload leaves a model you loaded from Unsloth in memory, and frees only the ones an API request loaded.",@@ -2406,8 +2407,17 @@ export const en = {noRamReserveDescription: "Reduce host RAM held for model weights.",noRamReserveHint: "Skips memory-mapped loading on supported Windows builds when the model is fully offloaded to the GPU, so its pages are not held resident. Otherwise keeps memory-mapped loading. Required CPU buffers can still use RAM. Drops --no-mmap and --mlock.",multiModel: "Keep multiple models loaded",- multiModelDescription: "Loading a model keeps the others in memory.",- multiModelHint: "Each loaded model answers the requests that name it. With several GPUs, a new model goes to a GPU no other model uses when one has room. When it does not fit beside the others, the models not in use are unloaded first, then it replaces the active model. Training unloads the extra models before the active one.",+ multiModelOff: "Off",+ multiModelFit: "When they fit",+ multiModelAlways: "Always",+ multiModelDescription: "Loading a chat, image or video model unloads the other ones.",+ multiModelDescriptionFit:+ "Loading a model keeps the others when they fit. When they don't, it unloads the ones not in use first, then the active one.",+ multiModelDescriptionAlways:+ "Loading a model never unloads another. A model that does not fit is not loaded. Idle auto-unload and training still free memory.",+ multiModelHint: "Covers chat, image and video models. Each loaded chat model answers the requests that name it. With several GPUs, Unsloth tries to place a new model on a GPU no other model uses. “When they fit” leaves about 1 GB spare. “When they fit” and “Always” never unload a model on another GPU.",+ mediaIdleUnloadDescription:+ "Free VRAM by unloading the image and video models after this many idle seconds. 0 keeps them loaded, minimum 60.",mlockVetoed: "--mlock stays off: pinning the model in place would reserve RAM for all of it. Idle auto-unload is still disabled.",mlockNotApplicable: "Fully on the GPU: nothing in system RAM to lock. Idle auto-unload stays off.",memlockCapped: "This system caps locked memory at {limit}. A larger model will not be fully pinned; raise the limit with ulimit -l.",@@ -2417,6 +2427,10 @@ export const en = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu memory ram resident residency pin pinned page lock locked keep loaded unload idle mmap no-mmap load-mode swap paging",+ multiModelKeywords:+ "multiple several models together alongside swap fit unload evict vram gpu image video chat always idle",+ mediaIdleUnloadKeywords:+ "image video diffusion idle unload ttl timeout seconds free vram gpu memory",},storage: {title: "Storage",diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex dd02ee81ec2..210ad2012dd 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -1743,9 +1743,10 @@ export const es = {autoDownload: "Descargar los modelos que falten",autoDownloadDescription:"Descarga un GGUF que se indique en una solicitud de la API y que aún no esté descargado. Cualquiera con una clave de API podría así consumir disco y ancho de banda.",- keepKv: "Conservar el contexto del chat al liberar el modelo por inactividad",+ keepKv: "Conservar el contexto del chat entre descargas",keepKvDescription:- "Guarda la caché KV antes de liberar el modelo por inactividad para que los chats reanudados no vuelvan a leer el historial. Hasta 10 GB en disco.",+ "Guarda la caché KV antes de liberar el modelo por inactividad, o antes de que un modelo de imagen o vídeo ocupe la GPU, para que los chats reanudados no vuelvan a leer el historial. Hasta 10 GB en disco.",+ keepKvKeywords: "kv cache contexto cambio reanudar imagen video",apiOnly: "Liberar solo los modelos cargados por la API",apiOnlyDescription:"La liberación por inactividad mantiene en memoria el modelo que cargaste desde Unsloth y solo libera los que cargó una solicitud a la API.",@@ -2379,8 +2380,17 @@ export const es = {noRamReserveDescription: "Reduce la RAM ocupada por los pesos del modelo.",noRamReserveHint: "Omite la carga mapeada en memoria en las compilaciones de Windows compatibles cuando el modelo está totalmente descargado en la GPU, de modo que sus páginas no quedan residentes. En caso contrario conserva la carga mapeada en memoria. Los búferes de CPU necesarios pueden seguir usando RAM. Elimina --no-mmap y --mlock.",multiModel: "Mantener varios modelos cargados",- multiModelDescription: "Al cargar un modelo, los demás permanecen en memoria.",- multiModelHint: "Cada modelo cargado responde a las solicitudes que lo nombran. Con varias GPU, un modelo nuevo va a una GPU que ningún otro modelo usa cuando hay espacio. Si no cabe junto a los demás, primero se descargan los modelos que no se están usando y después reemplaza al modelo activo. El entrenamiento descarga los modelos adicionales antes que el activo.",+ multiModelOff: "Desactivado",+ multiModelFit: "Cuando quepan",+ multiModelAlways: "Siempre",+ multiModelDescription: "Al cargar un modelo de chat, imagen o vídeo, se descargan los demás.",+ multiModelDescriptionFit:+ "Al cargar un modelo, los demás se mantienen si caben. Si no caben, primero se descargan los que no se están usando y después el activo.",+ multiModelDescriptionAlways:+ "Al cargar un modelo nunca se descarga otro. Un modelo que no cabe no se carga. La descarga automática por inactividad y el entrenamiento siguen liberando memoria.",+ multiModelHint: "Se aplica a los modelos de chat, imagen y vídeo. Cada modelo de chat cargado responde a las solicitudes que lo nombran. Con varias GPU, Unsloth intenta colocar un modelo nuevo en una GPU que ningún otro modelo usa. «Cuando quepan» deja aproximadamente 1 GB libre. «Cuando quepan» y «Siempre» nunca descargan un modelo de otra GPU.",+ mediaIdleUnloadDescription:+ "Libera la VRAM descargando los modelos de imagen y vídeo después de este número de segundos de inactividad. El valor 0 los mantiene cargados; el mínimo es 60.",mlockVetoed: "--mlock permanece desactivado: fijar el modelo reservaría RAM para todo él. La descarga automática por inactividad sigue desactivada.",mlockNotApplicable: "Totalmente en la GPU: nada que bloquear en la RAM del sistema. La descarga automática por inactividad sigue desactivada.",memlockCapped: "Este sistema limita la memoria bloqueada a {limit}. Un modelo mayor no quedará fijado por completo; aumenta el límite con ulimit -l.",@@ -2390,6 +2400,10 @@ export const es = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu memoria ram residente fijar anclar bloquear mantener cargado descargar inactivo mmap no-mmap load-mode paginacion intercambio",+ multiModelKeywords:+ "varios multiples modelos juntos a la vez cambiar caber descargar expulsar vram gpu imagen video chat siempre inactivo",+ mediaIdleUnloadKeywords:+ "imagen video difusion inactivo descargar ttl tiempo de espera segundos liberar vram gpu memoria",},storage: {title: "Almacenamiento",diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex 62be5d0df97..367a718d123 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -1746,9 +1746,10 @@ export const fr = {autoDownloadDescription:"Récupérer un GGUF indiqué dans une requête API qui n'est pas encore téléchargé. Toute personne disposant d'une clé API peut alors consommer de l'espace disque et de la bande passante.",keepKv:- "Conserver le contexte de la discussion après un déchargement en cas d'inactivité",+ "Conserver le contexte de la discussion entre les déchargements",keepKvDescription:- "Enregistrer le cache KV avant un déchargement en cas d'inactivité, afin qu'une discussion reprise n'ait pas à relire l'historique. Jusqu'à 10 Go sur le disque.",+ "Enregistrer le cache KV avant un déchargement en cas d'inactivité, ou avant qu'un modèle d'image ou de vidéo prenne le GPU, afin qu'une discussion reprise n'ait pas à relire l'historique. Jusqu'à 10 Go sur le disque.",+ keepKvKeywords: "kv cache contexte changement reprendre image video",apiOnly: "Décharger uniquement les modèles chargés par l'API",apiOnlyDescription:"Le déchargement en cas d'inactivité laisse en mémoire un modèle que vous avez chargé depuis Unsloth et ne libère que ceux chargés par une requête API.",@@ -2383,8 +2384,17 @@ export const fr = {noRamReserveDescription: "Réduit la RAM occupée par les poids du modèle.",noRamReserveHint: "Ignore le chargement mappé en mémoire sur les versions Windows compatibles lorsque le modèle est entièrement déchargé sur le GPU, afin que ses pages ne restent pas résidentes. Sinon, conserve le chargement mappé en mémoire. Les tampons CPU nécessaires peuvent toujours occuper de la RAM. Supprime --no-mmap et --mlock.",multiModel: "Garder plusieurs modèles chargés",- multiModelDescription: "Charger un modèle garde les autres en mémoire.",- multiModelHint: "Chaque modèle chargé répond aux requêtes qui le nomment. Avec plusieurs GPU, un nouveau modèle va sur un GPU qu'aucun autre modèle n'utilise lorsqu'il y a de la place. S'il ne tient pas à côté des autres, les modèles inutilisés sont d'abord déchargés, puis il remplace le modèle actif. L'entraînement décharge les modèles supplémentaires avant le modèle actif.",+ multiModelOff: "Désactivé",+ multiModelFit: "S'ils tiennent",+ multiModelAlways: "Toujours",+ multiModelDescription: "Charger un modèle de discussion, d'image ou de vidéo décharge les autres.",+ multiModelDescriptionFit:+ "Charger un modèle garde les autres s'ils tiennent. Sinon, il décharge d'abord ceux qui ne sont pas utilisés, puis le modèle actif.",+ multiModelDescriptionAlways:+ "Charger un modèle n'en décharge jamais un autre. Un modèle qui ne tient pas n'est pas chargé. Le déchargement automatique en veille et l'entraînement libèrent toujours de la mémoire.",+ multiModelHint: "Concerne les modèles de discussion, d'image et de vidéo. Chaque modèle de discussion chargé répond aux requêtes qui le nomment. Avec plusieurs GPU, Unsloth essaie de placer un nouveau modèle sur un GPU qu'aucun autre modèle n'utilise. « S'ils tiennent » laisse environ 1 Go libre. « S'ils tiennent » et « Toujours » ne déchargent jamais un modèle sur un autre GPU.",+ mediaIdleUnloadDescription:+ "Libérer la VRAM en déchargeant les modèles d’image et de vidéo après ce nombre de secondes d’inactivité. 0 les maintient chargés ; le minimum est 60.",mlockVetoed: "--mlock reste désactivé : épingler le modèle réserverait de la RAM pour l'intégralité de celui-ci. Le déchargement automatique en veille reste désactivé.",mlockNotApplicable: "Entièrement sur le GPU : rien à verrouiller en RAM système. Le déchargement automatique en veille reste désactivé.",memlockCapped: "Ce système limite la mémoire verrouillée à {limit}. Un modèle plus grand ne sera pas entièrement épinglé ; augmentez la limite avec ulimit -l.",@@ -2394,6 +2404,10 @@ export const fr = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu memoire ram resident epingler verrouiller garder charge decharger inactif mmap no-mmap load-mode pagination echange",+ multiModelKeywords:+ "plusieurs modeles ensemble simultanes changer tenir decharger evincer vram gpu image video discussion toujours inactif",+ mediaIdleUnloadKeywords:+ "image video diffusion inactif decharger ttl delai secondes liberer vram gpu memoire",},storage: {title: "Stockage",diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.tsindex 0077eae8cce..390bdff565d 100644--- a/studio/frontend/src/i18n/locales/he.ts+++ b/studio/frontend/src/i18n/locales/he.ts@@ -1824,9 +1824,11 @@ export const he = {loadError: "טעינת הגדרות ההחלפה האוטומטית של מודלים נכשלה.",saveError: "שמירת הגדרות ההחלפה האוטומטית של מודלים נכשלה.",idleError: "הזן 0 כדי לשמור את המודל טעון, או לפחות 60 שניות.",- keepKv: "שמור הקשר צ'אט על פני פריקה בחוסר פעילות",+ keepKv: "שמור הקשר צ'אט על פני פריקות",keepKvDescription:- "שמור את מטמון ה-KV לפני פריקה בחוסר פעילות כדי שצ'אטים שיחודשו ידלגו על קריאה מחדש של ההיסטוריה. עד 10 GB בדיסק.",+ "שמור את מטמון ה-KV לפני פריקה בחוסר פעילות, או לפני שמודל תמונה או וידאו תופס את ה-GPU, כדי שצ'אטים שיחודשו ידלגו על קריאה מחדש של ההיסטוריה. עד 10 GB בדיסק.",+ keepKvKeywords:+ "kv cache context swap resume image video מטמון הקשר החלפה המשך תמונה וידאו",apiOnly: "פרוק רק מודלים שנטענו על ידי ה-API",apiOnlyDescription:"פריקה בחוסר פעילות תשאיר מודל שטענת מ-Unsloth בזיכרון, ותשחרר רק מודלים שנטענו בעקבות בקשת API.",@@ -2457,9 +2459,18 @@ export const he = {noRamReserveHint:"מדלג על טעינה ממופת זיכרון (Memory-mapped) בגרסאות Windows נתמכות כאשר המודל נפרק במלואו ל-GPU, כך שדפי הזיכרון שלו אינם נשמרים כתושבים. במקרים אחרים שומר על טעינה ממופת זיכרון. חוצצי CPU נדרשים עדיין יכולים להשתמש ב-RAM. מבטל את --no-mmap ו---mlock.",multiModel: "השאר מספר מודלים טעונים",- multiModelDescription: "טעינת מודל משאירה את האחרים בזיכרון.",+ multiModelOff: "כבוי",+ multiModelFit: "כשהם נכנסים",+ multiModelAlways: "תמיד",+ multiModelDescription: "טעינת מודל צ'אט, תמונה או וידאו פורקת את האחרים.",+ multiModelDescriptionFit:+ "טעינת מודל משאירה את האחרים כשהם נכנסים. כשלא, היא פורקת תחילה את אלה שאינם בשימוש, ואז את הפעיל.",+ multiModelDescriptionAlways:+ "טעינת מודל לעולם אינה פורקת מודל אחר. מודל שאינו נכנס לא נטען. פריקה בחוסר פעילות ואימון עדיין מפנים זיכרון.",multiModelHint:- "כל מודל טעון עונה לבקשות שמציינות אותו. כשיש כמה מעבדי GPU, מודל חדש נטען ל-GPU שאף מודל אחר אינו משתמש בו, אם יש בו מקום. כשהוא לא נכנס לצד האחרים, המודלים שאינם בשימוש נפרקים תחילה, ולאחר מכן הוא מחליף את המודל הפעיל. אימון פורק את המודלים הנוספים לפני המודל הפעיל.",+ "חל על מודלי צ'אט, תמונה ווידאו. כל מודל צ'אט טעון עונה לבקשות שמציינות אותו. כשיש כמה מעבדי GPU, Unsloth מנסה למקם מודל חדש ב-GPU שאף מודל אחר אינו משתמש בו. ”כשהם נכנסים” משאיר כ-1 GB פנוי. ”כשהם נכנסים” ו”תמיד” לעולם אינם פורקים מודל ב-GPU אחר.",+ mediaIdleUnloadDescription:+ "פנה VRAM על ידי פריקת מודלי תמונה ווידאו לאחר מספר שניות ללא פעילות. 0 שומר אותם טעונים, מינימום 60.",mlockVetoed:"הדגל --mlock נשאר כבוי: קיבוע המודל במקום ישריין RAM עבור כולו. פריקה אוטומטית בחוסר פעילות עדיין מושבתת.",mlockNotApplicable:@@ -2471,6 +2482,10 @@ export const he = {saveError: "שמירת הגדרות זיכרון המודל נכשלה",modelMemoryKeywords:"mlock memlock ulimit vram gpu memory ram resident residency pin pinned page lock locked keep loaded unload idle mmap no-mmap load-mode swap paging זיכרון קיבוע נעילה תושב השאר טעון פריקה סרק החלפה דפדוף",+ multiModelKeywords:+ "multiple several models together alongside swap fit unload evict vram gpu image video chat always idle מספר מודלים יחד במקביל החלפה נכנס פריקה פינוי תמונה וידאו צ'אט תמיד סרק",+ mediaIdleUnloadKeywords:+ "image video diffusion idle unload ttl timeout seconds free vram gpu memory תמונה וידאו דיפוזיה סרק פריקה זמן קצוב שניות פינוי זיכרון",},storage: {title: "אחסון",diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex 9a4d16199b6..fdd0c0ee187 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -1734,9 +1734,10 @@ export const hi = {autoDownload: "अनुपलब्ध मॉडल डाउनलोड करें",autoDownloadDescription:"API अनुरोध में बताया गया ऐसा GGUF लाता है जो अभी डाउनलोड नहीं हुआ है। इसके बाद API key रखने वाला कोई भी व्यक्ति डिस्क और बैंडविड्थ खर्च कर सकता है।",- keepKv: "निष्क्रियता पर अनलोड होने के बाद भी चैट का संदर्भ बनाए रखें",+ keepKv: "अनलोड होने के बाद भी चैट का संदर्भ बनाए रखें",keepKvDescription:- "निष्क्रियता पर अनलोड होने से पहले KV कैश सहेजता है, ताकि दोबारा शुरू की गई चैट को इतिहास फिर से न पढ़ना पड़े। डिस्क पर 10 GB तक।",+ "निष्क्रियता पर अनलोड होने से पहले, या किसी इमेज या वीडियो मॉडल के GPU लेने से पहले, KV कैश सहेजता है, ताकि दोबारा शुरू की गई चैट को इतिहास फिर से न पढ़ना पड़े। डिस्क पर 10 GB तक।",+ keepKvKeywords: "kv कैश संदर्भ स्वैप फिर से शुरू इमेज वीडियो",apiOnly: "केवल API द्वारा लोड किए गए मॉडल अनलोड करें",apiOnlyDescription:"निष्क्रियता पर अनलोड करते समय Unsloth से आपके द्वारा लोड किया गया मॉडल मेमोरी में बना रहता है, और केवल वही मॉडल हटाए जाते हैं जिन्हें किसी API अनुरोध ने लोड किया था।",@@ -2359,8 +2360,17 @@ export const hi = {noRamReserveDescription: "मॉडल वेट्स के लिए रखी गई RAM घटाता है।",noRamReserveHint: "जब मॉडल पूरी तरह GPU पर ऑफ़लोड हो, तो समर्थित Windows बिल्ड पर मेमोरी-मैप्ड लोडिंग छोड़ देता है, ताकि उसके पेज रेज़िडेंट न रहें। अन्यथा मेमोरी-मैप्ड लोडिंग बनाए रखता है। आवश्यक CPU बफ़र अब भी RAM ले सकते हैं। --no-mmap तथा --mlock हटा देता है।",multiModel: "कई मॉडल लोड रखें",- multiModelDescription: "मॉडल लोड करने पर बाकी मॉडल मेमोरी में बने रहते हैं।",- multiModelHint: "हर लोड किया गया मॉडल उन अनुरोधों का जवाब देता है जो उसका नाम लेते हैं। कई GPU होने पर, जगह हो तो नया मॉडल ऐसे GPU पर जाता है जिसे कोई दूसरा मॉडल इस्तेमाल नहीं कर रहा। अगर यह बाकी मॉडलों के साथ नहीं समाता, तो पहले इस्तेमाल में न रहे मॉडल अनलोड होते हैं, फिर यह सक्रिय मॉडल की जगह लेता है। ट्रेनिंग सक्रिय मॉडल से पहले अतिरिक्त मॉडलों को अनलोड करती है।",+ multiModelOff: "बंद",+ multiModelFit: "जब जगह हो",+ multiModelAlways: "हमेशा",+ multiModelDescription: "चैट, इमेज या वीडियो मॉडल लोड करने पर बाकी मॉडल अनलोड हो जाते हैं।",+ multiModelDescriptionFit:+ "मॉडल लोड करने पर, जगह हो तो बाकी मॉडल बने रहते हैं। जगह न हो, तो पहले इस्तेमाल में न रहे मॉडल अनलोड होते हैं, फिर सक्रिय मॉडल।",+ multiModelDescriptionAlways:+ "मॉडल लोड करने पर कोई दूसरा मॉडल कभी अनलोड नहीं होता। जो मॉडल नहीं समाता, वह लोड नहीं होता। निष्क्रियता पर स्वतः अनलोड और ट्रेनिंग अब भी मेमोरी खाली करते हैं।",+ multiModelHint: "चैट, इमेज और वीडियो मॉडल पर लागू होता है। हर लोड किया गया चैट मॉडल उन अनुरोधों का जवाब देता है जो उसका नाम लेते हैं। कई GPU होने पर, Unsloth नए मॉडल को ऐसे GPU पर रखने की कोशिश करता है जिसे कोई दूसरा मॉडल इस्तेमाल नहीं कर रहा। “जब जगह हो” लगभग 1 GB खाली छोड़ता है। “जब जगह हो” और “हमेशा” किसी दूसरे GPU पर मौजूद मॉडल को कभी अनलोड नहीं करते।",+ mediaIdleUnloadDescription:+ "इतने सेकंड तक निष्क्रिय रहने के बाद इमेज और वीडियो मॉडल अनलोड करके VRAM खाली करें। 0 पर वे लोड रहते हैं; न्यूनतम 60 सेकंड।",mlockVetoed: "--mlock बंद ही रहता है: मॉडल को पिन करने से उसकी पूरी मात्रा के लिए RAM आरक्षित हो जाएगी। निष्क्रिय होने पर स्वतः अनलोड अब भी अक्षम है।",mlockNotApplicable: "पूरी तरह GPU पर: सिस्टम RAM में लॉक करने के लिए कुछ नहीं। निष्क्रिय होने पर स्वतः अनलोड बंद रहता है।",memlockCapped: "यह सिस्टम लॉक की गई मेमोरी को {limit} तक सीमित करता है। इससे बड़ा मॉडल पूरी तरह पिन नहीं होगा; ulimit -l से सीमा बढ़ाएँ।",@@ -2370,6 +2380,10 @@ export const hi = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu मेमोरी रैम स्थायी पिन लॉक बनाए रखें लोड अनलोड निष्क्रिय mmap no-mmap load-mode स्वैप पेजिंग",+ multiModelKeywords:+ "कई मॉडल एक साथ स्वैप जगह अनलोड हटाना vram gpu इमेज वीडियो चैट हमेशा निष्क्रिय",+ mediaIdleUnloadKeywords:+ "इमेज वीडियो डिफ्यूजन निष्क्रिय अनलोड ttl टाइमआउट सेकंड खाली vram gpu मेमोरी",},storage: {title: "स्टोरेज",diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex 118ef13eb8f..4483f9831a2 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -1652,9 +1652,10 @@ export const it = {idleError:"Inserisci 0 per mantenere il modello in memoria, oppure almeno 60 secondi.",keepKv:- "Mantieni il contesto della chat dopo lo scaricamento dalla memoria per inattività",+ "Mantieni il contesto della chat tra gli scaricamenti",keepKvDescription:- "Salva la cache KV prima dello scaricamento dalla memoria per inattività, così le chat riprese non rileggono la cronologia. Fino a 10 GB su disco.",+ "Salva la cache KV prima dello scaricamento dalla memoria per inattività, o prima che un modello di immagini o video occupi la GPU, così le chat riprese non rileggono la cronologia. Fino a 10 GB su disco.",+ keepKvKeywords: "kv cache contesto cambio riprendere immagini video",apiOnly: "Scarica solo i modelli caricati dall'API",apiOnlyDescription:"Lo scaricamento per inattività lascia in memoria un modello caricato da te in Unsloth e libera solo quelli caricati da una richiesta API.",@@ -2290,8 +2291,17 @@ export const it = {noRamReserveDescription: "Riduce la RAM occupata dai pesi del modello.",noRamReserveHint: "Salta il caricamento mappato in memoria sulle build Windows supportate quando il modello è interamente scaricato sulla GPU, così le sue pagine non restano residenti. Altrimenti mantiene il caricamento mappato in memoria. I buffer CPU necessari possono comunque occupare RAM. Rimuove --no-mmap e --mlock.",multiModel: "Mantieni più modelli caricati",- multiModelDescription: "Caricare un modello mantiene gli altri in memoria.",- multiModelHint: "Ogni modello caricato risponde alle richieste che lo nominano. Con più GPU, un nuovo modello va su una GPU che nessun altro modello usa, se c'è spazio. Se non entra accanto agli altri, vengono prima scaricati i modelli non in uso, poi sostituisce il modello attivo. L'addestramento scarica i modelli aggiuntivi prima di quello attivo.",+ multiModelOff: "Disattivato",+ multiModelFit: "Se c'è spazio",+ multiModelAlways: "Sempre",+ multiModelDescription: "Caricare un modello di chat, immagini o video scarica gli altri.",+ multiModelDescriptionFit:+ "Caricare un modello mantiene gli altri se c'è spazio. Altrimenti scarica prima quelli non in uso, poi quello attivo.",+ multiModelDescriptionAlways:+ "Caricare un modello non ne scarica mai un altro. Un modello che non entra non viene caricato. Lo scaricamento automatico per inattività e l'addestramento liberano comunque memoria.",+ multiModelHint: "Vale per i modelli di chat, immagini e video. Ogni modello di chat caricato risponde alle richieste che lo nominano. Con più GPU, Unsloth prova a mettere un nuovo modello su una GPU che nessun altro modello usa. «Se c'è spazio» lascia circa 1 GB libero. «Se c'è spazio» e «Sempre» non scaricano mai un modello su un'altra GPU.",+ mediaIdleUnloadDescription:+ "Libera la VRAM scaricando i modelli di immagini e video dopo il numero indicato di secondi di inattività. 0 li mantiene in memoria; il minimo è 60.",mlockVetoed: "--mlock resta disattivato: bloccare il modello riserverebbe RAM per l'intero modello. Lo scaricamento automatico in inattività resta disattivato.",mlockNotApplicable: "Interamente sulla GPU: nulla da bloccare nella RAM di sistema. Lo scaricamento automatico in inattività resta disattivato.",memlockCapped: "Questo sistema limita la memoria bloccata a {limit}. Un modello più grande non verrà bloccato del tutto; aumenta il limite con ulimit -l.",@@ -2301,6 +2311,10 @@ export const it = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu memoria ram residente bloccare fissare mantenere caricato scaricare inattivo mmap no-mmap load-mode paginazione swap",+ multiModelKeywords:+ "più modelli insieme contemporaneamente cambio spazio scaricare espellere vram gpu immagini video chat sempre inattivo",+ mediaIdleUnloadKeywords:+ "immagini video diffusione inattivo scaricare ttl timeout secondi liberare vram gpu memoria",},storage: {title: "Archiviazione",diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex b99ce27ea06..7d99b729797 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -1722,9 +1722,10 @@ export const ja = {autoDownload: "不足しているモデルをダウンロード",autoDownloadDescription:"API リクエストで指定された未ダウンロードの GGUF を取得します。API キーを持つ人なら誰でもディスクと帯域を消費できるようになります。",- keepKv: "アイドル時の自動アンロードをまたいでチャットのコンテキストを保持",+ keepKv: "アンロードをまたいでチャットのコンテキストを保持",keepKvDescription:- "アイドル時の自動アンロードの前に KV キャッシュを保存し、再開したチャットが履歴を読み直さずに済むようにします。ディスク使用量は最大 10 GB です。",+ "アイドル時の自動アンロードの前、または画像や動画のモデルが GPU を使う前に KV キャッシュを保存し、再開したチャットが履歴を読み直さずに済むようにします。ディスク使用量は最大 10 GB です。",+ keepKvKeywords: "kv キャッシュ コンテキスト 切り替え 再開 画像 動画",apiOnly: "API が読み込んだモデルのみアンロード",apiOnlyDescription:"アイドル時の自動アンロードでは、Unsloth から自分で読み込んだモデルはメモリに残し、API リクエストが読み込んだモデルだけを解放します。",@@ -2332,8 +2333,17 @@ export const ja = {noRamReserveDescription: "モデルの重みが占有する RAM を減らします。",noRamReserveHint: "モデルが GPU に完全にオフロードされている場合、対応する Windows ビルドではメモリマップ読み込みを行わず、ファイルのページが常駐しないようにします。それ以外ではメモリマップ読み込みを維持します。必要な CPU バッファは RAM を使用することがあります。--no-mmap と --mlock を除去します。",multiModel: "複数のモデルを読み込んだままにする",- multiModelDescription: "モデルを読み込んでも、他のモデルはメモリに残ります。",- multiModelHint: "読み込まれた各モデルは、そのモデルを指定したリクエストに応答します。複数の GPU がある場合、空きがあれば新しいモデルは他のモデルが使っていない GPU に配置されます。他のモデルと並べて収まらない場合は、使用中でないモデルを先にアンロードし、それでも足りなければアクティブなモデルを置き換えます。トレーニングはアクティブなモデルより先に追加のモデルをアンロードします。",+ multiModelOff: "オフ",+ multiModelFit: "収まる場合",+ multiModelAlways: "常に",+ multiModelDescription: "チャット、画像、動画のモデルを読み込むと、他のモデルはアンロードされます。",+ multiModelDescriptionFit:+ "モデルを読み込んでも、収まる場合は他のモデルを残します。収まらない場合は、使用中でないモデルを先にアンロードし、次にアクティブなモデルをアンロードします。",+ multiModelDescriptionAlways:+ "モデルを読み込んでも、他のモデルはアンロードされません。収まらないモデルは読み込まれません。アイドル時の自動アンロードとトレーニングでは引き続きメモリが解放されます。",+ multiModelHint: "チャット、画像、動画のモデルが対象です。読み込まれた各チャットモデルは、そのモデルを指定したリクエストに応答します。複数の GPU がある場合、Unsloth は新しいモデルを他のモデルが使っていない GPU に配置しようとします。「収まる場合」は約 1 GB の空きを残します。「収まる場合」と「常に」は、別の GPU 上のモデルをアンロードしません。",+ mediaIdleUnloadDescription:+ "指定した秒数だけアイドル状態が続くと、画像モデルと動画モデルをアンロードして VRAM を解放します。0 にすると読み込んだままになります。最小値は 60 秒です。",mlockVetoed: "--mlock は無効のままです。モデルを固定するとモデル全体分の RAM を確保することになります。アイドル時の自動アンロードは引き続き無効です。",mlockNotApplicable: "すべて GPU 上にあるため、システム RAM に固定するものはありません。アイドル時の自動アンロードは無効のままです。",memlockCapped: "このシステムはロック可能なメモリを {limit} に制限しています。これより大きいモデルは完全には固定されません。ulimit -l で上限を引き上げてください。",@@ -2343,6 +2353,10 @@ export const ja = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu メモリ ram 常駐 固定 ロック 保持 ロード済み アンロード アイドル mmap no-mmap load-mode スワップ ページング",+ multiModelKeywords:+ "複数 モデル 同時 併用 切り替え 収まる アンロード 退避 vram gpu 画像 動画 チャット 常に アイドル",+ mediaIdleUnloadKeywords:+ "画像 動画 拡散 アイドル アンロード ttl タイムアウト 秒 解放 vram gpu メモリ",},storage: {title: "ストレージ",diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex 5306e76dc09..a1b1b4831f1 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -1727,9 +1727,10 @@ export const ko = {autoDownload: "아직 받지 않은 모델 다운로드",autoDownloadDescription:"API 요청에 지정된 GGUF 모델이 아직 다운로드되어 있지 않으면 해당 모델을 자동으로 다운로드합니다. 이 기능을 사용하면 API 키를 가진 사용자가 디스크 공간과 네트워크 대역폭을 사용할 수 있습니다.",- keepKv: "유휴 해제 후에도 채팅 컨텍스트 유지",+ keepKv: "해제 후에도 채팅 컨텍스트 유지",keepKvDescription:- "유휴 해제 전에 KV 캐시를 저장해, 이어서 하는 채팅이 기록을 다시 읽지 않도록 합니다. 디스크를 최대 10GB 사용합니다.",+ "유휴 해제 전이나 이미지 또는 동영상 모델이 GPU를 사용하기 전에 KV 캐시를 저장해, 이어서 하는 채팅이 기록을 다시 읽지 않도록 합니다. 디스크를 최대 10GB 사용합니다.",+ keepKvKeywords: "kv 캐시 컨텍스트 전환 이어서 이미지 동영상",apiOnly: "API가 불러온 모델만 해제",apiOnlyDescription:"유휴 해제 시 Unsloth에서 직접 불러온 모델은 메모리에 남기고, API 요청이 불러온 모델만 해제합니다.",@@ -2347,8 +2348,17 @@ export const ko = {noRamReserveDescription: "모델 가중치가 차지하는 RAM을 줄입니다.",noRamReserveHint: "모델이 GPU에 완전히 오프로드된 경우 지원되는 Windows 빌드에서 메모리 매핑 로딩을 건너뛰어 파일 페이지가 상주하지 않도록 합니다. 그렇지 않으면 메모리 매핑 로딩을 유지합니다. 필요한 CPU 버퍼는 여전히 RAM을 사용할 수 있습니다. --no-mmap과 --mlock을 제거합니다.",multiModel: "여러 모델을 로드된 상태로 유지",- multiModelDescription: "모델을 로드해도 다른 모델이 메모리에 남아 있습니다.",- multiModelHint: "로드된 각 모델은 해당 모델을 지정한 요청에 응답합니다. GPU가 여러 개이면 여유가 있을 때 새 모델은 다른 모델이 사용하지 않는 GPU에 배치됩니다. 다른 모델과 함께 들어가지 않으면 사용하지 않는 모델을 먼저 언로드하고, 그래도 부족하면 활성 모델을 대체합니다. 학습은 활성 모델보다 추가 모델을 먼저 언로드합니다.",+ multiModelOff: "끄기",+ multiModelFit: "공간이 있을 때",+ multiModelAlways: "항상",+ multiModelDescription: "채팅, 이미지, 동영상 모델을 로드하면 다른 모델은 언로드됩니다.",+ multiModelDescriptionFit:+ "모델을 로드할 때 공간이 있으면 다른 모델을 유지합니다. 공간이 없으면 사용하지 않는 모델을 먼저 언로드하고, 그다음 활성 모델을 언로드합니다.",+ multiModelDescriptionAlways:+ "모델을 로드해도 다른 모델을 언로드하지 않습니다. 공간이 부족한 모델은 로드되지 않습니다. 유휴 시 자동 언로드와 학습은 여전히 메모리를 확보합니다.",+ multiModelHint: "채팅, 이미지, 동영상 모델에 적용됩니다. 로드된 각 채팅 모델은 해당 모델을 지정한 요청에 응답합니다. GPU가 여러 개이면 Unsloth는 다른 모델이 사용하지 않는 GPU에 새 모델을 배치하려고 합니다. '공간이 있을 때'는 약 1GB를 남겨 둡니다. '공간이 있을 때'와 '항상'은 다른 GPU에 있는 모델을 언로드하지 않습니다.",+ mediaIdleUnloadDescription:+ "지정한 유휴 시간(초)이 지나면 이미지와 동영상 모델을 해제하여 VRAM을 확보합니다. 0으로 설정하면 계속 로드된 상태로 유지됩니다. 최소 60초입니다.",mlockVetoed: "--mlock은 꺼진 상태로 유지됩니다. 모델을 고정하면 모델 전체 크기만큼 RAM을 예약하게 됩니다. 유휴 시 자동 언로드는 계속 비활성화됩니다.",mlockNotApplicable: "모두 GPU에 있어 시스템 RAM에 고정할 것이 없습니다. 유휴 시 자동 언로드는 계속 꺼져 있습니다.",memlockCapped: "이 시스템은 잠금 메모리를 {limit}로 제한합니다. 더 큰 모델은 완전히 고정되지 않습니다. ulimit -l로 한도를 늘리세요.",@@ -2358,6 +2368,10 @@ export const ko = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu 메모리 ram 상주 고정 잠금 유지 로드됨 언로드 유휴 mmap no-mmap load-mode 스왑 페이징",+ multiModelKeywords:+ "여러 모델 동시 함께 전환 공간 언로드 해제 vram gpu 이미지 동영상 채팅 항상 유휴",+ mediaIdleUnloadKeywords:+ "이미지 동영상 디퓨전 유휴 해제 언로드 ttl 시간 초과 초 확보 vram gpu 메모리",},storage: {title: "저장소",diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex 75614e1d0f6..dd36b1ad812 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -1736,9 +1736,10 @@ export const ptBR = {autoDownload: "Baixar modelos ausentes",autoDownloadDescription:"Busca um GGUF indicado em uma requisição da API que ainda não foi baixado. Com isso, qualquer pessoa com uma chave de API pode consumir disco e largura de banda.",- keepKv: "Manter o contexto do chat ao descarregar por inatividade",+ keepKv: "Manter o contexto do chat entre descarregamentos",keepKvDescription:- "Salva o cache KV antes de um descarregamento por inatividade, para que chats retomados não releiam o histórico. Até 10 GB em disco.",+ "Salva o cache KV antes de um descarregamento por inatividade, ou antes que um modelo de imagem ou vídeo ocupe a GPU, para que chats retomados não releiam o histórico. Até 10 GB em disco.",+ keepKvKeywords: "kv cache contexto troca retomar imagem video",apiOnly: "Descarregar apenas modelos carregados pela API",apiOnlyDescription:"O descarregamento por inatividade mantém na memória o modelo que você carregou pelo Unsloth e libera apenas os que uma requisição da API carregou.",@@ -2367,8 +2368,17 @@ export const ptBR = {noRamReserveDescription: "Reduz a RAM ocupada pelos pesos do modelo.",noRamReserveHint: "Ignora o carregamento mapeado em memória nas versões compatíveis do Windows quando o modelo está totalmente descarregado na GPU, para que suas páginas não fiquem residentes. Caso contrário, mantém o carregamento mapeado em memória. Buffers de CPU necessários ainda podem usar RAM. Remove --no-mmap e --mlock.",multiModel: "Manter vários modelos carregados",- multiModelDescription: "Carregar um modelo mantém os outros na memória.",- multiModelHint: "Cada modelo carregado responde às solicitações que o nomeiam. Com várias GPUs, um novo modelo vai para uma GPU que nenhum outro modelo usa quando há espaço. Se não couber ao lado dos outros, os modelos fora de uso são descarregados primeiro e depois ele substitui o modelo ativo. O treinamento descarrega os modelos extras antes do ativo.",+ multiModelOff: "Desativado",+ multiModelFit: "Quando couberem",+ multiModelAlways: "Sempre",+ multiModelDescription: "Carregar um modelo de chat, imagem ou vídeo descarrega os outros.",+ multiModelDescriptionFit:+ "Carregar um modelo mantém os outros quando eles cabem. Quando não cabem, descarrega primeiro os que não estão em uso e depois o ativo.",+ multiModelDescriptionAlways:+ "Carregar um modelo nunca descarrega outro. Um modelo que não cabe não é carregado. A descarga automática por inatividade e o treinamento ainda liberam memória.",+ multiModelHint: "Vale para modelos de chat, imagem e vídeo. Cada modelo de chat carregado responde às solicitações que o nomeiam. Com várias GPUs, o Unsloth tenta colocar um novo modelo em uma GPU que nenhum outro modelo usa. “Quando couberem” deixa cerca de 1 GB livre. “Quando couberem” e “Sempre” nunca descarregam um modelo em outra GPU.",+ mediaIdleUnloadDescription:+ "Libera a VRAM descarregando os modelos de imagem e vídeo após esta quantidade de segundos de inatividade. 0 os mantém carregados; o mínimo é 60.",mlockVetoed: "--mlock continua desativado: fixar o modelo reservaria RAM para todo ele. A descarga automática por inatividade continua desativada.",mlockNotApplicable: "Totalmente na GPU: nada para bloquear na RAM do sistema. A descarga automática por inatividade continua desativada.",memlockCapped: "Este sistema limita a memória bloqueada a {limit}. Um modelo maior não será totalmente fixado; aumente o limite com ulimit -l.",@@ -2378,6 +2388,10 @@ export const ptBR = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu memoria ram residente fixar travar manter carregado descarregar ocioso mmap no-mmap load-mode paginacao swap",+ multiModelKeywords:+ "varios multiplos modelos juntos simultaneos trocar caber descarregar remover vram gpu imagem video chat sempre ocioso",+ mediaIdleUnloadKeywords:+ "imagem video difusao ocioso descarregar ttl tempo limite segundos liberar vram gpu memoria",},storage: {title: "Armazenamento",diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex 1f2e30ff36b..79bd8c961d5 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -1733,9 +1733,11 @@ export const ru = {autoDownload: "Скачивать недостающие модели",autoDownloadDescription:"Скачивает GGUF, указанный в запросе к API, если его ещё нет. Тогда любой, у кого есть ключ API, сможет расходовать место на диске и трафик.",- keepKv: "Сохранять контекст чата при автовыгрузке",+ keepKv: "Сохранять контекст чата между выгрузками",keepKvDescription:- "Сохраняет KV-кеш перед автовыгрузкой при простое, чтобы возобновлённые чаты не перечитывали историю. До 10 ГБ на диске.",+ "Сохраняет KV-кеш перед автовыгрузкой при простое или перед тем, как модель изображений или видео займёт GPU, чтобы возобновлённые чаты не перечитывали историю. До 10 ГБ на диске.",+ keepKvKeywords:+ "kv кеш контекст переключение возобновить изображения видео",apiOnly: "Выгружать только модели, загруженные через API",apiOnlyDescription:"Автовыгрузка при простое оставляет в памяти модель, которую вы загрузили в Unsloth, и освобождает только те, что загрузил запрос через API.",@@ -2363,8 +2365,17 @@ export const ru = {noRamReserveDescription: "Уменьшает объём ОЗУ, занятый весами модели.",noRamReserveHint: "Пропускает загрузку через отображение файла в память в поддерживаемых сборках Windows, когда модель полностью выгружена на видеокарту, чтобы её страницы не оставались в памяти. В остальных случаях сохраняет загрузку через отображение файла в память. Необходимые буферы ЦП всё равно могут занимать ОЗУ. Убирает --no-mmap и --mlock.",multiModel: "Держать несколько моделей загруженными",- multiModelDescription: "При загрузке модели остальные остаются в памяти.",- multiModelHint: "Каждая загруженная модель отвечает на запросы, в которых она указана. При нескольких GPU новая модель размещается на GPU, который не занят другой моделью, если там есть место. Если она не помещается рядом с остальными, сначала выгружаются неиспользуемые модели, затем она заменяет активную. Обучение выгружает дополнительные модели раньше активной.",+ multiModelOff: "Выкл.",+ multiModelFit: "Если помещаются",+ multiModelAlways: "Всегда",+ multiModelDescription: "При загрузке модели чата, изображений или видео остальные выгружаются.",+ multiModelDescriptionFit:+ "При загрузке модели остальные остаются, если помещаются. Если нет, сначала выгружаются неиспользуемые, затем активная.",+ multiModelDescriptionAlways:+ "Загрузка модели никогда не выгружает другую. Модель, которая не помещается, не загружается. Автовыгрузка по простою и обучение по-прежнему освобождают память.",+ multiModelHint: "Относится к моделям чата, изображений и видео. Каждая загруженная модель чата отвечает на запросы, в которых она указана. При нескольких GPU Unsloth старается разместить новую модель на GPU, который не занят другой моделью. «Если помещаются» оставляет около 1 ГБ свободным. «Если помещаются» и «Всегда» никогда не выгружают модель с другого GPU.",+ mediaIdleUnloadDescription:+ "Освобождать VRAM, выгружая модели изображений и видео после указанного числа секунд простоя. 0 оставляет их загруженными; минимальное значение: 60.",mlockVetoed: "--mlock остаётся выключенным: закрепление модели зарезервировало бы ОЗУ под неё целиком. Автовыгрузка по простою по-прежнему отключена.",mlockNotApplicable: "Полностью на GPU: в системной памяти нечего закреплять. Автовыгрузка по простою остаётся выключенной.",memlockCapped: "Система ограничивает блокируемую память значением {limit}. Модель большего размера не будет закреплена полностью; увеличьте лимит через ulimit -l.",@@ -2374,6 +2385,10 @@ export const ru = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu память озу резидентный закрепить блокировать держать загружен выгрузка простой mmap no-mmap load-mode подкачка",+ multiModelKeywords:+ "несколько моделей вместе одновременно переключение помещаются выгрузка вытеснение vram gpu изображения видео чат всегда простой",+ mediaIdleUnloadKeywords:+ "изображения видео диффузия простой выгрузка ttl таймаут секунды освободить vram gpu память",},storage: {title: "Хранилище",diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.tsindex 0d911c7523d..066be332007 100644--- a/studio/frontend/src/i18n/locales/sv.ts+++ b/studio/frontend/src/i18n/locales/sv.ts@@ -1884,9 +1884,11 @@ export const sv = {"Det gick inte att spara inställningarna för automatiskt modellbyte.",idleError:"Ange 0 för att behålla modellen inläst, eller minst 60 sekunder.",- keepKv: "Behåll chattkontext vid avlastning efter inaktivitet",+ keepKv: "Behåll chattkontext mellan avlastningar",keepKvDescription:- "Spara KV-cachen före en avlastning efter inaktivitet, så att återupptagna chattar slipper läsa historiken igen. Upp till 10 GB på disk.",+ "Spara KV-cachen före en avlastning efter inaktivitet, eller innan en bild- eller videomodell tar över GPU:n, så att återupptagna chattar slipper läsa historiken igen. Upp till 10 GB på disk.",+ keepKvKeywords:+ "kv cache kontext växling återuppta bild video context swap resume image",apiOnly: "Avlasta endast modeller som lästs in av API:et",apiOnlyDescription:"Avlastning efter inaktivitet lämnar en modell som du läst in från Unsloth i minnet och frigör endast de som lästs in av en API-begäran.",@@ -2534,10 +2536,19 @@ export const sv = {noRamReserveHint:"Hoppar över minnesmappad inläsning i Windows-versioner som stöds när modellen är helt avlastad till GPU:n, så att dess sidor inte hålls kvar i minnet. Annars behålls minnesmappad inläsning. Nödvändiga CPU-buffertar kan fortfarande använda RAM. Tar bort --no-mmap och --mlock.",multiModel: "Behåll flera modeller inlästa",+ multiModelOff: "Av",+ multiModelFit: "När de får plats",+ multiModelAlways: "Alltid",multiModelDescription:- "När en modell läses in behålls de andra i minnet.",+ "När en chatt-, bild- eller videomodell läses in avlastas de andra.",+ multiModelDescriptionFit:+ "När en modell läses in behålls de andra om de får plats. Annars avlastas först de som inte används, sedan den aktiva.",+ multiModelDescriptionAlways:+ "När en modell läses in avlastas aldrig en annan. En modell som inte får plats läses inte in. Avlastning efter inaktivitet och träning frigör fortfarande minne.",multiModelHint:- "Varje inläst modell besvarar de förfrågningar som anger den. Med flera GPU:er hamnar en ny modell på en GPU som ingen annan modell använder, om någon har plats. När den inte får plats bredvid de andra avlastas först de modeller som inte används, och sedan ersätter den den aktiva modellen. Träning avlastar de extra modellerna före den aktiva.",+ "Gäller chatt-, bild- och videomodeller. Varje inläst chattmodell besvarar de förfrågningar som anger den. Med flera GPU:er försöker Unsloth placera en ny modell på en GPU som ingen annan modell använder. ”När de får plats” lämnar ungefär 1 GB ledigt. ”När de får plats” och ”Alltid” avlastar aldrig en modell på en annan GPU.",+ mediaIdleUnloadDescription:+ "Frigör VRAM genom att avlasta bild- och videomodeller efter så många inaktiva sekunder. 0 behåller dem inlästa; minst 60.",mlockVetoed:"--mlock förblir av: att låsa modellen på plats skulle reservera RAM för hela modellen. Automatisk avlastning vid inaktivitet är fortfarande avstängd.",mlockNotApplicable:@@ -2550,6 +2561,10 @@ export const sv = {saveError: "Det gick inte att spara inställningarna för modellminne",modelMemoryKeywords:"mlock memlock ulimit vram gpu minne ram minnesresident fäst sida lås låst behåll inläst avlasta inaktiv mmap no-mmap inläsningsläge växling sidväxling mlock memlock ulimit vram gpu memory ram resident residency pin pinned page lock locked keep loaded unload idle mmap no-mmap load-mode swap paging",+ multiModelKeywords:+ "flera modeller samtidigt tillsammans växla plats avlasta vram gpu bild video chatt alltid inaktiv multiple several models together alongside swap fit unload evict image chat always idle",+ mediaIdleUnloadKeywords:+ "bild video diffusion inaktiv avlasta ttl tidsgräns sekunder frigör vram gpu minne image idle unload timeout seconds free memory",},storage: {title: "Lagring",diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex e797c551979..df9bfcda793 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -1710,9 +1710,10 @@ export const zhCN = {autoDownload: "下载缺失的模型",autoDownloadDescription:"获取 API 请求中指定但尚未下载的 GGUF。开启后,任何持有 API 密钥的人都可以占用你的磁盘空间和带宽。",- keepKv: "空闲卸载后保留聊天上下文",+ keepKv: "卸载后保留聊天上下文",keepKvDescription:- "在空闲卸载前保存 KV 缓存,让恢复的聊天无需重新读取历史。最多占用 10 GB 磁盘空间。",+ "在空闲卸载前,或在图像或视频模型占用 GPU 前保存 KV 缓存,让恢复的聊天无需重新读取历史。最多占用 10 GB 磁盘空间。",+ keepKvKeywords: "kv 缓存 上下文 切换 恢复 图像 视频",apiOnly: "仅卸载由 API 加载的模型",apiOnlyDescription:"空闲卸载会将你在 Unsloth 中加载的模型保留在内存中,只释放由 API 请求加载的模型。",@@ -2322,8 +2323,17 @@ export const zhCN = {noRamReserveDescription: "减少模型权重占用的内存。",noRamReserveHint: "当模型完全卸载到 GPU 时,在受支持的 Windows 版本上跳过内存映射加载,使其页面不再常驻;否则保持内存映射加载。必要的 CPU 缓冲区仍可能占用内存。移除 --no-mmap 和 --mlock。",multiModel: "保持多个模型加载",- multiModelDescription: "加载模型时,其他模型仍保留在内存中。",- multiModelHint: "每个已加载的模型都会响应指定它的请求。在多 GPU 机器上,如果有空间,新模型会放到没有其他模型使用的 GPU 上。如果无法与其他模型同时容纳,会先卸载未在使用的模型,然后替换当前模型。训练会先卸载额外的模型,再卸载当前模型。",+ multiModelOff: "关闭",+ multiModelFit: "能容纳时",+ multiModelAlways: "总是",+ multiModelDescription: "加载聊天、图像或视频模型时,会卸载其他模型。",+ multiModelDescriptionFit:+ "加载模型时,如果能容纳就保留其他模型。无法容纳时,先卸载未在使用的模型,再卸载当前模型。",+ multiModelDescriptionAlways:+ "加载模型时绝不卸载其他模型。无法容纳的模型不会被加载。空闲自动卸载和训练仍会释放内存。",+ multiModelHint: "适用于聊天、图像和视频模型。每个已加载的聊天模型都会响应指定它的请求。在多 GPU 机器上,Unsloth 会尽量把新模型放到没有其他模型使用的 GPU 上。“能容纳时”会预留约 1 GB 空间。“能容纳时”和“总是”都不会卸载其他 GPU 上的模型。",+ mediaIdleUnloadDescription:+ "空闲达到该秒数后卸载图像和视频模型以释放 VRAM。设为 0 则保持加载,最小值为 60 秒。",mlockVetoed: "--mlock 保持关闭:锁定模型会为其全部内容预留内存。空闲自动卸载仍处于禁用状态。",mlockNotApplicable: "已完全位于 GPU 上:系统内存中没有需要锁定的内容。空闲自动卸载保持关闭。",memlockCapped: "本系统将锁定内存限制为 {limit}。更大的模型无法被完全锁定;请使用 ulimit -l 提高上限。",@@ -2333,6 +2343,8 @@ export const zhCN = {// Not rendered: extra terms the settings search matches these rows on.modelMemoryKeywords:"mlock memlock ulimit vram gpu 内存 显存 常驻 固定 锁定 保持 已加载 卸载 空闲 mmap no-mmap load-mode 交换 分页",+ multiModelKeywords: "多个 模型 同时 一起 切换 容纳 卸载 驱逐 vram gpu 图像 视频 聊天 总是 空闲",+ mediaIdleUnloadKeywords: "图像 视频 扩散 空闲 卸载 ttl 超时 秒 释放 vram gpu 内存 显存",},storage: {title: "存储",diff --git a/studio/frontend/src/lib/evicted-toast.ts b/studio/frontend/src/lib/evicted-toast.tsnew file mode 100644index 00000000000..67dedbb3e4a--- /dev/null+++ b/studio/frontend/src/lib/evicted-toast.ts@@ -0,0 +1,107 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// What a load unloaded to make room, as one notice. Chat raises it as its own toast; Images and+// Video put it on their "Model loaded" toast, so a swap never stacks two toasts.++import {+ notifyModelEjected,+ notifyModelLifecycle,+} from "@/lib/model-lifecycle-events";+import { toast } from "@/lib/toast";++export type EvictedKind = "chat" | "audio" | "image" | "video";+export type EvictedSlot = { kind: EvictedKind; model: string };++const KINDS: readonly EvictedKind[] = ["chat", "audio", "image", "video"];++function isKind(value: unknown): value is EvictedKind {+ return KINDS.includes(value as EvictedKind);+}++/** Reads `evicted_slots`; falls back to `evicted: string[]` as chat models; anything else is []. */+export function evictedSlotsFrom(answer: unknown): EvictedSlot[] {+ if (!answer || typeof answer !== "object") return [];+ const { evicted_slots: slots, evicted } = answer as {+ evicted_slots?: unknown;+ evicted?: unknown;+ };+ if (Array.isArray(slots)) {+ return slots.flatMap((slot) => {+ const { kind, model } = (slot ?? {}) as {+ kind?: unknown;+ model?: unknown;+ };+ return isKind(kind) && typeof model === "string" && model+ ? [{ kind, model }]+ : [];+ });+ }+ if (Array.isArray(evicted)) {+ return evicted+ .filter((model): model is string => typeof model === "string" && !!model)+ .map((model) => ({ kind: "chat" as const, model }));+ }+ return [];+}++const DESCRIPTIONS: Record<EvictedKind, [one: string, many: string]> = {+ chat: [+ "Select it in chat to load it back.",+ "Select them in chat to load them back.",+ ],+ image: [+ "Load it again on the Images page.",+ "Load them again on the Images page.",+ ],+ video: [+ "Load it again on the Video page.",+ "Load them again on the Video page.",+ ],+ audio: [+ "Load it again on its audio page.",+ "Load them again on their audio pages.",+ ],+};++export function evictedNotice(+ slots: EvictedSlot[],+): { title: string; description: string } | null {+ const models = [...new Set(slots.map((slot) => slot.model))];+ if (models.length === 0) return null;+ const kinds = [...new Set(slots.map((slot) => slot.kind))];+ const description =+ kinds.length > 1+ ? "Load them again where you use them."+ : DESCRIPTIONS[kinds[0]][models.length > 1 ? 1 : 0];+ return { title: `Unloaded ${models.join(", ")} to make room`, description };+}++/** For the Images and Video "Model loaded" toast: the notice as its description, or nothing. */+export function evictedToastOptions(slots: EvictedSlot[]): {+ description?: string;+} {+ const notice = evictedNotice(slots);+ return notice+ ? { description: `${notice.title}. ${notice.description}` }+ : {};+}++export function toastEvicted(slots: EvictedSlot[]): void {+ const notice = evictedNotice(slots);+ if (notice) toast.info(notice.title, { description: notice.description });+}++/**+ * Tell the other runtimes their model is gone. Never `self`: the Images page treats its own+ * eject as a cancel of the load in flight, which is this very load.+ */+export function resyncEvicted(slots: EvictedSlot[], self: EvictedKind): void {+ const kinds = new Set(slots.map((slot) => slot.kind));+ kinds.delete(self);+ if (kinds.has("image")) notifyModelEjected("image");+ if (kinds.has("video")) notifyModelEjected("video");+ if (kinds.has("chat") || kinds.has("audio")) {+ notifyModelLifecycle({ runtime: "chat", loading: false, model: null });+ }+}diff --git a/studio/frontend/src/lib/model-lifecycle-events.ts b/studio/frontend/src/lib/model-lifecycle-events.tsindex b03fd7c585b..ea41d096088 100644--- a/studio/frontend/src/lib/model-lifecycle-events.ts+++ b/studio/frontend/src/lib/model-lifecycle-events.ts@@ -116,7 +116,13 @@ export async function withModelLoadNotice<T>(* cancelled or evicted load leaves behind -- the Images page's own poll treats* it the same way, and must, "else this loop spins forever".*/-export type LoadPhase = "downloading" | "finalizing" | "ready" | "error" | null;+export type LoadPhase =+ | "downloading"+ | "finalizing"+ | "saving_chat_context"+ | "ready"+ | "error"+ | null;/** How often the settle poll asks; overridable so a test need not sleep. */export const BACKGROUND_LOAD_POLL_MS = 2000;@@ -198,7 +204,12 @@ async function settleWhenLoadEnds(if (Date.now() - lastHealthy >= stallMs) return;continue;}- if (phase !== "downloading" && phase !== "finalizing") return;+ if (+ phase !== "downloading" &&+ phase !== "finalizing" &&+ phase !== "saving_chat_context"+ )+ return;lastHealthy = Date.now();}} finally {diff --git a/studio/frontend/src/lib/multi-model-refusal.ts b/studio/frontend/src/lib/multi-model-refusal.tsnew file mode 100644index 00000000000..cbb2c692617--- /dev/null+++ b/studio/frontend/src/lib/multi-model-refusal.ts@@ -0,0 +1,100 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// A load refused because "Keep multiple models loaded" is set to Always: the model it would+// have to unload stays, so this one does not load. Chat, Images and Video all surface it, so it+// lives here rather than beside the image memory refusal.++import { readFastApiError } from "@/lib/format-fastapi-error";++/** The same header as MEMORY_REFUSAL_HEADER; the two refusals are told apart by its value. */+export const REFUSAL_HEADER = "x-unsloth-refusal";+export const MULTI_MODEL_REFUSAL_KIND = "multi-model-always";+/** Mirrors gpu_arbiter.MULTI_MODEL_REFUSAL_MARKERS: the owner copy, then the managed copy. */+export const MULTI_MODEL_REFUSAL_MARKERS = [+ "is set to Always",+ "is set to keep loaded",+] as const;+export const MULTI_MODEL_REFUSAL_TITLE = "Model not loaded";++type HeaderBag = Headers | Record<string, string> | null | undefined;++/** A failed load POST that keeps what the toast needs: the status and the refusal headers. */+export class LoadRequestError extends Error {+ status: number;+ headers: Record<string, string>;++ constructor(+ message: string,+ status: number,+ headers: Record<string, string>,+ ) {+ super(message);+ this.name = "LoadRequestError";+ this.status = status;+ this.headers = headers;+ }+}++/** The thrown message is exactly readFastApiError's, so a load that was not refused reads as before. */+export async function loadRequestError(+ response: Response,+): Promise<LoadRequestError> {+ const headers: Record<string, string> = {};+ for (const name of [REFUSAL_HEADER, "retry-after"]) {+ const value = response.headers.get(name);+ if (value != null) headers[name] = value;+ }+ return new LoadRequestError(+ await readFastApiError(response),+ response.status,+ headers,+ );+}++export async function parseLoadJson<T>(response: Response): Promise<T> {+ if (!response.ok) throw await loadRequestError(response);+ return (await response.json()) as T;+}++/** The refusal headers a failure carries, when it carries any. */+export function refusalHeadersOf(failure: unknown): HeaderBag {+ if (!failure || typeof failure !== "object") return undefined;+ const headers = (failure as { headers?: unknown }).headers;+ if (!headers || typeof headers !== "object") return undefined;+ return headers as HeaderBag;+}++export function failureMessage(failure: unknown): string {+ if (failure instanceof Error) return failure.message;+ return typeof failure === "string" ? failure : "";+}++function refusalHeaderValue(headers: HeaderBag): string | null {+ if (!headers) return null;+ if (typeof (headers as Headers).get === "function") {+ return (headers as Headers).get(REFUSAL_HEADER);+ }+ for (const [name, value] of Object.entries(headers)) {+ if (name.toLowerCase() === REFUSAL_HEADER && typeof value === "string") {+ return value;+ }+ }+ return null;+}++/**+ * The header decides when it is there: response headers, or the plain dict a padded body+ * carries in `_deferred_error.headers`. Without one, the backend's wording does. The status is+ * accepted but never required, since a padded body answers 200.+ */+export function isMultiModelRefusal(+ _status: number | null | undefined,+ headers: HeaderBag,+ message: string | null | undefined,+): boolean {+ const value = refusalHeaderValue(headers)?.trim().toLowerCase();+ if (value) return value === MULTI_MODEL_REFUSAL_KIND;+ const text = message ?? "";+ return MULTI_MODEL_REFUSAL_MARKERS.some((marker) => text.includes(marker));+}diff --git a/studio/frontend/src/lib/swap-save-phase.ts b/studio/frontend/src/lib/swap-save-phase.tsnew file mode 100644index 00000000000..e29ae950055--- /dev/null+++ b/studio/frontend/src/lib/swap-save-phase.ts@@ -0,0 +1,46 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// While an Images or Video load POST is pending, the backend may first save the chat model's+// context so chat can resume after the swap. That save is the only thing load-progress says+// about THIS load before the POST answers: every other phase still describes the previous+// model, so reading "ready" or null here as the end of the load would be wrong.++export const SAVING_CHAT_CONTEXT = "saving_chat_context";++/** Calls onSaving on each tick that reports the save, and ignores every other phase.+ * stop() is idempotent and drops a read still in flight. */+export function watchSavingPhase(+ read: (signal: AbortSignal) => Promise<{ phase: unknown }>,+ onSaving: () => void,+ opts: { intervalMs?: number; firstDelayMs?: number } = {},+): { stop(): void } {+ const intervalMs = opts.intervalMs ?? 1000;+ let stopped = false;+ let timer: ReturnType<typeof setTimeout> | null = null;+ let inFlight: AbortController | null = null;++ const tick = async () => {+ if (stopped) return;+ const controller = new AbortController();+ inFlight = controller;+ try {+ const progress = await read(controller.signal);+ if (!stopped && progress?.phase === SAVING_CHAT_CONTEXT) onSaving();+ } catch {+ // A failed read says nothing about the save; try again next tick.+ }+ if (inFlight === controller) inFlight = null;+ if (!stopped) timer = setTimeout(() => void tick(), intervalMs);+ };++ timer = setTimeout(() => void tick(), opts.firstDelayMs ?? intervalMs);+ return {+ stop() {+ if (stopped) return;+ stopped = true;+ if (timer) clearTimeout(timer);+ inFlight?.abort();+ },+ };+}diff --git a/studio/frontend/tests/image-generate-no-resend.test.ts b/studio/frontend/tests/image-generate-no-resend.test.tsindex 361e6531074..f70d95de17f 100644--- a/studio/frontend/tests/image-generate-no-resend.test.ts+++ b/studio/frontend/tests/image-generate-no-resend.test.ts@@ -39,6 +39,7 @@ function loadApis(): ImagesApi {"@/lib/model-lifecycle-events": { withBackgroundLoadNotice: (f: unknown) => f },"@/features/auth": { authFetch: auth.authFetch },"@/lib/format-fastapi-error": { readFastApiError: async () => "" },+ "@/lib/multi-model-refusal": { parseLoadJson: async () => ({}) },},{ relativePassthrough: true },);diff --git a/studio/frontend/tests/images-evicted-toast.test.ts b/studio/frontend/tests/images-evicted-toast.test.tsnew file mode 100644index 00000000000..5ab06ac38d2--- /dev/null+++ b/studio/frontend/tests/images-evicted-toast.test.ts@@ -0,0 +1,166 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// A load that unloads another model says so once: chat in its own toast, Images and Video on the+// "Model loaded" toast. Other runtimes are resynced, never the loading one (a self-eject cancels).++import assert from "node:assert/strict";+import { register } from "node:module";+import test from "node:test";++import type * as ActionModule from "../src/features/settings/lib/model-memory-action.ts";+import { useSettingsDialogStore } from "../src/features/settings/stores/settings-dialog-store.ts";+import { readSrc } from "./helpers/kit.ts";+import { loadWithStubs } from "./helpers/module-stubs.ts";+import { calls } from "./helpers/toast-stub.mjs";++register("./helpers/toast-resolver.mjs", import.meta.url);+// model-lifecycle-events dispatches on `window`; stand one up before importing it.+const win = new EventTarget();+(globalThis as { window?: unknown }).window = win;++const events = await import("../src/lib/model-lifecycle-events.ts");+const lib = await import("../src/lib/evicted-toast.ts");+type Kind = "chat" | "audio" | "image" | "video";+const slots = (kind: Kind, ...models: string[]) =>+ models.map((model) => ({ kind, model }));++test("evicted_slots wins, bare names read as chat, anything else is nothing", () => {+ const bad = [{ kind: "x", model: "y" }, { kind: "video", model: "" }, null];+ const mixed = {+ evicted_slots: [...slots("image", "F"), ...bad],+ evicted: ["Q"],+ };+ const junk = [null, "x", 4, {}, { evicted: "Q" }, { evicted_slots: {} }];+ const cases: [unknown, unknown][] = [+ [mixed, slots("image", "F")],+ [{ evicted: ["Q", 3, ""] }, slots("chat", "Q")],+ ...junk.map((answer): [unknown, unknown] => [answer, []]),+ ];+ for (const [answer, want] of cases) {+ assert.deepEqual(+ lib.evictedSlotsFrom(answer),+ want,+ JSON.stringify(answer),+ );+ }+});++test("the notice names what went and where to load it again", () => {+ const cases: [ReturnType<typeof slots>, string][] = [+ [slots("chat", "A"), "Select it in chat to load it back."],+ [slots("chat", "A", "B"), "Select them in chat to load them back."],+ [slots("image", "A"), "Load it again on the Images page."],+ [slots("image", "A", "B"), "Load them again on the Images page."],+ [slots("video", "A"), "Load it again on the Video page."],+ [slots("video", "A", "B"), "Load them again on the Video page."],+ [slots("audio", "A"), "Load it again on its audio page."],+ [slots("audio", "A", "B"), "Load them again on their audio pages."],+ [+ [...slots("chat", "A"), ...slots("audio", "B")],+ "Load them again where you use them.",+ ],+ ];+ for (const [evicted, description] of cases) {+ const title = `Unloaded ${evicted.map((s) => s.model).join(", ")} to make room`;+ assert.deepEqual(lib.evictedNotice(evicted), { title, description });+ }+ assert.equal(lib.evictedNotice([]), null);+ // Negative control: main's POST answer has no eviction fields, so "Model loaded" stays bare.+ assert.deepEqual(+ lib.evictedToastOptions(lib.evictedSlotsFrom({ loaded: true })),+ {},+ );+ assert.deepEqual(lib.evictedToastOptions(slots("chat", "Q")), {+ description: "Unloaded Q to make room. Select it in chat to load it back.",+ });+});++test("chat raises exactly one info toast, and none when nothing was unloaded", () => {+ calls.length = 0;+ lib.toastEvicted([]);+ lib.toastEvicted([...slots("image", "F"), ...slots("video", "L")]);+ const description = "Load them again where you use them.";+ const title = "Unloaded F, L to make room";+ assert.deepEqual(calls, [{ kind: "info", title, options: { description } }]);+});++test("the other runtimes are resynced, the loading one never is", () => {+ const seen: string[] = [];+ type Detail = CustomEvent<{ runtime: string }>;+ const record = (tag: string) => (e: Event) =>+ seen.push(`${tag}:${(e as Detail).detail.runtime}`);+ win.addEventListener(events.MODEL_EJECTED_EVENT, record("ejected"));+ win.addEventListener(events.MODEL_LIFECYCLE_EVENT, record("lifecycle"));+ const all = [+ slots("image", "A"),+ slots("video", "B"),+ slots("chat", "C"),+ ].flat();+ const cases: [ReturnType<typeof slots>, Kind, string[]][] = [+ [all, "image", ["ejected:video", "lifecycle:chat"]],+ [all, "video", ["ejected:image", "lifecycle:chat"]],+ [slots("image", "A"), "image", []],+ [slots("audio", "W"), "chat", ["lifecycle:chat"]],+ ];+ for (const [evicted, self, want] of cases) {+ seen.length = 0;+ lib.resyncEvicted(evicted, self);+ assert.deepEqual(seen, want, self);+ }+});++const media = (kind: Kind) => [+ 'toast.success("Model loaded", evictedToastOptions(evicted));',+ "pendingEvicted.current = evictedSlotsFrom(answer);",+ `resyncEvicted(pendingEvicted.current, "${kind}");`,+];+const SECOND_TOAST = [+ 'toast.success("Model loaded");',+ "toastEvicted(",+ "toast.info(`Unloaded",+];+const PINS: [string, string[], string[]][] = [+ ["features/images/images-page.tsx", media("image"), SECOND_TOAST],+ ["features/video/video-page.tsx", media("video"), SECOND_TOAST],+ [+ "features/chat/hooks/use-chat-model-runtime.ts",+ ["toastEvicted(evictedSlots);", 'resyncEvicted(evictedSlots, "chat");'],+ ["Select it again to load it back."],+ ],+];++for (const [path, required, forbidden] of PINS) {+ test(`${path} raises one eviction notice and never ejects itself`, () => {+ const source = readSrc(path);+ for (const pin of required)+ assert.ok(source.includes(pin), `missing: ${pin}`);+ for (const pin of forbidden)+ assert.ok(!source.includes(pin), `a second toast: ${pin}`);+ });+}++function actionFor(owner: boolean) {+ useSettingsDialogStore.setState({ open: false, scrollTarget: null });+ const url = new URL(+ "../src/features/settings/lib/model-memory-action.ts",+ import.meta.url,+ );+ return loadWithStubs<typeof ActionModule>(url, {+ "../stores/settings-dialog-store": { useSettingsDialogStore },+ "@/features/auth/account-session": { isAccountOwner: () => owner },+ }).modelMemorySettingsAction();+}++test("Open settings is the owner's only, and lands on Model memory", () => {+ assert.equal(actionFor(false), undefined);+ assert.equal(useSettingsDialogStore.getState().open, false);+ const action = actionFor(true);+ assert.equal(action?.label, "Open settings");+ action?.onClick();+ const { open, activeTab, scrollTarget } = useSettingsDialogStore.getState();+ assert.deepEqual(+ [open, activeTab, scrollTarget],+ [true, "resources", "resources-model-memory"],+ );+});diff --git a/studio/frontend/tests/load-refusal-header.test.ts b/studio/frontend/tests/load-refusal-header.test.tsnew file mode 100644index 00000000000..c4989406d52--- /dev/null+++ b/studio/frontend/tests/load-refusal-header.test.ts@@ -0,0 +1,179 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// A load refused by "Keep multiple models loaded: Always" reads as that however it arrives: the+// X-Unsloth-Refusal header (shared with the memory refusal, so its VALUE decides), its dict in a+// padded body, or only the backend's wording (chat drops headers today).++import assert from "node:assert/strict";+import { existsSync, readFileSync } from "node:fs";+import { createServer } from "node:http";+import { register } from "node:module";+import test, { afterEach } from "node:test";++import { readSrc } from "./helpers/kit.ts";+import { loadWithStubs } from "./helpers/module-stubs.ts";++register("./helpers/settings-api-resolver.mjs", import.meta.url);+const originalFetch = globalThis.fetch;+afterEach(() => {+ globalThis.fetch = originalFetch;+});++const refusal = await import("../src/lib/multi-model-refusal.ts");+const { isMultiModelRefusal, refusalHeadersOf } = refusal;+const { loadDiffusionModel } = await import("../src/features/images/api.ts");+const { loadVideoModel } = await import("../src/features/video/api.ts");+const DETAIL = "Another model holds the GPU and this load would unload it.";+const REFUSED = { "x-unsloth-refusal": "multi-model-always" };+const refused = (err: unknown) =>+ isMultiModelRefusal(null, refusalHeadersOf(err), (err as Error).message);++const LOADS = [+ ["Images", () => loadDiffusionModel({ model_path: "FLUX.2-klein" })],+ ["Video", () => loadVideoModel({ model_path: "LTX-2" })],+] as const;++for (const [page, load] of LOADS) {+ test(`a ${page} load POST keeps the refusal header, and a plain failure reads as before`, async () => {+ const cases: [number, Record<string, string>, string, boolean][] = [+ [409, { ...REFUSED, "retry-after": "5" }, DETAIL, true],+ [500, {}, "CUDA out of memory", false],+ ];+ for (const [status, headers, detail, want] of cases) {+ const body = JSON.stringify({ detail });+ globalThis.fetch = (async () =>+ new Response(body, { status, headers })) as typeof fetch;+ await assert.rejects(load(), (err: unknown) => {+ assert.ok(err instanceof refusal.LoadRequestError);+ assert.deepEqual(+ [err.message, err.status, err.headers["retry-after"]],+ [detail, status, headers["retry-after"]],+ );+ return refused(err) === want;+ });+ }+ });+}++test("the matcher: header value first, then the backend's wording", () => {+ type Bag = Parameters<typeof isMultiModelRefusal>[1];+ type Row = [number | null, Bag, string, boolean];+ const memory = new Headers({ "X-Unsloth-Refusal": "memory-estimate" });+ const cases: Row[] = [+ [200, REFUSED, "x", true], // a padded body's dict, under a 200+ [null, { "X-Unsloth-Refusal": " Multi-Model-Always " }, "", true],+ ...refusal.MULTI_MODEL_REFUSAL_MARKERS.map(+ (m): Row => [null, undefined, m, true],+ ),+ [409, memory, "is set to Always", false], // the shared header's value wins+ [409, undefined, DETAIL, false],+ [409, {}, "", false],+ ];+ for (const [status, headers, message, want] of cases) {+ assert.equal(+ isMultiModelRefusal(status, headers, message),+ want,+ `${JSON.stringify(headers)} ${message}`,+ );+ }+ // The LoadModelError shape (an error with .headers) is read by them; other failures carry none.+ assert.equal(+ refused(Object.assign(new Error("Refused."), { headers: REFUSED })),+ true,+ );+ assert.equal(refusalHeadersOf(new Error("x")), undefined);+});++test("a chat load refused inside a padded body is recognised by its wording", async () => {+ const detail = "Keep multiple models loaded is set to Always.";+ const body = JSON.stringify({+ _deferred_error: { status_code: 409, detail, headers: REFUSED },+ });+ const server = createServer((req, res) => {+ req.resume();+ req.on("end", () =>+ res.writeHead(200, { "Content-Type": "application/json" }).end(body),+ );+ });+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));+ const { port } = server.address() as { port: number };+ // Only what loadModel needs answered is spelled out; every other import is a no-op.+ const used: Record<string, unknown> = {+ "@/features/auth": {+ authFetch: (path: string, init?: RequestInit) =>+ originalFetch(`http://127.0.0.1:${port}${path}`, init),+ },+ "./padded-response": await import(+ "../src/features/chat/api/padded-response.ts"+ ),+ "@/lib/format-fastapi-error": await import(+ "../src/lib/format-fastapi-error.ts"+ ),+ "@/features/hf-auth": {+ prepareHfTokenForUse: async () => ({ proceed: true }),+ },+ "@/lib/model-lifecycle-events": {+ withModelLoadNotice: (_r: string, _m: string, run: () => unknown) =>+ run(),+ },+ };+ const stubs = new Proxy(used, {+ has: () => true,+ get: (t, k: string) =>+ t[k] ?? new Proxy({}, { get: () => () => undefined }),+ });+ const chat = loadWithStubs<{ loadModel: (p: object) => Promise<unknown> }>(+ new URL("../src/features/chat/api/chat-api.ts", import.meta.url),+ stubs,+ );+ try {+ await assert.rejects(+ chat.loadModel({ model_path: "unsloth/Qwen3-0.6B-GGUF" }),+ (err: unknown) => {+ assert.equal((err as Error).message, detail);+ // chat-api drops the padded headers until LoadModelError carries them; the wording still matches.+ return refused(err);+ },+ );+ } finally {+ server.close();+ }+});++test("Images, Video and chat raise the refusal under its title, with the owner's settings link", () => {+ const media = [+ "if (isMultiModelRefusal(null, refusalHeadersOf(failure), text)) {",+ "{ description: text || fallback, action: modelMemorySettingsAction() }",+ 'reportLoadFailure(err, "Failed to start load");',+ ];+ const pins: [string, string[]][] = [+ ["features/images/images-page.tsx", media],+ ["features/video/video-page.tsx", media],+ [+ "features/chat/hooks/use-chat-model-runtime.ts",+ [+ "isMultiModelRefusal(null, refusalHeadersOf(err), message);",+ "const title = refusal ? MULTI_MODEL_REFUSAL_TITLE : summary;",+ "const action = refusal ? modelMemorySettingsAction() : logsAction;",+ ],+ ],+ ];+ for (const [path, required] of pins) {+ const source = readSrc(path);+ for (const pin of required)+ assert.ok(source.includes(pin), `${path} missing: ${pin}`);+ }+});++test("the wording matched here is the backend's", (t) => {+ const arbiter = new URL(+ "../../backend/core/inference/gpu_arbiter.py",+ import.meta.url,+ );+ const source = existsSync(arbiter) ? readFileSync(arbiter, "utf8") : "";+ if (!source.includes("MULTI_MODEL_REFUSAL_MARKERS ="))+ return t.skip("the backend exports no refusal markers yet");+ for (const marker of refusal.MULTI_MODEL_REFUSAL_MARKERS)+ assert.ok(source.includes(marker), marker);+});diff --git a/studio/frontend/tests/media-auto-switch-setting.test.ts b/studio/frontend/tests/media-auto-switch-setting.test.tsindex d2e511151be..9c460410c9b 100644--- a/studio/frontend/tests/media-auto-switch-setting.test.ts+++ b/studio/frontend/tests/media-auto-switch-setting.test.ts@@ -120,3 +120,14 @@ test("a saved auto-switch value reaches subscribers until they unsubscribe", asyawait updateOpenAIAutoSwitchSettings({ enabled: true });assert.deepEqual(seen, [false]);});++test("a media TTL save from Model memory leaves the chat toggle stored", async () => {+ // That row has no chat toggle on screen, so it must not write back a stale `enabled`.+ invalidateOpenAIAutoSwitchSettings();+ bodies.length = 0;+ await updateOpenAIAutoSwitchSettings({ mediaAutoUnloadIdleSeconds: 600 });+ // biome-ignore lint/style/useNamingConvention: API schema+ assert.deepEqual(JSON.parse(bodies[0] ?? "{}"), {+ media_auto_unload_idle_seconds: 600,+ });+});diff --git a/studio/frontend/tests/media-idle-unload-api-only.test.ts b/studio/frontend/tests/media-idle-unload-api-only.test.tsindex b195f999023..6ceab97bfaf 100644--- a/studio/frontend/tests/media-idle-unload-api-only.test.ts+++ b/studio/frontend/tests/media-idle-unload-api-only.test.ts@@ -11,7 +11,10 @@import assert from "node:assert/strict";import test from "node:test";+import ts from "@typescript/typescript6";+import { readSrc } from "./helpers/kit.ts";+import { openingTag } from "./helpers/tsx-ast.ts";const SECTION = readSrc("features/settings/components/model-auto-switch-section.tsx");@@ -34,12 +37,22 @@ test("it is still reachable from the chat TTL alone", () => {assert.match(guardFor("apiOnly"), /idleUnloadActive/);});-test("the KV-save option stays with the chat TTL it belongs to", () => {- // It persists llama.cpp slot KV; there is no media equivalent, so widening the API-only- // row must not drag it along.- const guard = guardFor("keepKv");- assert.match(guard, /idleUnloadActive/);- assert.doesNotMatch(guard, /mediaAutoUnloadIdleSeconds/);+test("the KV-save option renders without the chat TTL", () => {+ // It also saves the chat KV before an image or video model takes the GPU, so no guard.+ const file = ts.createSourceFile("s.tsx", SECTION, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TSX);+ let row: ts.Node | undefined;+ const visit = (node: ts.Node): void => {+ const tag = openingTag(node);+ if (tag?.tagName.getText() === "SettingsRow" && /modelAutoSwitch\.keepKv"/.test(tag.getText())) row = node;+ ts.forEachChild(node, visit);+ };+ visit(file);+ assert.ok(row, "the keepKv row is rendered");+ assert.doesNotMatch(row.getText(), /mediaAutoUnloadIdleSeconds/);+ for (let node = row.parent; openingTag(node)?.tagName.getText() !== "SettingsSection"; node = node.parent) {+ const guard = ts.isConditionalExpression(node) || (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken);+ assert.ok(!guard, `keepKv is behind ${node.getText().slice(0, 40)}`);+ }});test("the media row still says when a veto is holding its TTL", () => {diff --git a/studio/frontend/tests/media-load-cancel.test.ts b/studio/frontend/tests/media-load-cancel.test.tsindex e10cee7b563..7af695c5a2c 100644--- a/studio/frontend/tests/media-load-cancel.test.ts+++ b/studio/frontend/tests/media-load-cancel.test.ts@@ -41,10 +41,12 @@ for (const [page, path] of PAGES) {// the mount-time resume of a load started elsewhere, re-created in place by// each progress tick, and rebuilt by handleCancelLoad when the unload fails// and the load it could not stop has to stay visible. A tick that dropped- // the action would make the button vanish one second into the load.+ // the action would make the button vanish one second into the load. The+ // fifth is handleLoad's "Saving chat context…" update while the start+ // request is pending, which must keep the Cancel too.// Call sites only: the declaration's own argument list opens with a newline.const sites = SOURCE.match(/loadToastArgs\((?!\n)[^)\n]*\)/g) ?? [];- assert.equal(sites.length, 4, "expected the four load-toast call sites");+ assert.equal(sites.length, 5, "expected the five load-toast call sites");for (const site of sites) {assert.match(site,diff --git a/studio/frontend/tests/media-saving-chat-context.test.ts b/studio/frontend/tests/media-saving-chat-context.test.tsnew file mode 100644index 00000000000..8471662f1b8--- /dev/null+++ b/studio/frontend/tests/media-saving-chat-context.test.ts@@ -0,0 +1,92 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// While a media load POST is pending the backend may save the chat context first, and the toast+// says so. Every other phase then describes the PREVIOUS model, so only the save is rendered.++import assert from "node:assert/strict";+import test from "node:test";++import * as save from "../src/lib/swap-save-phase.ts";+import { readSrc } from "./helpers/kit.ts";++const tick = () => new Promise((resolve) => setTimeout(resolve, 5));+const FAST = { intervalMs: 1, firstDelayMs: 0 };+const SAVE = save.SAVING_CHAT_CONTEXT;++test("only the saving phase reaches the toast, and a failed read keeps watching", async () => {+ const phases = ["ready", null, "boom", SAVE, "downloading", "error", SAVE];+ let saving = 0;+ let reads = 0;+ const watch = save.watchSavingPhase(+ async () => {+ const phase = phases[reads++] ?? "ready";+ if (phase === "boom") throw new Error("offline");+ return { phase };+ },+ () => saving++,+ FAST,+ );+ while (reads < phases.length) await tick();+ watch.stop();+ assert.equal(saving, 2);+});++test("a read still in flight at stop() is dropped, and stop() is idempotent", async () => {+ let release: (value: { phase: unknown }) => void = () => {};+ let aborted = false;+ let saving = 0;+ let reads = 0;+ const read = (signal: AbortSignal) => {+ reads++;+ signal.addEventListener("abort", () => {+ aborted = true;+ });+ return new Promise<{ phase: unknown }>((resolve) => {+ release = resolve;+ });+ };+ const watch = save.watchSavingPhase(read, () => saving++, FAST);+ while (reads === 0) await tick();+ watch.stop();+ watch.stop();+ release({ phase: SAVE });+ await tick();+ assert.deepEqual(+ { aborted, saving, reads },+ { aborted: true, saving: 0, reads: 1 },+ );+});++for (const [path, read] of [+ ["features/images/images-page.tsx", "getDiffusionLoadProgress"],+ ["features/video/video-page.tsx", "getVideoLoadProgress"],+] as const) {+ test(`${path} shows the save on its own load toast, only while the POST is pending`, () => {+ const source = readSrc(path);+ for (const pin of [+ 'if (p.phase === "saving_chat_context") {',+ 'title="Saving chat context…"',+ `message="Saving the chat model's context so it can resume after this load."`,+ // The same toast id, keeping Cancel, fenced on a cancel or a newer load.+ "if (startSeq === cancelSeq.current && startLoad === loadSeq.current && loadToastId.current != null) {",+ "toast(null, loadToastArgs(SAVING_PROGRESS, loadToastId.current, cancelLoadFromToast));",+ ]) {+ assert.ok(source.includes(pin), `missing: ${pin}`);+ }+ const load = source.slice(+ source.indexOf("const handleLoad = useCallback("),+ );+ const order = [+ "loadToastId.current = toast(",+ `const savePoll = watchSavingPhase(${read}, () => {`,+ "const answer = await startRequest;",+ "savePoll.stop();",+ "void pollLoadProgress();",+ ].map((pin) => load.indexOf(pin));+ assert.ok(+ order.every((at, i) => at > 0 && (i === 0 || at > order[i - 1])),+ `out of order: ${order}`,+ );+ });+}diff --git a/studio/frontend/tests/model-memory-multi-model-mode.test.ts b/studio/frontend/tests/model-memory-multi-model-mode.test.tsnew file mode 100644index 00000000000..e8ff0e9749e--- /dev/null+++ b/studio/frontend/tests/model-memory-multi-model-mode.test.ts@@ -0,0 +1,142 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// "Keep multiple models loaded" is a three-way mode now: Off, When they fit,+// Always. An older backend still answers only {enabled}, so the read has to+// fall back to the bool, and the write sends the mode alone. The chat store+// keeps its bool, so the chat readers stay as they were.++import assert from "node:assert/strict";+import { register } from "node:module";+import test from "node:test";++import ts from "@typescript/typescript6";++import { installLocalStorageFake, readSrc } from "./helpers/kit.ts";+import { openingTag } from "./helpers/tsx-ast.ts";++register("./helpers/settings-api-resolver.mjs", import.meta.url);+installLocalStorageFake();++let nextBody: unknown = {};+const requests: { method: string; body: unknown }[] = [];++globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {+ requests.push({+ method: init?.method ?? "GET",+ body: init?.body ? JSON.parse(String(init.body)) : undefined,+ });+ return new Response(JSON.stringify(nextBody), { status: 200 });+}) as typeof fetch;++const {+ isMultiModelMode,+ keepsModelsLoaded,+ loadMultiModelMode,+ normaliseMultiModelMode,+ updateMultiModelMode,+} = await import("../src/features/settings/api/multi-model.ts");++test("the mode is read tolerantly, and only Off unloads", () => {+ const cases: [unknown, string][] = [+ [{ enabled: false, mode: "always" }, "always"],+ [{ enabled: true, mode: "off" }, "off"],+ [{ enabled: true }, "fit"],+ // A mode this build does not know keeps the bool's answer, not "off".+ [{ enabled: true, mode: "bogus" }, "fit"],+ // biome-ignore lint/style/useNamingConvention: API schema+ [{ enabled: false, default_mode: "always" }, "off"],+ [{ enabled: "yes" }, "off"],+ [{}, "off"],+ [null, "off"],+ ];+ for (const [json, expected] of cases) {+ assert.equal(normaliseMultiModelMode(json), expected, JSON.stringify(json));+ }+ assert.deepEqual(+ ["off", "fit", "always", "Fit", "on", true].map(isMultiModelMode),+ [true, true, true, false, false, false],+ );+ assert.deepEqual((["off", "fit", "always"] as const).map(keepsModelsLoaded), [+ false,+ true,+ true,+ ]);+});++test("a save sends the mode alone; both reads normalise", async () => {+ requests.length = 0;+ nextBody = { enabled: true, mode: "fit" };+ assert.equal(await updateMultiModelMode("fit", "x"), "fit");+ assert.deepEqual(requests, [{ method: "PUT", body: { mode: "fit" } }]);+ nextBody = { enabled: true };+ assert.equal(await updateMultiModelMode("always", "x"), "fit");+ nextBody = { enabled: false, mode: "always" };+ assert.equal(await loadMultiModelMode("x"), "always");+});++// The row, read from the source: the node suite has no DOM.+test("the row is a three-item Select and the idle row closes the section", () => {+ const file = ts.createSourceFile(+ "model-memory-section.tsx",+ readSrc("features/settings/components/model-memory-section.tsx"),+ ts.ScriptTarget.ESNext,+ true,+ ts.ScriptKind.TSX,+ );+ const component = file.statements.find(+ (node): node is ts.FunctionDeclaration =>+ ts.isFunctionDeclaration(node) &&+ node.name?.getText() === "ModelMemorySection",+ );+ assert.ok(component, "ModelMemorySection is declared");+ const tags: ts.JsxOpeningLikeElement[] = [];+ const visit = (node: ts.Node): void => {+ const tag = openingTag(node);+ if (tag) {+ tags.push(tag);+ }+ ts.forEachChild(node, visit);+ };+ visit(component);+ const named = (name: string) =>+ tags.filter((tag) => tag.tagName.getText() === name);+ const attr = (tag: ts.JsxOpeningLikeElement, name: string) =>+ tag.attributes.properties+ .filter(ts.isJsxAttribute)+ .find((p) => p.name.getText() === name)+ ?.initializer?.getText();++ assert.equal(named("Select").length, 1);+ const [trigger] = named("SelectTrigger");+ assert.deepEqual(+ [attr(trigger, "size"), attr(trigger, "className")],+ ['"sm"', '"w-48"'],+ );+ assert.match(attr(trigger, "aria-label") ?? "", /modelMemory\.multiModel"/);+ assert.deepEqual(+ named("SelectItem").map((item) => attr(item, "value")),+ ['"off"', '"fit"', '"always"'],+ );+ for (const sw of named("Switch")) {+ assert.doesNotMatch(attr(sw, "aria-label") ?? "", /multiModel"/);+ }+ // The chat store bool follows the mode: after the read and after a save.+ assert.equal(+ component.getText().match(/setKeepModelsLoaded\(keepsModelsLoaded\(/g)+ ?.length,+ 2,+ );++ const [section] = named("SettingsSection");+ assert.equal(attr(section, "ref"), "{ref}");+ const last = (section.parent as ts.JsxElement).children+ .filter((c) => !(ts.isJsxText(c) && c.containsOnlyTriviaWhiteSpaces))+ .at(-1);+ const lastTag = last ? openingTag(last) : null;+ assert.equal(lastTag?.tagName.getText(), "MediaIdleUnloadSetting");+ assert.match(+ lastTag ? (attr(lastTag, "residencyKey") ?? "") : "",+ /keepResident/,+ );+});diff --git a/studio/frontend/tests/settings-search.test.ts b/studio/frontend/tests/settings-search.test.tsindex 6dcbaa863c7..8ef0bc69f46 100644--- a/studio/frontend/tests/settings-search.test.ts+++ b/studio/frontend/tests/settings-search.test.ts@@ -163,3 +163,21 @@ test("the tool output length is found by truncate and limit, by the owner only",assert.ok(renderedSearchEntries(index, "chat", "huggingface", true).includes(TOOL_RESULT_LIMIT_ENTRY));assert.ok(!renderedSearchEntries(index, "chat", "huggingface", false).includes(TOOL_RESULT_LIMIT_ENTRY));});++test("the multi-model, image/video idle and keepKv rows are found where they render", () => {+ const index = createSettingsSearchIndex({ desktop: false, closeToTray: false });+ const rows = [+ ["resources", "settings.resources.modelMemory.multiModel", "settings.resources.modelMemory.multiModelKeywords", "evict"],+ ["resources", "settings.general.modelAutoSwitch.mediaIdleUnload", "settings.resources.modelMemory.mediaIdleUnloadKeywords", "ttl"],+ ["api-keys", "settings.general.modelAutoSwitch.keepKv", "settings.general.modelAutoSwitch.keepKvKeywords", "kv"],+ ] as const;+ for (const [tab, row, keywordsKey, term] of rows) {+ assert.ok(index[tab].includes(row), `${row} is indexed under ${tab}`);+ assert.equal(SETTINGS_SEARCH_KEYWORDS[row], keywordsKey);+ const keywords = keywordsKey.split(".").reduce<unknown>((node, part) => (node as Record<string, unknown>)[part], en);+ assert.ok(String(keywords).includes(term), `${row} matches "${term}"`);+ }+ assert.ok(!index["api-keys"].includes("settings.general.modelAutoSwitch.mediaIdleUnload"));+ // ModelAutoSwitchSection is owner-only on a tab every account sees.+ assert.ok(!renderedSearchEntries(index, "api-keys", "huggingface", false).includes("settings.general.modelAutoSwitch.keepKv"));+});diff --git a/tests/studio/playwright_settings_tabs.py b/tests/studio/playwright_settings_tabs.pyindex b172830dc47..b0d3fc330b6 100644--- a/tests/studio/playwright_settings_tabs.py+++ b/tests/studio/playwright_settings_tabs.py@@ -523,6 +523,22 @@ def run_keystroke_search(page) -> None:report["steps"].append("keystroke-search")+def assert_model_memory_rows() -> None:+ """The image/video idle row moved to Model memory; keepKv renders without a backend."""+ labels = {+ tab: report["tabs"][tab]["settled"].get("labels", []) for tab in ("resources", "api-keys")+ }+ expected = [+ ("resources", "Keep multiple models loaded", True),+ ("resources", "Idle auto-unload for image and video", True),+ ("api-keys", "Idle auto-unload for image and video", False),+ ("api-keys", "Keep chat context across unloads", True),+ ]+ for tab, label, present in expected:+ if (label in labels[tab]) != present:+ fail(f"{tab}: '{label}' {'missing' if present else 'still renders'} ({labels[tab]})")++def run(page) -> None:if CHUNK_FAIL:run_chunk_fail(page)@@ -553,6 +569,7 @@ def run(page) -> None:f"blank frames {obs['blank_frames']}/{obs['frames_sampled']}")report["steps"].append("all-tabs-render")+ assert_model_memory_rows()run_lan_address_actions(page)