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: Load anyway for the unified-memory diffusion refusal, and a capacity fix for its pre-download check (#14379)
Daniel Han34c5203ebbce
diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.pyindex 8008987b6bc..04af24d9f34 100644--- a/studio/backend/core/inference/diffusion.py+++ b/studio/backend/core/inference/diffusion.py@@ -183,6 +183,11 @@ from .diffusion_memory import (prequant_seed_device,raise_on_image_activation_shortfall,raise_on_unified_memory_shortfall,+ scoped_allow_oversized_load,+ UNIFIED_OVERSIZE_REFUSAL_CODE,+ UnifiedMemoryShortfallError,+ unified_capacity_memory,+ unified_memory_refusal_code,reclaimable_snapshot_device_memory,reclaim_host_memory,reclaim_offload_host_memory,@@ -378,6 +383,7 @@ from .diffusion_auto_policy import (family_bf16_components_gb,precision_fallback_allowed,precision_refusal_message,+ companion_bytes_from_declared,resident_bytes_from_declared,resolve_dense_quant_candidate,)@@ -1413,6 +1419,7 @@ class _LoadingState:base_repo: strexpected_bytes: int = 0error: Optional[str] = None+ error_code: Optional[str] = None# Where the companion BYTES land: ``base_repo``, or its mirror when one was swapped in. Never surfaced# (``base_repo`` stays the id status() reports), but the cache scan and the delete guard must look here.fetch_repo: Optional[str] = None@@ -4280,6 +4287,7 @@ class DiffusionBackend:gpu_ordinal: Optional[int] = None,text_encoder_files: Optional[Sequence[str]] = None,vae_file: Optional[str] = None,+ allow_oversized_load: bool = False,_load_token: Optional[int] = None,) -> dict[str, Any]:"""Validate, then run the (slow) load on a daemon thread. Returns at once."""@@ -4393,6 +4401,7 @@ class DiffusionBackend:gpu_ordinal = gpu_ordinal,text_encoder_files = list(text_encoder_files or ()) or None,vae_file = vae_file,+ allow_oversized_load = bool(allow_oversized_load),_load_token = token,_cancel_event = cancel_event,_gpu_ordinals = gpu_ordinals,@@ -4401,6 +4410,7 @@ class DiffusionBackend:).start()return self.status()+ @scoped_allow_oversized_load# The multi-GPU selection (begin_load's ``_gpu_ordinals``) is visible to this load's planner and placement only.@with_load_selection@scoped_local_files_only@@ -4682,7 +4692,7 @@ class DiffusionBackend:"diffusion.memory: refusing oversized unified-memory load before download: %s",shortfall,)- raise RuntimeError(shortfall)+ raise UnifiedMemoryShortfallError(shortfall)# Outside the lock: a disk scan, and nothing of ours has written to the artifact repo yet.asset_baseline = self._cache_bytes(dit_prequant[0]) if skip_transformer_weights else 0planned_files = _planned_progress_files(@@ -4809,6 +4819,7 @@ class DiffusionBackend:with self._load_cancel_lock:if self._load_token == token and self._loading is not None:self._loading.error = redact_native_paths(text)+ self._loading.error_code = unified_memory_refusal_code(exc)finally:# Nothing else knows when the prefetch returned, so this is the drain's only owner.with self._load_cancel_lock:@@ -4818,7 +4829,7 @@ class DiffusionBackend:"""Phase + downloaded/total bytes for the in-flight load (cache-scan based)."""loading = self._loadingif loading is not None and loading.error:- return _progress("error", error = loading.error)+ return _progress("error", error = loading.error, error_code = loading.error_code)if loading is None:return _progress("ready" if self._state is not None else None)finalized = loading.finalized_scan@@ -6097,6 +6108,7 @@ class DiffusionBackend:ref_size = _hub_file_size(ref.repo_id, ref.filename, hf_token)required_total += ref_sizeadd_missing_entry(ref.repo_id, [ref.filename], {ref.filename: ref_size})+ incompatible_code: Optional[str] = Noneif incompatible is None and allow_device_probe and memory_verdict:incompatible = self.declared_footprint_shortfall(fam,@@ -6116,12 +6128,15 @@ class DiffusionBackend:memory_mode = load_kwargs.get("memory_mode"),cpu_offload = bool(load_kwargs.get("cpu_offload")),)+ if incompatible is not None:+ incompatible_code = UNIFIED_OVERSIZE_REFUSAL_CODEreturn {"entries": entries,"total_bytes": sum(entry["bytes"] for entry in entries),"required_bytes": int(required_total),"checkpoint_bytes": checkpoint_bytes,"incompatible_reason": incompatible,+ "incompatible_code": incompatible_code,# Companion discovery failed, so the file list above is partial. The UI stages what it can and the loader# pulls the rest inline; a caller that must not download at all has to treat this plan as unverified# rather than as nothing missing.@@ -6995,6 +7010,7 @@ class DiffusionBackend:return DiffusionBackend._union_over_cached_revs(base, _params, staged_dir) * 2@_invalidates_gpu_memory("diffusion load")+ @scoped_allow_oversized_load@rocm_probe_load_scoped@_account_owned_load@_plans_at_requested_speed@@ -7023,6 +7039,8 @@ class DiffusionBackend:model_kind: Optional[str] = None,loras: Optional[list[tuple[str, float]]] = None,gpu_ordinal: Optional[int] = None,+ # Read by ``scoped_allow_oversized_load``.+ allow_oversized_load: bool = False,_load_token: Optional[int] = None,_base_local_dir: Optional[str] = None,# True when the prefetch staged the base repo's ``transformer/`` shards, the only condition under which the@@ -10692,13 +10710,22 @@ class DiffusionBackend:)if not resident_bytes:return None- capacity = replace(device_memory, free_mib = device_memory.total_mib)+ capacity = unified_capacity_memory(device_memory)resident_mib = int(resident_bytes) // (1024 * 1024)+ # Plain pipelines only: pre-cast or separately hosted parts are not split by file here.+ companion_bytes = (+ companion_bytes_from_declared(base, declared_files, dtype_scale = dtype_scale)+ if not prequant_bytes and not extra_bf16_bytes+ else None+ )variant_hint = _image_variant_hint(fam.name, gguf_filename, repo_id, base)plan = plan_diffusion_memory(target = target,device_memory = capacity,model_dense_mib = resident_mib,+ companion_dense_mib = (+ None if companion_bytes is None else int(companion_bytes) // (1024 * 1024)+ ),runtime_headroom_mib = estimate_image_runtime_mib(width = None, height = None, family = variant_hint),@@ -13458,6 +13485,7 @@ def _progress(fraction: float = 0.0,*,error: Optional[str] = None,+ error_code: Optional[str] = None,) -> dict[str, Any]:return {"phase": phase,@@ -13465,6 +13493,7 @@ def _progress("bytes_total": bytes_total,"fraction": fraction,"error": error,+ "error_code": error_code,}diff --git a/studio/backend/core/inference/diffusion_auto_policy.py b/studio/backend/core/inference/diffusion_auto_policy.pyindex 435a4136194..c0ac64219bd 100644--- a/studio/backend/core/inference/diffusion_auto_policy.py+++ b/studio/backend/core/inference/diffusion_auto_policy.py@@ -172,6 +172,27 @@ def resident_bytes_from_declared(return int(dtype_resident * dtype_scale) + prequant_bytes+def companion_bytes_from_declared(+ base_repo: Optional[str],+ declared_files: Any,+ *,+ dtype_scale: float = 1.0,+) -> Optional[int]:+ """Non-denoiser (text encoder, VAE) share of ``resident_bytes_from_declared``; None when none declared."""+ _denoiser_factor, companion_factor = _BASE_RESIDENT_FACTORS.get(+ _base_key(base_repo) if base_repo else "", (1.0, 1.0)+ )+ # An SDXL-style UNet is a denoiser too.+ companions = sum(+ max(0, int(size or 0))+ for path, size in (declared_files or ())+ if not str(path).startswith(DENOISER_SUBFOLDERS + ("unet/",))+ )+ if companions <= 0:+ return None+ return int(int(companions / max(companion_factor, 0.01)) * max(1.0, float(dtype_scale or 1.0)))++def _base_key(base_repo: Optional[str]) -> str:"""Return the canonical, case-insensitive key used by per-base tables."""from .diffusion_families import canonical_basediff --git a/studio/backend/core/inference/diffusion_memory.py b/studio/backend/core/inference/diffusion_memory.pyindex 3a294c9790c..831700df95b 100644--- a/studio/backend/core/inference/diffusion_memory.py+++ b/studio/backend/core/inference/diffusion_memory.py@@ -16,6 +16,8 @@ lazily.from __future__ import annotations+import contextlib+import contextvarsimport functoolsimport osimport sys@@ -1670,37 +1672,109 @@ def total_capacity_budget_mib(memory: DeviceMemory) -> Optional[int]:# Opt-in escape hatch for the unified-memory refusal below: the shortfall check is an estimate, so an operator who-# believes it is wrong can still attempt the load.+# believes it is wrong can still attempt the load. Desktop / API callers send ``allow_oversized_load`` per load instead.UNIFIED_OVERSIZE_ENV = "UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD"+UNIFIED_OVERSIZE_REQUEST_FIELD = "allow_oversized_load"+# Must match the Settings switch label and location in frontend unified-memory-load-refusal.ts.+UNIFIED_OVERSIZE_SETTING_LABEL = "Allow oversized model loads"+UNIFIED_OVERSIZE_SETTING_LOCATION = "Settings > System > Model memory"+UNIFIED_OVERSIZE_REFUSAL_CODE = "unified-memory-load"++# Unlike the env var, the per-load flag does NOT lift the MPS allocator cap: that cap is process-wide and set once,+# and keeping it turns an over-commit into an MPS OOM rather than the OS killing the process.+_UNIFIED_OVERSIZE_REQUESTED: contextvars.ContextVar[bool] = contextvars.ContextVar(+ "unsloth_diffusion_allow_oversized_load", default = False+)-def _unified_oversize_override() -> bool:+class UnifiedMemoryShortfallError(RuntimeError):+ """A RuntimeError so existing handlers still catch it."""++ code = UNIFIED_OVERSIZE_REFUSAL_CODE+++def unified_memory_refusal_code(exc: Optional[BaseException]) -> Optional[str]:+ """``UNIFIED_OVERSIZE_REFUSAL_CODE`` when ``exc`` is, or was raised from, the unified-memory refusal."""+ seen: set[int] = set()+ while exc is not None and id(exc) not in seen:+ if isinstance(exc, UnifiedMemoryShortfallError):+ return UNIFIED_OVERSIZE_REFUSAL_CODE+ seen.add(id(exc))+ exc = exc.__cause__ or exc.__context__+ return None+++def unified_oversize_requested(allowed: Any):+ """Per-load ``UNIFIED_OVERSIZE_ENV``; a ContextVar so concurrent loads / plans on other threads are unaffected."""+ token = _UNIFIED_OVERSIZE_REQUESTED.set(bool(allowed))+ try:+ yield+ finally:+ _UNIFIED_OVERSIZE_REQUESTED.reset(token)+++def unified_oversize_scoped(allowed: Any, fn: Callable[..., Any]) -> Callable[..., Any]:+ @functools.wraps(fn)+ def _scoped(*args: Any, **kwargs: Any) -> Any:+ with unified_oversize_requested(allowed):+ return fn(*args, **kwargs)++ return _scoped+++def scoped_allow_oversized_load(fn: Callable[..., Any]) -> Callable[..., Any]:+ """Kwarg is read, not popped, so ``fn`` keeps it in its signature; nested calls keep an outer True."""++ @functools.wraps(fn)+ def _wrapper(*args: Any, **kwargs: Any) -> Any:+ allowed = (+ bool(kwargs.get(UNIFIED_OVERSIZE_REQUEST_FIELD)) or _UNIFIED_OVERSIZE_REQUESTED.get()+ )+ with unified_oversize_requested(allowed):+ return fn(*args, **kwargs)++ return _wrapper+++def _unified_oversize_env() -> bool:return os.environ.get(UNIFIED_OVERSIZE_ENV, "").strip().lower() in ("1", "true", "yes", "on")-def unified_memory_shortfall_message(plan: Any, *, family: Optional[str] = None) -> Optional[str]:- """On UNIFIED device memory, a user-facing refusal when the WEIGHTS alone cannot fit the safe- budget (else None).+def _unified_oversize_override() -> bool:+ return _UNIFIED_OVERSIZE_REQUESTED.get() or _unified_oversize_env()- Unified memory is the one placement with no fallback left. On discrete VRAM an oversized model- still loads, degrading to group / whole-module CPU offload and streaming from host RAM. On Apple- Silicon (and integrated CUDA) the CPU and GPU share one pool, so offload moves bytes within that- pool and frees nothing: ``plan_diffusion_memory`` correctly returns ``none`` and the load then- allocates past physical memory. ``apply_mps_memory_cap`` bounds MPS allocations just below RAM,- but that only turns the overrun into a late OOM after minutes of loading (and integrated CUDA has- no such cap), so refusing up front is still the better failure.- Weights only (``model_dense_mib`` plus the flat base overhead): the per-call runtime headroom is- a coarse activation / VAE-decode estimate and the mps path already turns on VAE tiling and- slicing, so counting it would refuse marginal loads that would in fact complete. The weights are- unavoidable resident bytes, and if they alone do not fit then nothing at generation time can- rescue the load. Same reasoning as the llama.cpp APU guard.+def _unified_oversize_source() -> str:+ if _UNIFIED_OVERSIZE_REQUESTED.get():+ return UNIFIED_OVERSIZE_REQUEST_FIELD+ return f"{UNIFIED_OVERSIZE_ENV}=1"- Fail-open on anything unknown (no budget, no size), matching the planner's own "budget or model- size unknown; staying resident".- """- if _unified_oversize_override():- return None++def unified_capacity_memory(memory: DeviceMemory) -> DeviceMemory:+ """``memory`` at CAPACITY (free = total), so the verdict does not depend on what is loaded right now.++ On mps the snapshot picks the RAM or working-set view from the CURRENT free reading; re-read RAM here so the+ same pick is not judged against the smaller working set just because something is resident."""+ capacity = replace(memory, free_mib = memory.total_mib)+ if getattr(memory, "device", None) != "mps" or memory.metal_working_set_mib is None:+ return capacity+ try:+ total, _free = _system_memory_mib()+ except Exception: # noqa: BLE001 - no RAM reading: keep the working-set view+ return capacity+ if total is None:+ return capacity+ ram = DeviceMemory(memory.backend, memory.device, "unified_memory", int(total), int(total))+ ram_budget = _safe_device_budget_mib(ram)+ capacity_budget = _safe_device_budget_mib(capacity)+ if ram_budget is not None and (capacity_budget is None or ram_budget > capacity_budget):+ return ram+ return capacity+++def _unified_memory_shortfall_text(plan: Any, family: Optional[str]) -> Optional[str]:+ """Ignores the overrides."""try:memory = plan.device_memory# ``system_memory`` (plain CPU) is deliberately excluded: it is an opt-in fringe path, it has swap, and it is@@ -1741,6 +1815,14 @@ def unified_memory_shortfall_message(plan: Any, *, family: Optional[str] = None)"the main model will not fit either. Use a smaller model, or free memory by closing ""other applications.")+ elif companions and int(companions) < int(weights) and int(budget) - floor >= 1024:+ room = int(budget) - floor+ advice = (+ f"Its text encoders and VAE need about {floor / 1024:.0f} GB, which leaves room for a "+ f"main model of up to about {room / 1024:.0f} GB: use a lower GGUF quant (or another "+ "quantized build) of this model at or below that size, or free memory by closing "+ "other applications."+ )else:advice = ("Use a smaller or more quantized model (for example a lower GGUF quant), or free memory "@@ -1753,12 +1835,42 @@ def unified_memory_shortfall_message(plan: Any, *, family: Optional[str] = None)f"about {int(budget) / 1024:.{digits}f} GB is usable on this device ({free_note}). This device ""has unified memory, so the CPU and GPU share one pool: offloading weights to the CPU ""frees nothing, and the operating system stops an oversized load outright instead of "- f"reporting an out-of-memory error. {advice} (Server "- f"installs that know this estimate is wrong can set {UNIFIED_OVERSIZE_ENV}=1 to attempt "- "the load anyway.)"+ f"reporting an out-of-memory error. {advice} The size is an estimate. To try anyway, "+ f"choose Load anyway, or turn on '{UNIFIED_OVERSIZE_SETTING_LABEL}' in "+ f"{UNIFIED_OVERSIZE_SETTING_LOCATION} (API callers can send {UNIFIED_OVERSIZE_REQUEST_FIELD}; "+ f"server installs can set {UNIFIED_OVERSIZE_ENV}=1). An oversized load can exhaust memory, "+ "swap heavily, stop Studio or make the computer unresponsive.")+def unified_memory_shortfall_message(plan: Any, *, family: Optional[str] = None) -> Optional[str]:+ """On UNIFIED device memory, a user-facing refusal when the WEIGHTS alone cannot fit the safe+ budget (else None).++ Unified memory is the one placement with no fallback left. On discrete VRAM an oversized model+ still loads, degrading to group / whole-module CPU offload and streaming from host RAM. On Apple+ Silicon (and integrated CUDA) the CPU and GPU share one pool, so offload moves bytes within that+ pool and frees nothing: ``plan_diffusion_memory`` correctly returns ``none`` and the load then+ allocates past physical memory. ``apply_mps_memory_cap`` bounds MPS allocations just below RAM,+ but that only turns the overrun into a late OOM after minutes of loading (and integrated CUDA has+ no such cap), so refusing up front is still the better failure.++ Weights only (``model_dense_mib`` plus the flat base overhead): the per-call runtime headroom is+ a coarse activation / VAE-decode estimate and the mps path already turns on VAE tiling and+ slicing, so counting it would refuse marginal loads that would in fact complete. The weights are+ unavoidable resident bytes, and if they alone do not fit then nothing at generation time can+ rescue the load. Same reasoning as the llama.cpp APU guard.++ None under the env var or a per-load ``allow_oversized_load``, as the loaders' speculative probes also see.++ Fail-open on anything unknown (no budget, no size), matching the planner's own "budget or model+ size unknown; staying resident".+ """+ if _unified_oversize_override():+ return None+ return _unified_memory_shortfall_text(plan, family)++def raise_on_unified_memory_shortfall(plan: Any,*,@@ -1773,13 +1885,22 @@ def raise_on_unified_memory_shortfall(both re-plan against a settled snapshot), and a planner that raised would turn those probesinto load failures instead of letting a smaller candidate win. Call this once, on the planthe loader has committed to, after the previous pipeline has been evicted so the free- reading is the memory the load actually gets."""- message = unified_memory_shortfall_message(plan, family = family)+ reading is the memory the load actually gets. Under an override the+ load proceeds with a warning."""+ message = _unified_memory_shortfall_text(plan, family)if message is None:return+ if _unified_oversize_override():+ if logger is not None:+ logger.warning(+ "diffusion.memory: loading past the unified-memory estimate (%s): %s",+ _unified_oversize_source(),+ message,+ )+ returnif logger is not None:logger.error("diffusion.memory: refusing oversized unified-memory load: %s", message)- raise RuntimeError(message)+ raise UnifiedMemoryShortfallError(message)def _sum_required(*values: Optional[int]) -> Optional[int]:diff --git a/studio/backend/core/inference/mlx_diffusion_backend.py b/studio/backend/core/inference/mlx_diffusion_backend.pyindex 63cda6b808f..3c08cc02849 100644--- a/studio/backend/core/inference/mlx_diffusion_backend.py+++ b/studio/backend/core/inference/mlx_diffusion_backend.py@@ -660,6 +660,7 @@ class MlxDiffusionBackend:loras: Optional[list[tuple[str, float]]] = None,gpu_ids: Optional[list[int]] = None,gpu_ordinal: Optional[int] = None,+ allow_oversized_load: bool = False,**_ignored: Any,) -> dict[str, Any]:if isinstance(hf_token, str):diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.pyindex 1804d47ecc9..05a8142c3cc 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -3191,6 +3191,8 @@ class SdCppDiffusionBackend:gpu_ids: Optional[list[int]] = None,# The ordinal the ROUTE already ranked, so the preflight and the load agree on one cardgpu_ordinal: Optional[int] = None,+ # Accepted for parity; native never raises the unified-memory refusal.+ allow_oversized_load: bool = False,) -> dict[str, Any]:"""Validate, then fetch assets on a daemon thread. Returns at once."""# Empty/whitespace token = "no token"; "" verbatim breaks the anonymous fallback.diff --git a/studio/backend/core/inference/video.py b/studio/backend/core/inference/video.pyindex 5479a46cf7b..bba15a4094d 100644--- a/studio/backend/core/inference/video.py+++ b/studio/backend/core/inference/video.py@@ -136,6 +136,8 @@ from .diffusion_memory import (plan_diffusion_memory,plan_keeps_transformer_resident,raise_on_unified_memory_shortfall,+ scoped_allow_oversized_load,+ unified_memory_refusal_code,reclaim_host_memory,reclaim_offload_host_memory,refine_memory_plan_for_components,@@ -1472,6 +1474,7 @@ class _VideoLoadingState:base_repo: strexpected_bytes: Optional[int] = Noneerror: Optional[str] = None+ error_code: Optional[str] = None# Companion repos this load is ALSO pulling from, beyond repo_id / base_repo (the native H3 GGUF and component# repos). Mirrors the image backend's _SdLoading.asset_repos.asset_repos: tuple[str, ...] = ()@@ -4283,6 +4286,7 @@ class VideoBackend:gpu_ids: Optional[list[int]] = None,# The ordinal the ROUTE already ranked, so the preflight and the load agree on one cardgpu_ordinal: Optional[int] = None,+ allow_oversized_load: bool = False,) -> dict[str, Any]:"""Validate, then run the (slow) load on a daemon thread. Returns at once."""hf_token = (hf_token.strip() if isinstance(hf_token, str) else hf_token) or None@@ -4406,6 +4410,7 @@ class VideoBackend:model_kind = model_kind,h3_task = h3_task,gpu_ordinal = gpu_ordinal,+ allow_oversized_load = bool(allow_oversized_load),_load_token = token,_cancel_event = cancel_event,_gpu_ordinals = gpu_ordinals,@@ -4414,6 +4419,7 @@ class VideoBackend:).start()return self.status()+ @scoped_allow_oversized_load# The multi-GPU selection (begin_load's ``_gpu_ordinals``) is visible to this load's planner and placement only.@with_load_selection@scoped_local_files_only@@ -4906,6 +4912,7 @@ class VideoBackend:with self._lock:if self._load_token == token and self._loading is not None:self._loading.error = modelscope_missing(exc) or redact_native_paths(str(exc))+ self._loading.error_code = unified_memory_refusal_code(exc)def _run_load_h3_native(self,@@ -7641,7 +7648,7 @@ class VideoBackend:"""Phase + downloaded/total bytes for the in-flight load (cache-scan based)."""loading = self._loadingif loading is not None and loading.error:- return _progress("error", error = loading.error)+ return _progress("error", error = loading.error, error_code = loading.error_code)if loading is None:return _progress("ready" if self._state is not None else None)# The load's own plan, settled once at estimate time by the worker that owns this state: the repo + revision@@ -7721,6 +7728,7 @@ class VideoBackend:raise RuntimeError("Video load was cancelled or superseded.")@_invalidates_gpu_memory("video load")+ @scoped_allow_oversized_load@rocm_probe_load_scoped@scoped_local_files_onlydef load_pipeline(@@ -7743,6 +7751,8 @@ class VideoBackend:model_kind: Optional[str] = None,h3_task: Optional[str] = None,gpu_ordinal: Optional[int] = None,+ # Read by ``scoped_allow_oversized_load``.+ allow_oversized_load: bool = False,_load_token: Optional[int] = None,_base_local_dir: Optional[str] = None,_base_fetch_repo: Optional[str] = None,diff --git a/studio/backend/models/inference.py b/studio/backend/models/inference.pyindex bef6e2c29dc..4987ab0ca73 100644--- a/studio/backend/models/inference.py+++ b/studio/backend/models/inference.py@@ -4593,6 +4593,13 @@ class DiffusionLoadRequest(BaseModel):"cut), low_vram (offload every component, lowest VRAM, slower). ""Overrides cpu_offload when set.",)+ allow_oversized_load: bool = Field(+ False,+ description = "Attempt the load even when the unified-memory check (Apple Silicon, integrated "+ "GPUs) estimates its weights will not fit. The check stays on by default; an oversized load "+ "can exhaust memory, swap heavily, stop the server or make the computer unresponsive. Same "+ "effect as the server's UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1, for this load only.",+ )speed_mode: Optional[Literal["off", "eager", "default", "max"]] = Field(None,description = "Opt-in speed optims (default off -> bit-identical output): "@@ -5415,6 +5422,11 @@ class DiffusionLoadProgressResponse(BaseModel):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]")error: Optional[str] = Field(None, description = "Failure message when phase is 'error'")+ error_code: Optional[str] = Field(+ None,+ description = "Stable code for error: 'unified-memory-load' when the unified-memory check refused "+ "the load (retry with allow_oversized_load to attempt it anyway); null otherwise.",+ )class DiffusionResolvedControl(BaseModel):@@ -5517,6 +5529,11 @@ class DiffusionDownloadPlanResponse(BaseModel):"nothing is known to be wrong -- the check reads metadata only and stays silent on an ""unreadable header, an unmapped base or an offline host.",)+ incompatible_code: Optional[str] = Field(+ None,+ description = "Stable code for incompatible_reason: 'unified-memory-load' when the unified-memory "+ "check refused the pick (send allow_oversized_load to attempt it anyway); null otherwise.",+ )class DiffusionStatusResponse(BaseModel):@@ -6619,6 +6636,13 @@ class VideoLoadRequest(BaseModel):"(stream the transformer, near-resident speed, moderate VRAM cut), low_vram ""(offload every component, lowest VRAM, slower).",)+ allow_oversized_load: bool = Field(+ False,+ description = "Attempt the load even when the unified-memory check (Apple Silicon, integrated "+ "GPUs) estimates its weights will not fit. The check stays on by default; an oversized load "+ "can exhaust memory, swap heavily, stop the server or make the computer unresponsive. Same "+ "effect as the server's UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1, for this load only.",+ )speed_mode: Optional[Literal["off", "eager", "default", "max"]] = Field(None,description = "Opt-in speed optims (default off -> bit-identical output): "@@ -7054,6 +7078,11 @@ class VideoLoadProgressResponse(BaseModel):None, description = "Estimated total bytes to download (null = unknown)")error: Optional[str] = Field(None, description = "Failure message when phase is 'error'")+ error_code: Optional[str] = Field(+ None,+ description = "Stable code for error: 'unified-memory-load' when the unified-memory check refused "+ "the load (retry with allow_oversized_load to attempt it anyway); null otherwise.",+ )class VideoGenerationDefaults(BaseModel):diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex b2aec809672..8d6c89794b4 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -50956,8 +50956,10 @@ async def diffusion_download_plan(text_encoder_files = request.supplied_text_encoder_files(),gguf_filename = request.gguf_filename,)+ from core.inference.diffusion_memory import unified_oversize_scoped+plan = await asyncio.to_thread(- planner.download_plan,+ unified_oversize_scoped(request.allow_oversized_load, planner.download_plan),request.model_path,gpu_ordinal = gpu_ordinal,gguf_filename = request.gguf_filename,@@ -51474,6 +51476,8 @@ async def load_diffusion_model_gated(# different card from free VRAM that has moved since.gpu_ordinal = gpu_ordinal,**_component_file_kwargs(request),+ # Only when set: the native engines take no such argument.+ **({"allow_oversized_load": True} if request.allow_oversized_load else {}),)# A warm start that took the generation slot between the stop above and begin_load publishing the load would# bring the old model's upsampler up beside this one: cancel it now that the load is visible.diff --git a/studio/backend/routes/video.py b/studio/backend/routes/video.pyindex a0c6d987f19..ec4ebce4d81 100644--- a/studio/backend/routes/video.py+++ b/studio/backend/routes/video.py@@ -462,6 +462,7 @@ async def load_video_model_gated(# The winner this route already ranked and preflighted, so the load cannot pick a# different card from free VRAM that has moved since.gpu_ordinal = gpu_ordinal,+ allow_oversized_load = request.allow_oversized_load,)def _begin_load():diff --git a/studio/backend/tests/test_diffusion_unified_load_override.py b/studio/backend/tests/test_diffusion_unified_load_override.pynew file mode 100644index 00000000000..77f268dc952--- /dev/null+++ b/studio/backend/tests/test_diffusion_unified_load_override.py@@ -0,0 +1,406 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Unified-memory load refusal (#14267) and the per-load ``allow_oversized_load`` opt-in."""++from __future__ import annotations++import asyncio+import threading+import types++import pytest++from core.inference import diffusion as diffusion_mod+from core.inference import diffusion_memory as dm+from core.inference import video as video_mod+from core.inference.diffusion import DiffusionBackend, _LoadingState+from core.inference.diffusion_device import DiffusionDeviceTarget+from core.inference.diffusion_memory import (+ UNIFIED_OVERSIZE_ENV,+ UNIFIED_OVERSIZE_REFUSAL_CODE,+ DeviceMemory,+ UnifiedMemoryShortfallError,+ plan_diffusion_memory,+ raise_on_unified_memory_shortfall,+ scoped_allow_oversized_load,+ unified_memory_refusal_code,+ unified_memory_shortfall_message,+ unified_oversize_requested,+ unified_oversize_scoped,+)++MIB = 1024 * 1024+GIB_MIB = 1024++# Qwen/Qwen-Image sizes from Hub metadata.+QWEN_IMAGE = [+ ("transformer/diffusion_pytorch_model.safetensors", 40_861_227_138),+ ("text_encoder/model.safetensors", 16_584_475_660),+ ("vae/diffusion_pytorch_model.safetensors", 253_807_696),+]+MAC_64_GIB = 64 * GIB_MIB+MAC_64_WORKING_SET = 48 * GIB_MIB++[email protected](autouse = True)+def _no_env_override(monkeypatch):+ monkeypatch.delenv(UNIFIED_OVERSIZE_ENV, raising = False)+++def _target(device: str = "mps") -> DiffusionDeviceTarget:+ return DiffusionDeviceTarget(+ device = device,+ dtype = "bfloat16",+ backend = device,+ vendor = "apple" if device == "mps" else "nvidia",+ supports_model_cpu_offload = device == "cuda",+ supports_default_torch_compile = False,+ supports_pinned_transfer = device == "cuda",+ )+++def _backend(+ monkeypatch,+ snapshot: DeviceMemory,+ *,+ ram_total_mib: int | None = None,+):+ backend = DiffusionBackend()+ target = _target(snapshot.device)+ monkeypatch.setattr(backend, "_target_for_ordinal", lambda *_a, **_k: target)+ monkeypatch.setattr(diffusion_mod, "snapshot_device_memory", lambda _t: snapshot)+ if ram_total_mib is not None:+ monkeypatch.setattr(dm, "_system_memory_mib", lambda: (ram_total_mib, 1024))+ return backend+++def _qwen_verdict(backend, files = QWEN_IMAGE):+ fam = types.SimpleNamespace(name = "qwen-image", base_repo = "Qwen/Qwen-Image")+ return backend.declared_footprint_shortfall(+ fam, "Qwen/Qwen-Image", "Qwen/Qwen-Image", kind = "pipeline", declared_files = files+ )+++def _plan(+ weights_mib: int,+ *,+ total_mib: int = 16 * GIB_MIB,+ companions_mib = None,+):+ memory = DeviceMemory("mps", "mps", "unified_memory", total_mib, total_mib)+ return plan_diffusion_memory(+ target = _target(),+ device_memory = memory,+ model_dense_mib = weights_mib,+ runtime_headroom_mib = 0,+ companion_dense_mib = companions_mib,+ )+++# --- sizing -----------------------------------------------------------------------------------------------------+++def test_qwen_image_on_a_64_gib_unified_pool_reproduces_the_report_and_names_the_room_left(+ monkeypatch,+):+ # The issue's numbers: 55,026 MiB weights + 2 GiB overhead vs 64 GiB minus the 20% reserve.+ snapshot = DeviceMemory("mps", "mps", "unified_memory", MAC_64_GIB, MAC_64_GIB)+ message = _qwen_verdict(_backend(monkeypatch, snapshot))+ assert message is not None+ assert "needs about 56 GB of memory for its weights" in message+ assert "only about 51 GB is usable" in message+ assert "currently free" not in message+ assert "Its text encoders and VAE need about 18 GB" in message+ assert "main model of up to about 34 GB" in message+++def test_the_pre_download_capacity_view_on_a_mac_does_not_depend_on_what_is_free_now(monkeypatch):+ # 44,200 MiB of weights: fits RAM minus 20% (52,428 MiB) but not 85% of the 48 GiB working set (41,779 MiB).+ files = [+ ("transformer/diffusion_pytorch_model.safetensors", 38_000 * MIB),+ ("text_encoder/model.safetensors", 6_000 * MIB),+ ("vae/diffusion_pytorch_model.safetensors", 200 * MIB),+ ]+ idle = DeviceMemory("mps", "mps", "unified_memory", 60 * GIB_MIB, MAC_64_GIB)+ assert _qwen_verdict(_backend(monkeypatch, idle), files) is None+ # With a model loaded the snapshot returns the working-set view; the capacity verdict must not flip.+ busy = DeviceMemory(+ "mps",+ "mps",+ "unified_memory",+ 20 * GIB_MIB,+ MAC_64_WORKING_SET,+ metal_working_set_mib = MAC_64_WORKING_SET,+ )+ assert _qwen_verdict(_backend(monkeypatch, busy, ram_total_mib = MAC_64_GIB), files) is None+++def test_a_load_past_ram_capacity_is_still_refused_from_the_working_set_view(monkeypatch):+ busy = DeviceMemory(+ "mps",+ "mps",+ "unified_memory",+ 20 * GIB_MIB,+ MAC_64_WORKING_SET,+ metal_working_set_mib = MAC_64_WORKING_SET,+ )+ message = _qwen_verdict(_backend(monkeypatch, busy, ram_total_mib = MAC_64_GIB))+ assert message is not None and "about 51 GB is usable" in message+++def test_capacity_view_keeps_the_working_set_when_ram_cannot_be_read(monkeypatch):+ busy = DeviceMemory(+ "mps",+ "mps",+ "unified_memory",+ 1024,+ MAC_64_WORKING_SET,+ metal_working_set_mib = MAC_64_WORKING_SET,+ )+ monkeypatch.setattr(dm, "_system_memory_mib", lambda: (None, None))+ assert dm.unified_capacity_memory(busy).free_mib == MAC_64_WORKING_SET+ assert dm.unified_capacity_memory(busy).total_mib == MAC_64_WORKING_SET+++def test_companion_split_matches_the_resident_total():+ from core.inference.diffusion_auto_policy import (+ companion_bytes_from_declared,+ resident_bytes_from_declared,+ )++ companions = companion_bytes_from_declared("Qwen/Qwen-Image", QWEN_IMAGE)+ total = resident_bytes_from_declared("Qwen/Qwen-Image", QWEN_IMAGE)+ assert companions == 16_584_475_660 + 253_807_696+ assert total - companions == 40_861_227_138+ assert companion_bytes_from_declared("Qwen/Qwen-Image", QWEN_IMAGE[:1]) is None+++def test_a_unet_is_not_counted_as_a_companion():+ from core.inference.diffusion_auto_policy import companion_bytes_from_declared++ companions = (+ ("text_encoder/model.safetensors", 246_144_152),+ ("text_encoder_2/model.safetensors", 1_389_382_176),+ ("vae/diffusion_pytorch_model.safetensors", 334_643_268),+ )+ sdxl = (("unet/diffusion_pytorch_model.safetensors", 5_135_149_760),) + companions+ base = "stabilityai/stable-diffusion-xl-base-1.0"+ assert companion_bytes_from_declared(base, sdxl) == companion_bytes_from_declared(+ base, companions+ )+++# --- the override ----------------------------------------------------------------------------------------------+++def test_default_still_refuses_with_a_coded_runtime_error():+ plan = _plan(20 * GIB_MIB)+ with pytest.raises(UnifiedMemoryShortfallError) as excinfo:+ raise_on_unified_memory_shortfall(plan, family = "qwen-image")+ assert isinstance(excinfo.value, RuntimeError)+ assert excinfo.value.code == UNIFIED_OVERSIZE_REFUSAL_CODE == "unified-memory-load"+ message = str(excinfo.value)+ assert "Load anyway" in message+ assert "'Allow oversized model loads' in Settings > System > Model memory" in message+ assert "allow_oversized_load" in message+ assert f"{UNIFIED_OVERSIZE_ENV}=1" in message+++def test_the_request_flag_lifts_the_refusal_for_its_own_scope_only():+ plan = _plan(20 * GIB_MIB)+ assert unified_memory_shortfall_message(plan) is not None+ with unified_oversize_requested(True):+ assert unified_memory_shortfall_message(plan) is None+ raise_on_unified_memory_shortfall(plan) # must not raise+ assert unified_memory_shortfall_message(plan) is not None+ with unified_oversize_requested(False):+ assert unified_memory_shortfall_message(plan) is not None+++def test_the_override_is_never_silent():+ plan = _plan(20 * GIB_MIB)+ warnings: list[tuple] = []+ logger = types.SimpleNamespace(+ warning = lambda *a: warnings.append(a), error = lambda *a: None, info = lambda *a: None+ )+ with unified_oversize_requested(True):+ raise_on_unified_memory_shortfall(plan, family = "qwen-image", logger = logger)+ assert len(warnings) == 1+ assert warnings[0][1] == "allow_oversized_load"+ with unified_oversize_requested(True):+ raise_on_unified_memory_shortfall(_plan(1024), logger = logger)+ assert len(warnings) == 1++[email protected]("value", ["1", "true", "yes", "on"])+def test_the_env_var_still_works(monkeypatch, value):+ plan = _plan(20 * GIB_MIB)+ monkeypatch.setenv(UNIFIED_OVERSIZE_ENV, value)+ assert unified_memory_shortfall_message(plan) is None+ raise_on_unified_memory_shortfall(plan)+++def test_the_flag_does_not_leak_into_another_thread():+ plan = _plan(20 * GIB_MIB)+ seen: list = []+ with unified_oversize_requested(True):+ worker = threading.Thread(+ target = lambda: seen.append(unified_memory_shortfall_message(plan))+ )+ worker.start()+ worker.join()+ assert seen and seen[0] is not None+++def test_asyncio_to_thread_carries_the_flag_into_the_plan_worker():+ plan = _plan(20 * GIB_MIB)++ async def _plan_route():+ with unified_oversize_requested(True):+ return await asyncio.to_thread(unified_memory_shortfall_message, plan)++ assert asyncio.run(_plan_route()) is None+++def test_the_plan_route_wrapper_scopes_the_worker_call():+ plan = _plan(20 * GIB_MIB)++ async def _plan_route(allowed):+ return await asyncio.to_thread(+ unified_oversize_scoped(allowed, unified_memory_shortfall_message), plan+ )++ assert asyncio.run(_plan_route(True)) is None+ assert asyncio.run(_plan_route(False)) is not None+++def test_scoped_decorator_reads_the_kwarg_and_nests():+ @scoped_allow_oversized_load+ def probe(**kwargs):+ return dm._unified_oversize_override()++ assert probe() is False+ assert probe(allow_oversized_load = True) is True+ with unified_oversize_requested(True):+ assert probe(allow_oversized_load = False) is True+++def test_the_code_survives_a_wrapping_exception():+ try:+ try:+ raise UnifiedMemoryShortfallError("too big")+ except UnifiedMemoryShortfallError as inner:+ raise RuntimeError("load failed") from inner+ except RuntimeError as outer:+ assert unified_memory_refusal_code(outer) == UNIFIED_OVERSIZE_REFUSAL_CODE+ assert unified_memory_refusal_code(RuntimeError("other")) is None+ assert unified_memory_refusal_code(None) is None+++# --- API plumbing ----------------------------------------------------------------------------------------------+++def test_request_models_default_off_and_accept_the_flag():+ from models.inference import (+ DiffusionDownloadPlanResponse,+ DiffusionLoadProgressResponse,+ DiffusionLoadRequest,+ VideoLoadProgressResponse,+ VideoLoadRequest,+ )++ assert DiffusionLoadRequest(model_path = "Qwen/Qwen-Image").allow_oversized_load is False+ assert DiffusionLoadRequest(+ model_path = "Qwen/Qwen-Image", allow_oversized_load = True+ ).allow_oversized_load+ assert VideoLoadRequest(model_path = "Lightricks/LTX-2").allow_oversized_load is False+ assert VideoLoadRequest(+ model_path = "Lightricks/LTX-2", allow_oversized_load = True+ ).allow_oversized_load+ assert DiffusionLoadProgressResponse(+ phase = "error", error = "x", error_code = "unified-memory-load"+ ).error_code+ assert VideoLoadProgressResponse(phase = "error", error = "x").error_code is None+ assert DiffusionDownloadPlanResponse(incompatible_code = "unified-memory-load").incompatible_code+++def test_image_begin_load_hands_the_flag_to_the_worker(monkeypatch):+ backend = DiffusionBackend()+ fam = types.SimpleNamespace(+ name = "qwen-image", base_repo = "Qwen/Qwen-Image", single_file_is_pipeline = False+ )+ monkeypatch.setattr(backend, "validate_load_request", lambda *_a, **_k: fam)+ monkeypatch.setattr(backend, "assert_precision_available", lambda *_a, **_k: None)+ monkeypatch.setattr(backend, "status", lambda: {})+ monkeypatch.setattr(diffusion_mod, "auto_cuda_ordinal_for_load", lambda: None)+ started: list[dict] = []++ def _thread(*, target, kwargs, **_k):+ started.append(kwargs)+ return types.SimpleNamespace(start = lambda: None)++ monkeypatch.setattr(diffusion_mod, "account_thread", _thread)+ backend.begin_load("Qwen/Qwen-Image", allow_oversized_load = True)+ assert started[-1]["allow_oversized_load"] is True+ backend._loading = None+ backend.begin_load("Qwen/Qwen-Image")+ assert started[-1]["allow_oversized_load"] is False+++def _refusing_detector(seen: list):+ def _detect(*_a, **_k):+ seen.append(dm._unified_oversize_override())+ raise UnifiedMemoryShortfallError("'qwen-image' needs about 56 GB")++ return _detect+++def test_image_worker_reports_the_code_and_scopes_the_flag(monkeypatch):+ backend = DiffusionBackend()+ seen: list = []+ monkeypatch.setattr(diffusion_mod, "detect_family_for_pick", _refusing_detector(seen))+ for allowed in (False, True):+ backend._load_token += 1+ backend._loading = _LoadingState(repo_id = "Qwen/Qwen-Image", base_repo = "Qwen/Qwen-Image")+ backend._run_load(+ repo_id = "Qwen/Qwen-Image", _load_token = backend._load_token, allow_oversized_load = allowed+ )+ progress = backend.load_progress()+ assert progress["phase"] == "error"+ assert progress["error_code"] == UNIFIED_OVERSIZE_REFUSAL_CODE+ assert seen == [False, True]+ assert dm._unified_oversize_override() is False+++def test_image_worker_leaves_other_failures_uncoded(monkeypatch):+ backend = DiffusionBackend()++ def _boom(*_a, **_k):+ raise RuntimeError("CUDA out of memory")++ monkeypatch.setattr(diffusion_mod, "detect_family_for_pick", _boom)+ backend._load_token += 1+ backend._loading = _LoadingState(repo_id = "x", base_repo = "y")+ backend._run_load(repo_id = "x", _load_token = backend._load_token)+ assert backend.load_progress()["error_code"] is None+++def test_video_worker_reports_the_code_and_scopes_the_flag(monkeypatch):+ backend = video_mod.VideoBackend()+ seen: list = []+ monkeypatch.setattr(video_mod, "_detect_load_family", _refusing_detector(seen))+ for allowed in (False, True):+ backend._load_token += 1+ backend._loading = video_mod._VideoLoadingState(+ repo_id = "Lightricks/LTX-2", base_repo = "Lightricks/LTX-2"+ )+ backend._run_load(+ repo_id = "Lightricks/LTX-2",+ _load_token = backend._load_token,+ allow_oversized_load = allowed,+ )+ progress = backend.load_progress()+ assert progress["phase"] == "error"+ assert progress["error_code"] == UNIFIED_OVERSIZE_REFUSAL_CODE+ assert seen == [False, True]diff --git a/studio/backend/tests/test_swap_kv_resume.py b/studio/backend/tests/test_swap_kv_resume.pyindex 5e1168ee594..c4913eda333 100644--- a/studio/backend/tests/test_swap_kv_resume.py+++ b/studio/backend/tests/test_swap_kv_resume.py@@ -489,4 +489,5 @@ def test_load_progress_is_unchanged_without_a_save(client, env, monkeypatch, cas"bytes_total": 0,"fraction": 1.0,"error": None,+ "error_code": None,}diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.tsindex 1f044b88809..1240ab1de5a 100644--- a/studio/frontend/scripts/check-bundle-budget.ts+++ b/studio/frontend/scripts/check-bundle-budget.ts@@ -304,8 +304,11 @@ export const BUDGET = {// Token usage tracking (#14076) keeps the saved-count matching, recount scheduling and their review guards in the// eager chat runtime: merged with main at 4e0fe5b99 the build measures 6,857,322 B raw / 2,064,700 B transfer// (Node 24, 96 chunks). Raised to that plus the same 160 B raw / 189 B transfer margin.- transferBytes: 2_064_889,- rawBytes: 6_857_482,+ // The Allow oversized model loads row in Settings (#14379) adds its switch and strings to the eager settings+ // chunk and locale: 1,886 B raw / 628 B transfer (6,857,308 -> 6,859,194 B raw, 2,064,700 -> 2,065,328 B+ // transfer against f1f283a24e, one machine and build, Node 24, 96 chunks). Raised by that, same margin.+ transferBytes: 2_065_517,+ rawBytes: 6_859_354,};// 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/components/load-anyway-dialog.tsx b/studio/frontend/src/components/load-anyway-dialog.tsxnew file mode 100644index 00000000000..d8585dd1331--- /dev/null+++ b/studio/frontend/src/components/load-anyway-dialog.tsx@@ -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++import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+} from "@/components/ui/alert-dialog";+import { toast } from "@/lib/toast";+import {+ LOAD_ANYWAY_CONFIRM_TITLE,+ LOAD_ANYWAY_LABEL,+ LOAD_ANYWAY_WARNING,+ UNIFIED_MEMORY_LOAD_TITLE,+} from "@/lib/unified-memory-load-refusal";+import { type ReactNode, useCallback, useRef, useState } from "react";++interface PendingRetry {+ message: string;+ retry: () => void;+}++/**+ * Load anyway toast: the action only opens a confirmation; only Confirm retries the pick once with the+ * override. ``dismiss`` retires an open prompt when a newer pick or load begins.+ */+export function useLoadAnywayPrompt(): {+ offer: (message: string, retry: () => void) => void;+ dismiss: () => void;+ dialog: ReactNode;+} {+ const [pending, setPending] = useState<PendingRetry | null>(null);+ const toastId = useRef<string | number | null>(null);+ const dismiss = useCallback(() => {+ if (toastId.current !== null) {+ toast.dismiss(toastId.current);+ }+ toastId.current = null;+ setPending(null);+ }, []);+ const offer = useCallback((message: string, retry: () => void) => {+ toastId.current = toast.error(UNIFIED_MEMORY_LOAD_TITLE, {+ description: message,+ duration: 20_000,+ action: {+ label: LOAD_ANYWAY_LABEL,+ onClick: () => setPending({ message, retry }),+ },+ });+ }, []);+ const confirm = () => {+ const current = pending;+ setPending(null);+ current?.retry();+ };+ const dialog = (+ <AlertDialog+ open={pending !== null}+ onOpenChange={(open) => !open && setPending(null)}+ >+ <AlertDialogContent onOverlayClick={() => setPending(null)}>+ <AlertDialogHeader>+ <AlertDialogTitle>{LOAD_ANYWAY_CONFIRM_TITLE}</AlertDialogTitle>+ <AlertDialogDescription className="break-words">+ {LOAD_ANYWAY_WARNING}+ </AlertDialogDescription>+ {pending ? (+ <p className="break-words text-xs text-muted-foreground">+ {pending.message}+ </p>+ ) : null}+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel onClick={() => setPending(null)}>+ Cancel+ </AlertDialogCancel>+ <AlertDialogAction+ variant="destructive"+ onClick={confirm}+ data-testid="load-anyway-confirm"+ >+ {LOAD_ANYWAY_LABEL}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ );+ return { offer, dismiss, dialog };+}diff --git a/studio/frontend/src/features/images/api.ts b/studio/frontend/src/features/images/api.tsindex 753cb64f53b..d8aa1e7bfbf 100644--- a/studio/frontend/src/features/images/api.ts+++ b/studio/frontend/src/features/images/api.ts@@ -5,6 +5,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 { withAllowOversizedLoad } from "@/lib/unified-memory-load-refusal";import {isMemoryEstimateRefusal,MEMORY_REFUSAL_HEADER,@@ -162,6 +163,8 @@ export interface DiffusionLoadProgress {bytes_total: number;fraction: number;error: string | null;+ /** Absent on an older backend. */+ error_code?: string | null;}export interface DiffusionLoadRequest {@@ -217,6 +220,8 @@ export interface DiffusionLoadRequest {// quantisation and compile, so a quantized load that omits them rejects every generation. Ignored by bf16 /// bnb-4bit, which apply at generate time.loras?: LoraSpecInput[];+ // Omitted = refuse as usual; withAllowOversizedLoad fills it from the persisted setting.+ allow_oversized_load?: boolean;}export interface DiffusionGenerateRequest {@@ -414,7 +419,7 @@ export async function loadDiffusionModel(body: DiffusionLoadRequest): Promise<Diawait authFetch("/api/inference/images/load", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),+ body: JSON.stringify(withAllowOversizedLoad(body)),}),),async (signal) => (await getDiffusionLoadProgress(signal)).phase,@@ -443,6 +448,8 @@ export interface DiffusionDownloadPlan {* speak, refuse the pick here, since the alternative is the loader saying the same thing after a ~19 GB* download. */incompatible_reason?: string | null;+ /** Absent on an older backend. */+ incompatible_code?: string | null;}/** What to stage through the download manager before loading this pick. */@@ -453,7 +460,7 @@ export async function getDiffusionDownloadPlan(await authFetch("/api/inference/images/download-plan", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),+ body: JSON.stringify(withAllowOversizedLoad(body)),}),);}diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex 1c812e821fa..77821ab2f71 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -212,6 +212,8 @@ import {routedGgufLabel,} from "@/lib/diffusion-route-search";import { toast } from "@/lib/toast";+import { useLoadAnywayPrompt } from "@/components/load-anyway-dialog";+import { readAllowOversizedLoad, retryWhileCurrent, shouldOfferLoadAnyway } from "@/lib/unified-memory-load-refusal";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";@@ -1506,6 +1508,7 @@ type LoadAdvanced = Pick<| "text_encoder_file"| "vae_file"| "engine"+ | "allow_oversized_load">;function openImageLabel(t: ReturnType<typeof useT>, prompt: string): string {@@ -1730,6 +1733,12 @@ export function ImagesPage({const [livePreviewOff, setLivePreviewOff] = usePersistedToggle("unsloth_images_live_preview_off");const livePreview = !livePreviewOff;const oversizedOnce = useRef(false);+ // Set only around a confirmed Load anyway retry.+ const oversizedLoadOnce = useRef(false);+ const lastLoadAttempt = useRef<{ overrideSent: boolean; retry: () => void } | null>(null);+ // Synced after render (handleLoadRef is written during render).+ const retryLoadRef = useRef<((repoId: string, opts: ImageLoadOptions, pinned?: LoadAdvanced) => Promise<boolean>) | null>(null);+ const { offer: offerLoadAnyway, dismiss: dismissLoadAnyway, dialog: loadAnywayDialog } = useLoadAnywayPrompt();// Queued: "Generate anyway" is clickable before the refused run releases busy.const [oversizedRetryQueued, setOversizedRetryQueued] = useState(false);// Advanced (load-time) options; "auto"/"off"/"none" map to the backend defaults. Changing one@@ -3005,6 +3014,16 @@ export function ImagesPage({setAspectOpen(false);}, [active]);+ const offerLoadAnywayFor = useCallback(+ (failure: unknown, code?: string | null): boolean => {+ const attempt = lastLoadAttempt.current;+ if (!attempt || !shouldOfferLoadAnyway({ code, failure, overrideSent: attempt.overrideSent })) return false;+ offerLoadAnyway(failureMessage(failure) || "Failed to load model", attempt.retry);+ return true;+ },+ [offerLoadAnyway],+ );+// Poll load-progress until the background load reaches "ready" or "error", updating the persistent toast in place.const pollLoadProgress = useCallback(async () => {// This tick's cancellation fence: clearing pollTimer stops the next tick, not the awaits below.@@ -3059,7 +3078,7 @@ export function ImagesPage({pendingRecalledGeneration.current = null;pendingEvicted.current = [];dismissLoadToast();- reportLoadFailure(p.error, "Failed to load model");+ if (!offerLoadAnywayFor(p.error, p.error_code)) reportLoadFailure(p.error, "Failed to load model");setBusy(null);// A load that failed AFTER starting leaves the previous pipeline loaded, so roll the// optimistic quant label back.@@ -3112,7 +3131,7 @@ export function ImagesPage({}if (seq !== cancelSeq.current) return;pollTimer.current = setTimeout(() => void pollLoadProgress(), 1000);- }, [dismissLoadToast, refreshStatus, cancelLoadFromToast]);+ }, [dismissLoadToast, refreshStatus, cancelLoadFromToast, offerLoadAnywayFor]);// Put back what a teardown removed when the load it was tearing down is still running: the// unload failed, so the poll and toast were stopped for nothing. refreshStatus cannot do@@ -3411,6 +3430,8 @@ export function ImagesPage({// unload that can reach the backend first, find no load registered, and stop nothing.const startSeq = cancelSeq.current;const startLoad = ++loadSeq.current;+ // An older pick's Load anyway prompt would retry a model this load supersedes.+ dismissLoadAnyway();// Published now and settled in the finally below, so a cancel waits for the WHOLE path.let settleLoad: () => void = () => {};const inFlight = new Promise<void>((resolve) => {@@ -3470,6 +3491,13 @@ 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 };+ const overrideSent = advanced.allow_oversized_load === true || readAllowOversizedLoad();+ const retryPick = pickSeq.current;+ const retryOversized = retryWhileCurrent(+ () => retryPick === pickSeq.current && startLoad === loadSeq.current,+ () => void retryLoadRef.current?.(repoId, opts, { ...advanced, allow_oversized_load: true }),+ );+ lastLoadAttempt.current = { overrideSent, retry: retryOversized };// 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) {@@ -3500,6 +3528,7 @@ export function ImagesPage({family_override: advanced.family_override,loras: bakeLoras.length > 0 ? bakeLoras : undefined,gpu_ids: advanced.gpu_ids,+ allow_oversized_load: advanced.allow_oversized_load,...componentFiles,});const answer = await startRequest;@@ -3514,7 +3543,7 @@ export function ImagesPage({// Engine select from the resident build rather than replay the refused pick on the next Reapply.setEngineSeed("");dismissLoadToast();- reportLoadFailure(err, "Failed to start load");+ if (!offerLoadAnywayFor(err)) reportLoadFailure(err, "Failed to start load");setBusy(null);void refreshStatus();return settle(false);@@ -3542,7 +3571,7 @@ export function ImagesPage({void pollLoadProgress();return settle(true);},- [pollLoadProgress, refreshStatus, dismissLoadToast, currentLoadAdvanced, cancelLoadFromToast, pickToast, engineFor],+ [pollLoadProgress, refreshStatus, dismissLoadToast, currentLoadAdvanced, cancelLoadFromToast, pickToast, engineFor, offerLoadAnywayFor, dismissLoadAnyway],);// Set or clear the Transform/Inpaint source image; always drop the painted mask, which is@@ -3638,6 +3667,9 @@ export function ImagesPage({toastId?: string;} | null>(null);const handleLoadRef = useRef(handleLoad);+ useEffect(() => {+ retryLoadRef.current = handleLoad;+ }, [handleLoad]);handleLoadRef.current = handleLoad;// Set when a staged download finished while this page was hidden: both diffusion pages stay// mounted and a load evicts whatever holds the GPU. The pick fires on return.@@ -3813,6 +3845,8 @@ export function ImagesPage({// The plan route preflights precision and sizes the file set against the card the load will// use, so a selection the load carries has to reach the plan.gpu_ids: advanced.gpu_ids,+ // A Load anyway retry sends it on the plan too, or the plan refuses the pick again.+ allow_oversized_load: advanced.allow_oversized_load,...componentFileFields(opts.kind, advanced.text_encoder_file, advanced.vae_file),});},@@ -3832,12 +3866,15 @@ export function ImagesPage({): Promise<boolean> => {const downloadOnly =downloadSnapshot !== undefined || (!forceLoad && modelSelectionAction === "download");+ // Read before the first await: a confirmed Load anyway retry sets it only around this call.+ const oversizedRetry = oversizedLoadOnce.current && !downloadOnly;// Staging never sets `busy`, so a second pick passes the guard while this plan is in flight, and// plans resolve in response order rather than pick order. Bumped before the non-hub return too, so// a local pick invalidates an in-flight hub plan. Never for a download-only pick: it supersedes// nothing, and retiring the sequence made the load it interrupted fail its own stale check below// and return silently, leaving the selected model neither staged nor loaded.const pick = downloadOnly ? pickSeq.current : ++pickSeq.current;+ if (!downloadOnly) dismissLoadAnyway();// The previous pick's staged intent dies with it: a pick that stages nothing never calls// stage(), so the queue keeps the older job and its onReady loads the abandoned model.// Only load intents have an owner; a download-only pick holds no token and answers true.@@ -3871,6 +3908,8 @@ export function ImagesPage({// A local snapshot of the copy is now a Hub load of the base: plan and stage it like one.source = "hub";}+ // The retry's override rides the same snapshot, so its plan and its load both carry it.+ if (oversizedRetry) advanced = { ...advanced, allow_oversized_load: true };// Resolve the engine into the snapshot, so the plan and the load it fires cannot read different selects.if (!advanced.engine && sendsEngine(opts.kind, opts.filename)) {advanced = { ...advanced, engine: engineFor(repoId, opts, advanced) ?? "auto" };@@ -3887,6 +3926,7 @@ export function ImagesPage({// Read inside the try, acted on outside it: refusing from in there would fall through to the// load if the refusal itself threw.let incompatible: string | null = null;+ let incompatibleCode: string | null = null;try {const plan = await requestDownloadPlan(opts.displayRepoId ?? repoId, opts, advanced);// Only load intents are superseded; accepted downloads keep their own plans.@@ -3898,6 +3938,7 @@ export function ImagesPage({throw new Error("Required asset metadata is incomplete. Retry when it is available.");}incompatible = plan.incompatible_reason ?? null;+ incompatibleCode = plan.incompatible_code ?? null;if (!incompatible && plan.entries.length > 0) {if (!downloadOnly) {pendingStagedLoad.current = {@@ -3954,7 +3995,20 @@ export function ImagesPage({}if (incompatible) {pickToast.dismiss(pickToastId);- toast.error(incompatible);+ const overrideSent = advanced.allow_oversized_load === true || readAllowOversizedLoad();+ if (!downloadOnly && shouldOfferLoadAnyway({ code: incompatibleCode, overrideSent })) {+ const retrySource = source;+ offerLoadAnyway(incompatible, retryWhileCurrent(() => pick === pickSeq.current, () => {+ oversizedLoadOnce.current = true;+ try {+ void loadOrStageRef.current(repoId, opts, retrySource, undefined, familyOverrideRequired, undefined, true);+ } finally {+ oversizedLoadOnce.current = false;+ }+ }));+ } else {+ toast.error(incompatible);+ }return downloadOnly;}if (downloadOnly) {@@ -3963,8 +4017,12 @@ export function ImagesPage({}return handleLoadRef.current(repoId, opts, advanced, pickToastId);},- [stage, currentLoadAdvanced, requestDownloadPlan, modelSelectionAction, pickGuard, revertPick, pickToast, engineFor],+ [stage, currentLoadAdvanced, requestDownloadPlan, modelSelectionAction, pickGuard, revertPick, pickToast, engineFor, offerLoadAnyway, dismissLoadAnyway],);+ const loadOrStageRef = useRef(loadOrStage);+ useEffect(() => {+ loadOrStageRef.current = loadOrStage;+ }, [loadOrStage]);const resolveDownloadFootprint = useCallback(async (repoId: string, meta: ModelSelectorChangeMeta) => {@@ -3993,7 +4051,8 @@ export function ImagesPage({stagedLoadDeferred.current = false;stagedQuantRevert.current = null;pickToast.dismissAll();- }, [pickToast]);+ dismissLoadAnyway();+ }, [pickToast, dismissLoadAnyway]);// A GGUF pick can arrive with only a repo id. The backend rejects a gguf load with no filename// and a pipeline load of a GGUF repo, so name the file from the listing first.@@ -6788,6 +6847,7 @@ export function ImagesPage({</div>)}+ {loadAnywayDialog}</div>);}diff --git a/studio/frontend/src/features/settings/components/model-memory-section.tsx b/studio/frontend/src/features/settings/components/model-memory-section.tsxindex f2bedfce7e2..59a4afcde78 100644--- a/studio/frontend/src/features/settings/components/model-memory-section.tsx+++ b/studio/frontend/src/features/settings/components/model-memory-section.tsx@@ -11,7 +11,9 @@ import {import { Switch } from "@/components/ui/switch";import { useChatRuntimeStore } from "@/features/chat";import { formatBytes } from "@/features/hub/lib/format";+import { usePersistedToggle } from "@/hooks/use-persisted-toggle";import { useT } from "@/i18n";+import { ALLOW_OVERSIZED_LOAD_STORAGE_KEY } from "@/lib/unified-memory-load-refusal";import { subscribeModelLifecycle } from "@/lib/model-lifecycle-events";import { type Ref, useEffect, useRef, useState } from "react";import {@@ -88,6 +90,9 @@ export function ModelMemorySection({ ref }: { ref?: Ref<HTMLElement> }) {useChatRuntimeStore.getState().keepModelsLoaded ? "fit" : "off",);const [multiModelRead, setMultiModelRead] = useState(false);+ const [allowOversizedLoad, setAllowOversizedLoad] = usePersistedToggle(+ ALLOW_OVERSIZED_LOAD_STORAGE_KEY,+ );const [isSavingMultiModel, setIsSavingMultiModel] = useState(false);useEffect(() => {@@ -259,6 +264,20 @@ export function ModelMemorySection({ ref }: { ref?: Ref<HTMLElement> }) {</SelectContent></Select></SettingsRow>+ <SettingsRow+ label={t("settings.resources.modelMemory.allowOversizedLoad")}+ description={t(+ "settings.resources.modelMemory.allowOversizedLoadDescription",+ )}+ hint={t("settings.resources.modelMemory.allowOversizedLoadHint")}+ >+ <Switch+ aria-label={t("settings.resources.modelMemory.allowOversizedLoad")}+ checked={allowOversizedLoad}+ onCheckedChange={setAllowOversizedLoad}+ data-testid="allow-oversized-load-switch"+ />+ </SettingsRow>{error ? (<p className="pb-3 text-xs text-destructive">{error}</p>) : (diff --git a/studio/frontend/src/features/video/api.ts b/studio/frontend/src/features/video/api.tsindex 5a5092f74a3..50e636d2837 100644--- a/studio/frontend/src/features/video/api.ts+++ b/studio/frontend/src/features/video/api.ts@@ -8,6 +8,7 @@ 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";+import { withAllowOversizedLoad } from "@/lib/unified-memory-load-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),@@ -145,6 +146,8 @@ export interface VideoLoadProgress {// null when the total isn't known yet.expected_bytes?: number | null;error?: string | null;+ /** Absent on an older backend. */+ error_code?: string | null;}export interface VideoLoadRequest {@@ -189,6 +192,8 @@ export interface VideoLoadRequest {// Text-encoder precision. Omit for the family default (the hosted quantized encoder ComfyUI's template matches);// "none" keeps the dense bf16 encoder. An explicit scheme is refused with a 409 when the host cannot run it.text_encoder_quant?: "none" | "fp8" | "fp8_dynamic" | "int8" | "nvfp4";+ // Omitted = refuse as usual; withAllowOversizedLoad fills it from the persisted setting.+ allow_oversized_load?: boolean;}/** One reference video, with the soundtrack MiniMax-H3 conditions on alongside it. */@@ -312,7 +317,7 @@ export async function loadVideoModel(body: VideoLoadRequest): Promise<VideoStatuawait authFetch("/api/inference/video/load", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),+ body: JSON.stringify(withAllowOversizedLoad(body)),}),),async (signal) => (await getVideoLoadProgress(signal)).phase,@@ -327,7 +332,7 @@ export async function getVideoDownloadPlan(await authFetch("/api/inference/video/download-plan", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify(body),+ body: JSON.stringify(withAllowOversizedLoad(body)),}),);}diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsxindex 2ca697b601f..486771b6bb3 100644--- a/studio/frontend/src/features/video/video-page.tsx+++ b/studio/frontend/src/features/video/video-page.tsx@@ -194,6 +194,8 @@ import {isDownloadCancelled,} from "@/lib/native-files";import { toast } from "@/lib/toast";+import { useLoadAnywayPrompt } from "@/components/load-anyway-dialog";+import { readAllowOversizedLoad, retryWhileCurrent, shouldOfferLoadAnyway } from "@/lib/unified-memory-load-refusal";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";@@ -963,6 +965,7 @@ type VideoLoadAdvanced = Pick<| "transformer_quant"| "family_override"| "gpu_ids"+ | "allow_oversized_load">;// Centered panel used for both halves of the capability gate below: the wait, and the answer.@@ -1254,6 +1257,12 @@ function VideoGenerator({// The Reapply target (and its canReapply flag) to restore if the optimistic swap fails:// handleLoad overwrites lastLoad at load start, and a later failure leaves the old model.const lastLoadRevert = useRef<{ prev: typeof lastLoad.current; canReapply: boolean } | null>(null);+ // Set only around a confirmed Load anyway retry.+ const oversizedLoadOnce = useRef(false);+ const lastLoadAttempt = useRef<{ overrideSent: boolean; retry: () => void } | null>(null);+ // Synced after render (handleLoadRef is written during render).+ const retryLoadRef = useRef<((repoId: string, opts: VideoLoadOptions, pinned?: VideoLoadAdvanced) => Promise<boolean>) | null>(null);+ const { offer: offerLoadAnyway, dismiss: dismissLoadAnyway, dialog: loadAnywayDialog } = useLoadAnywayPrompt();// Which pick owns the page: resolving and staging do not set `busy`, so a pick can land on an// awaiting one. Lazy state, not a ref, since a ref cannot be written during render.const [pickGuard] = useState(createPickGuard);@@ -2435,6 +2444,16 @@ function VideoGenerator({setSelectorOpen(false);}, [active]);+ const offerLoadAnywayFor = useCallback(+ (failure: unknown, code?: string | null): boolean => {+ const attempt = lastLoadAttempt.current;+ if (!attempt || !shouldOfferLoadAnyway({ code, failure, overrideSent: attempt.overrideSent })) return false;+ offerLoadAnyway(failureMessage(failure) || "Failed to load model", attempt.retry);+ return true;+ },+ [offerLoadAnyway],+ );+// Poll load-progress until the background load reaches "ready" or "error", updating the persistent toast in place.const pollLoadProgress = useCallback(async () => {// This tick's cancellation fence: clearing pollTimer stops the next tick, not the awaits below.@@ -2465,7 +2484,7 @@ function VideoGenerator({if (p.phase === "error") {pendingEvicted.current = [];dismissLoadToast();- reportLoadFailure(p.error, "Failed to load model");+ if (!offerLoadAnywayFor(p.error, p.error_code)) reportLoadFailure(p.error, "Failed to load model");setBusy(null);if (quantRevert.current) {revertPick(quantRevert.current);@@ -2509,7 +2528,7 @@ function VideoGenerator({}if (seq !== cancelSeq.current) return;pollTimer.current = setTimeout(() => void pollLoadProgress(), 1000);- }, [dismissLoadToast, refreshStatus, cancelLoadFromToast]);+ }, [dismissLoadToast, refreshStatus, cancelLoadFromToast, offerLoadAnywayFor]);// Put back what a teardown removed when the load it was tearing down is still running: the// unload failed, so the poll and toast were stopped for nothing. refreshStatus cannot do@@ -2685,6 +2704,8 @@ function VideoGenerator({controls.gpuChoices.some((d) => String(d.index) === controls.selectedGpu)? [Number(controls.selectedGpu)]: undefined,+ // Only a confirmed Load anyway retry sets it, around the one loadOrStage call that snapshots this.+ allow_oversized_load: oversizedLoadOnce.current ? true : undefined,};},[],@@ -2729,6 +2750,8 @@ function VideoGenerator({// unload that can reach the backend first, find no load registered, and stop nothing.const startSeq = cancelSeq.current;const startLoad = ++loadSeq.current;+ // An older pick's Load anyway prompt would retry a model this load supersedes.+ dismissLoadAnyway();// Published now and settled in the finally below, so a cancel waits for the WHOLE path.let settleLoad: () => void = () => {};const inFlight = new Promise<void>((resolve) => {@@ -2755,6 +2778,13 @@ 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 };+ const overrideSent = advanced.allow_oversized_load === true || readAllowOversizedLoad();+ const retryPick = pickSeq.current;+ const retryOversized = retryWhileCurrent(+ () => retryPick === pickSeq.current && startLoad === loadSeq.current,+ () => void retryLoadRef.current?.(repoId, opts, { ...advanced, allow_oversized_load: true }),+ );+ lastLoadAttempt.current = { overrideSent, retry: retryOversized };// 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) {@@ -2779,6 +2809,7 @@ function VideoGenerator({// joining the pinned set.h3_task: opts.h3Task,gpu_ids: advanced.gpu_ids,+ allow_oversized_load: advanced.allow_oversized_load,});const answer = await startRequest;pendingEvicted.current = evictedSlotsFrom(answer);@@ -2789,7 +2820,7 @@ function VideoGenerator({setCanReapply(prevCanReapply);lastLoadRevert.current = null;dismissLoadToast();- reportLoadFailure(err, "Failed to start load");+ if (!offerLoadAnywayFor(err)) reportLoadFailure(err, "Failed to start load");setBusy(null);void refreshStatus();return settle(false);@@ -2825,6 +2856,8 @@ function VideoGenerator({canReapply,currentLoadAdvanced,pickToast,+ offerLoadAnywayFor,+ dismissLoadAnyway,],);@@ -2839,6 +2872,9 @@ function VideoGenerator({toastId?: string;} | null>(null);const handleLoadRef = useRef(handleLoad);+ useEffect(() => {+ retryLoadRef.current = handleLoad;+ }, [handleLoad]);handleLoadRef.current = handleLoad;// A download finishing while this page is hidden must not evict the model the visible page// loaded. The pick is held, not dropped.@@ -2915,6 +2951,7 @@ function VideoGenerator({// missing its base repo's text encoder or VAE. Staging never sets `busy`, so plans resolve in// response order; bumped before the non-hub return too, so a local pick invalidates one in flight.const pick = ++pickSeq.current;+ dismissLoadAnyway();// The previous pick's staged intent dies with it: a pick that stages nothing never calls// stage(), so the queue keeps the older job and its onReady loads the abandoned model.pendingStagedLoad.current = null;@@ -2932,6 +2969,7 @@ function VideoGenerator({const ownRevert = quantRevert.current;// Read inside the try, acted on outside it, as on the images page.let incompatible: string | null = null;+ let incompatibleCode: string | null = null;try {const plan = await getVideoDownloadPlan({model_path: opts.displayRepoId ?? repoId,@@ -2949,6 +2987,8 @@ function VideoGenerator({h3_task: opts.h3Task,// The plan sizes its file set against the card the load will use, so it needs the pick.gpu_ids: advanced.gpu_ids,+ // A Load anyway retry sends it on the plan too, or the plan refuses the pick again.+ allow_oversized_load: advanced.allow_oversized_load,});// Superseded. Report started so this pick's `.then` leaves the newer label alone.if (pick !== pickSeq.current || !owns()) {@@ -2960,6 +3000,7 @@ function VideoGenerator({// GGUF/base size pairing and the video planner has no diffusers base to pair against, so this is// the shared envelope's half of the contract rather than a live path.incompatible = plan.incompatible_reason ?? null;+ incompatibleCode = plan.incompatible_code ?? null;if (!incompatible && plan.entries.length > 0) {const entries = diffusionStagingEntries(plan.entries, repoId, opts);if (entries.length === 0) return handleLoadRef.current(repoId, opts, advanced);@@ -2985,13 +3026,29 @@ function VideoGenerator({}if (incompatible) {pickToast.dismiss(pickToastId);- toast.error(incompatible);+ const overrideSent = advanced.allow_oversized_load === true || readAllowOversizedLoad();+ if (shouldOfferLoadAnyway({ code: incompatibleCode, overrideSent })) {+ offerLoadAnyway(incompatible, retryWhileCurrent(() => pick === pickSeq.current, () => {+ oversizedLoadOnce.current = true;+ try {+ void loadOrStageRef.current(repoId, opts, source, undefined, familyOverrideRequired);+ } finally {+ oversizedLoadOnce.current = false;+ }+ }));+ } else {+ toast.error(incompatible);+ }return false;}return handleLoadRef.current(repoId, opts, advanced, pickToastId);},- [stage, pickGuard, currentLoadAdvanced, pickToast],+ [stage, pickGuard, currentLoadAdvanced, pickToast, offerLoadAnyway, dismissLoadAnyway],);+ const loadOrStageRef = useRef(loadOrStage);+ useEffect(() => {+ loadOrStageRef.current = loadOrStage;+ }, [loadOrStage]);// A GGUF pick can arrive with only a repo id. The backend rejects a gguf load with no filename// and a pipeline load of a GGUF repo, so name the file from the listing first.@@ -3240,7 +3297,8 @@ function VideoGenerator({stagedLoadDeferred.current = false;stagedQuantRevert.current = null;pickToast.dismissAll();- }, [pickToast]);+ dismissLoadAnyway();+ }, [pickToast, dismissLoadAnyway]);const handleModelSelect = useCallback((id: string, meta: ModelSelectorChangeMeta) => {@@ -4937,6 +4995,7 @@ function VideoGenerator({</div></div>+ {loadAnywayDialog}</div>);}diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex 01e1c664108..295e459388d 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -2395,6 +2395,9 @@ export const ar = {multiModelDescriptionAlways:"لا يفرّغ تحميل نموذج أي نموذج آخر أبدًا. النموذج الذي لا يتسع لا يُحمَّل. ولا يزال التفريغ التلقائي عند الخمول والتدريب يحرّران الذاكرة.",multiModelHint: "يشمل نماذج المحادثة والصوت والصور والفيديو. يجيب كل نموذج محادثة محمّل عن الطلبات التي تذكره بالاسم. مع عدة كروت رسوميات، يحاول Unsloth وضع النموذج الجديد على كرت لا يستخدمه نموذج آخر. يترك خيار «عندما تتسع» نحو 1 جيجابايت فارغة. ولا يفرّغ الخياران «عندما تتسع» و«دائمًا» أبدًا نموذجًا على كرت آخر.",+ allowOversizedLoad: "السماح بتحميل النماذج الكبيرة جدًا",+ allowOversizedLoadDescription: "تحميل نماذج الصور والفيديو حتى عندما يشير فحص الذاكرة إلى أنها لن تتسع.",+ allowOversizedLoadHint: "ينطبق عندما يتشارك المعالج ووحدة GPU ذاكرة واحدة (Apple Silicon ووحدات GPU المدمجة). يرفض Studio التحميل عندما يكون تقديره لأوزان النموذج أكبر من الذاكرة المتبقية بعد حجز مساحة لنظام التشغيل. عند تفعيل هذا الخيار تتم محاولة التحميل على أي حال. قد يخطئ التقدير في أي اتجاه: قد يفشل التحميل الكبير جدًا أو يستهلك كل الذاكرة أو يسبب تبديلًا كثيفًا للذاكرة أو توقف الكمبيوتر عن الاستجابة أو إيقاف Studio. معطل افتراضيًا.",mediaIdleUnloadDescription:"حرّر ذاكرة VRAM بتفريغ نموذجَي الصور والفيديو بعد هذا العدد من ثواني الخمول. تُبقي القيمة 0 النموذجين محمَّلين، والحد الأدنى 60 ثانية.",mlockVetoed: "يبقى --mlock معطَّلاً: تثبيت النموذج سيحجز ذاكرة تكفي حجمه كاملاً. ولا يزال التفريغ التلقائي عند الخمول معطَّلاً.",diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex 768c99c44b1..ab4d598672a 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -2427,6 +2427,9 @@ export const de = {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-, Sprach-, 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.",+ allowOversizedLoad: "Übergroße Modelle trotzdem laden",+ allowOversizedLoadDescription: "Bild- und Videomodelle auch laden, wenn die Speicherprüfung meldet, dass sie nicht passen.",+ allowOversizedLoadHint: "Gilt, wenn CPU und GPU sich einen Speicher teilen (Apple Silicon, integrierte GPUs). Studio verweigert das Laden, wenn die geschätzten Modellgewichte größer sind als der Speicher, der nach der Reserve für das Betriebssystem bleibt. Ist dies aktiviert, wird das Laden trotzdem versucht. Die Schätzung kann in beide Richtungen falsch sein: Ein zu großes Modell kann fehlschlagen, den gesamten Speicher belegen, starkes Auslagern verursachen, den Computer einfrieren oder Studio beenden. Standardmäßig aus.",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.",diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 15c673c0872..f3f87c7dd0e 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -2458,6 +2458,9 @@ export const en = {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, speech, 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.",+ allowOversizedLoad: "Allow oversized model loads",+ allowOversizedLoadDescription: "Load image and video models even when the memory check says they will not fit.",+ allowOversizedLoadHint: "Applies where the CPU and GPU share one memory pool (Apple Silicon, integrated GPUs). Studio refuses a load when its estimate of the model weights is larger than the memory left after reserving room for the operating system. With this on, those loads are attempted anyway. The estimate can be wrong either way: an oversized load can fail, use up all memory, make the computer swap heavily or stop responding, or stop Studio. Off by default.",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.",diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex 02b470d2691..a5b9539752c 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -2422,6 +2422,9 @@ export const es = {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, voz, 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.",+ allowOversizedLoad: "Permitir cargar modelos demasiado grandes",+ allowOversizedLoadDescription: "Cargar modelos de imagen y vídeo aunque la comprobación de memoria indique que no caben.",+ allowOversizedLoadHint: "Se aplica cuando la CPU y la GPU comparten una sola memoria (Apple Silicon, GPU integradas). Studio rechaza la carga cuando su estimación de los pesos del modelo supera la memoria que queda tras reservar espacio para el sistema operativo. Con esta opción activada, se intenta cargar de todos modos. La estimación puede fallar en ambos sentidos: una carga demasiado grande puede fallar, agotar la memoria, hacer que el equipo use mucho la memoria de intercambio o deje de responder, o cerrar Studio. Desactivado de forma predeterminada.",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.",diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex ac7760977b3..558e5634491 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -2426,6 +2426,9 @@ export const fr = {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, vocaux, 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.",+ allowOversizedLoad: "Autoriser le chargement de modèles trop grands",+ allowOversizedLoadDescription: "Charger les modèles d'image et de vidéo même si la vérification de mémoire indique qu'ils ne tiennent pas.",+ allowOversizedLoadHint: "S'applique lorsque le CPU et le GPU partagent une seule mémoire (Apple Silicon, GPU intégrés). Studio refuse un chargement quand son estimation des poids du modèle dépasse la mémoire restante après la réserve pour le système d'exploitation. Si cette option est activée, le chargement est tenté quand même. L'estimation peut se tromper dans les deux sens : un chargement trop grand peut échouer, épuiser la mémoire, faire beaucoup swapper l'ordinateur ou le bloquer, ou arrêter Studio. Désactivé par défaut.",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é.",diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.tsindex fc3faf6b102..ef194fec498 100644--- a/studio/frontend/src/i18n/locales/he.ts+++ b/studio/frontend/src/i18n/locales/he.ts@@ -2502,6 +2502,9 @@ export const he = {"טעינת מודל לעולם אינה פורקת מודל אחר. מודל שאינו נכנס לא נטען. פריקה בחוסר פעילות ואימון עדיין מפנים זיכרון.",multiModelHint:"חל על מודלי צ'אט, דיבור, תמונה ווידאו. כל מודל צ'אט טעון עונה לבקשות שמציינות אותו. כשיש כמה מעבדי GPU, Unsloth מנסה למקם מודל חדש ב-GPU שאף מודל אחר אינו משתמש בו. ”כשהם נכנסים” משאיר כ-1 GB פנוי. ”כשהם נכנסים” ו”תמיד” לעולם אינם פורקים מודל ב-GPU אחר.",+ allowOversizedLoad: "לאפשר טעינת מודלים גדולים מדי",+ allowOversizedLoadDescription: "לטעון מודלי תמונה ווידאו גם כשבדיקת הזיכרון קובעת שהם לא ייכנסו.",+ allowOversizedLoadHint: "חל כאשר המעבד וה-GPU חולקים מאגר זיכרון אחד (Apple Silicon, מעבדים גרפיים משולבים). Studio מסרב לטעינה כאשר ההערכה שלו למשקלי המודל גדולה מהזיכרון שנותר אחרי שמירת מקום למערכת ההפעלה. כשאפשרות זו מופעלת, הטעינה תנוסה בכל זאת. ההערכה יכולה לטעות לשני הכיוונים: טעינה גדולה מדי עלולה להיכשל, לנצל את כל הזיכרון, לגרום להחלפה כבדה לדיסק או לתקיעת המחשב, או לעצור את Studio. כבוי כברירת מחדל.",mediaIdleUnloadDescription:"פנה VRAM על ידי פריקת מודלי תמונה ווידאו לאחר מספר שניות ללא פעילות. 0 שומר אותם טעונים, מינימום 60.",mlockVetoed:diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex 72626388edd..02cca91317e 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -2401,6 +2401,9 @@ export const hi = {multiModelDescriptionAlways:"मॉडल लोड करने पर कोई दूसरा मॉडल कभी अनलोड नहीं होता। जो मॉडल नहीं समाता, वह लोड नहीं होता। निष्क्रियता पर स्वतः अनलोड और ट्रेनिंग अब भी मेमोरी खाली करते हैं।",multiModelHint: "चैट, स्पीच, इमेज और वीडियो मॉडल पर लागू होता है। हर लोड किया गया चैट मॉडल उन अनुरोधों का जवाब देता है जो उसका नाम लेते हैं। कई GPU होने पर, Unsloth नए मॉडल को ऐसे GPU पर रखने की कोशिश करता है जिसे कोई दूसरा मॉडल इस्तेमाल नहीं कर रहा। “जब जगह हो” लगभग 1 GB खाली छोड़ता है। “जब जगह हो” और “हमेशा” किसी दूसरे GPU पर मौजूद मॉडल को कभी अनलोड नहीं करते।",+ allowOversizedLoad: "बहुत बड़े मॉडल लोड करने दें",+ allowOversizedLoadDescription: "मेमोरी जाँच के अनुसार फिट न होने पर भी इमेज और वीडियो मॉडल लोड करें।",+ allowOversizedLoadHint: "यह तब लागू होता है जब CPU और GPU एक ही मेमोरी साझा करते हैं (Apple Silicon, इंटीग्रेटेड GPU)। जब मॉडल वेट्स का अनुमान ऑपरेटिंग सिस्टम के लिए जगह छोड़ने के बाद बची मेमोरी से बड़ा होता है, तो Studio लोड करने से मना कर देता है। इसे चालू करने पर लोड फिर भी आज़माया जाता है। अनुमान किसी भी दिशा में गलत हो सकता है: बहुत बड़ा लोड विफल हो सकता है, पूरी मेमोरी भर सकता है, कंप्यूटर में भारी स्वैपिंग करा सकता है या उसे रोक सकता है, या Studio बंद कर सकता है। डिफ़ॉल्ट रूप से बंद।",mediaIdleUnloadDescription:"इतने सेकंड तक निष्क्रिय रहने के बाद इमेज और वीडियो मॉडल अनलोड करके VRAM खाली करें। 0 पर वे लोड रहते हैं; न्यूनतम 60 सेकंड।",mlockVetoed: "--mlock बंद ही रहता है: मॉडल को पिन करने से उसकी पूरी मात्रा के लिए RAM आरक्षित हो जाएगी। निष्क्रिय होने पर स्वतः अनलोड अब भी अक्षम है।",diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex 71553f6c064..97f33606562 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -2333,6 +2333,9 @@ export const it = {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, voce, 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.",+ allowOversizedLoad: "Consenti il caricamento di modelli troppo grandi",+ allowOversizedLoadDescription: "Carica modelli di immagini e video anche quando il controllo della memoria indica che non entrano.",+ allowOversizedLoadHint: "Si applica quando CPU e GPU condividono un'unica memoria (Apple Silicon, GPU integrate). Studio rifiuta il caricamento quando la stima dei pesi del modello supera la memoria rimasta dopo la riserva per il sistema operativo. Con questa opzione attiva, il caricamento viene tentato comunque. La stima può sbagliare in entrambe le direzioni: un caricamento troppo grande può fallire, esaurire la memoria, far usare molto lo swap al computer o bloccarlo, oppure chiudere Studio. Disattivato per impostazione predefinita.",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.",diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex 92c964ca606..277b74a8a96 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -2374,6 +2374,9 @@ export const ja = {multiModelDescriptionAlways:"モデルを読み込んでも、他のモデルはアンロードされません。収まらないモデルは読み込まれません。アイドル時の自動アンロードとトレーニングでは引き続きメモリが解放されます。",multiModelHint: "チャット、音声、画像、動画のモデルが対象です。読み込まれた各チャットモデルは、そのモデルを指定したリクエストに応答します。複数の GPU がある場合、Unsloth は新しいモデルを他のモデルが使っていない GPU に配置しようとします。「収まる場合」は約 1 GB の空きを残します。「収まる場合」と「常に」は、別の GPU 上のモデルをアンロードしません。",+ allowOversizedLoad: "大きすぎるモデルの読み込みを許可",+ allowOversizedLoadDescription: "メモリチェックで収まらないと判定された場合でも、画像と動画のモデルを読み込みます。",+ allowOversizedLoadHint: "CPU と GPU が 1 つのメモリを共有する環境 (Apple Silicon、内蔵 GPU) に適用されます。モデルの重みの推定値が、オペレーティングシステム用の領域を確保した後の残りメモリを超えると、Studio は読み込みを拒否します。オンにすると、その場合でも読み込みを試みます。推定はどちらの方向にも外れることがあり、大きすぎる読み込みは失敗する、メモリを使い切る、激しいスワップや応答停止を起こす、または Studio を停止させることがあります。既定ではオフです。",mediaIdleUnloadDescription:"指定した秒数だけアイドル状態が続くと、画像モデルと動画モデルをアンロードして VRAM を解放します。0 にすると読み込んだままになります。最小値は 60 秒です。",mlockVetoed: "--mlock は無効のままです。モデルを固定するとモデル全体分の RAM を確保することになります。アイドル時の自動アンロードは引き続き無効です。",diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex b09a107e517..26eed611a56 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -2389,6 +2389,9 @@ export const ko = {multiModelDescriptionAlways:"모델을 로드해도 다른 모델을 언로드하지 않습니다. 공간이 부족한 모델은 로드되지 않습니다. 유휴 시 자동 언로드와 학습은 여전히 메모리를 확보합니다.",multiModelHint: "채팅, 음성, 이미지, 동영상 모델에 적용됩니다. 로드된 각 채팅 모델은 해당 모델을 지정한 요청에 응답합니다. GPU가 여러 개이면 Unsloth는 다른 모델이 사용하지 않는 GPU에 새 모델을 배치하려고 합니다. '공간이 있을 때'는 약 1GB를 남겨 둡니다. '공간이 있을 때'와 '항상'은 다른 GPU에 있는 모델을 언로드하지 않습니다.",+ allowOversizedLoad: "너무 큰 모델 로드 허용",+ allowOversizedLoadDescription: "메모리 검사에서 맞지 않는다고 판단해도 이미지 및 비디오 모델을 로드합니다.",+ allowOversizedLoadHint: "CPU와 GPU가 하나의 메모리를 공유하는 경우(Apple Silicon, 내장 GPU)에 적용됩니다. 모델 가중치 추정치가 운영 체제용 공간을 확보한 후 남은 메모리보다 크면 Studio는 로드를 거부합니다. 이 옵션을 켜면 그래도 로드를 시도합니다. 추정치는 어느 방향으로든 틀릴 수 있으며, 너무 큰 로드는 실패하거나, 메모리를 모두 사용하거나, 심한 스와핑 또는 응답 없음을 일으키거나, Studio를 중지시킬 수 있습니다. 기본값은 꺼짐입니다.",mediaIdleUnloadDescription:"지정한 유휴 시간(초)이 지나면 이미지와 동영상 모델을 해제하여 VRAM을 확보합니다. 0으로 설정하면 계속 로드된 상태로 유지됩니다. 최소 60초입니다.",mlockVetoed: "--mlock은 꺼진 상태로 유지됩니다. 모델을 고정하면 모델 전체 크기만큼 RAM을 예약하게 됩니다. 유휴 시 자동 언로드는 계속 비활성화됩니다.",diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex e0ea80c2811..c2c5321c723 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -2410,6 +2410,9 @@ export const ptBR = {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, fala, 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.",+ allowOversizedLoad: "Permitir carregar modelos grandes demais",+ allowOversizedLoadDescription: "Carregar modelos de imagem e vídeo mesmo quando a verificação de memória indica que eles não cabem.",+ allowOversizedLoadHint: "Vale quando a CPU e a GPU compartilham uma única memória (Apple Silicon, GPUs integradas). O Studio recusa o carregamento quando a estimativa dos pesos do modelo é maior que a memória que sobra depois de reservar espaço para o sistema operacional. Com esta opção ativada, o carregamento é tentado mesmo assim. A estimativa pode errar para os dois lados: um carregamento grande demais pode falhar, esgotar a memória, fazer o computador usar muito a memória de troca ou travar, ou encerrar o Studio. Desativado por padrão.",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.",diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex 58a6c93f304..cb786956859 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -2407,6 +2407,9 @@ export const ru = {multiModelDescriptionAlways:"Загрузка модели никогда не выгружает другую. Модель, которая не помещается, не загружается. Автовыгрузка по простою и обучение по-прежнему освобождают память.",multiModelHint: "Относится к моделям чата, речи, изображений и видео. Каждая загруженная модель чата отвечает на запросы, в которых она указана. При нескольких GPU Unsloth старается разместить новую модель на GPU, который не занят другой моделью. «Если помещаются» оставляет около 1 ГБ свободным. «Если помещаются» и «Всегда» никогда не выгружают модель с другого GPU.",+ allowOversizedLoad: "Разрешить загрузку слишком больших моделей",+ allowOversizedLoadDescription: "Загружать модели изображений и видео, даже если проверка памяти сообщает, что они не поместятся.",+ allowOversizedLoadHint: "Действует, когда CPU и GPU используют общую память (Apple Silicon, встроенные GPU). Studio отказывает в загрузке, если оценка весов модели больше памяти, оставшейся после резерва для операционной системы. Если параметр включен, загрузка все равно выполняется. Оценка может ошибаться в обе стороны: слишком большая загрузка может завершиться ошибкой, занять всю память, вызвать активный своппинг или зависание компьютера либо остановить Studio. По умолчанию выключено.",mediaIdleUnloadDescription:"Освобождать VRAM, выгружая модели изображений и видео после указанного числа секунд простоя. 0 оставляет их загруженными; минимальное значение: 60.",mlockVetoed: "--mlock остаётся выключенным: закрепление модели зарезервировало бы ОЗУ под неё целиком. Автовыгрузка по простою по-прежнему отключена.",diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.tsindex b51987f541f..05f8b3d235a 100644--- a/studio/frontend/src/i18n/locales/sv.ts+++ b/studio/frontend/src/i18n/locales/sv.ts@@ -2579,6 +2579,9 @@ export const sv = {"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:"Gäller chatt-, tal-, 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.",+ allowOversizedLoad: "Tillåt inläsning av för stora modeller",+ allowOversizedLoadDescription: "Läs in bild- och videomodeller även när minneskontrollen säger att de inte får plats.",+ allowOversizedLoadHint: "Gäller när CPU och GPU delar ett minne (Apple Silicon, integrerade GPU:er). Studio vägrar en inläsning när uppskattningen av modellvikterna är större än minnet som finns kvar efter reserven för operativsystemet. Med detta påslaget görs inläsningen ändå. Uppskattningen kan fela åt båda hållen: en för stor inläsning kan misslyckas, ta slut på minnet, få datorn att swappa kraftigt eller sluta svara, eller stoppa Studio. Av som standard.",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:diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex b4b0729b390..37281e733d9 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -2365,6 +2365,9 @@ export const zhCN = {multiModelDescriptionAlways:"加载模型时绝不卸载其他模型。无法容纳的模型不会被加载。空闲自动卸载和训练仍会释放内存。",multiModelHint: "适用于聊天、语音、图像和视频模型。每个已加载的聊天模型都会响应指定它的请求。在多 GPU 机器上,Unsloth 会尽量把新模型放到没有其他模型使用的 GPU 上。“能容纳时”会预留约 1 GB 空间。“能容纳时”和“总是”都不会卸载其他 GPU 上的模型。",+ allowOversizedLoad: "允许加载超大模型",+ allowOversizedLoadDescription: "即使内存检查认为放不下,也加载图像和视频模型。",+ allowOversizedLoadHint: "适用于 CPU 和 GPU 共用一块内存的设备(Apple Silicon、集成显卡)。当模型权重的估算值大于为操作系统预留空间后剩余的内存时,Studio 会拒绝加载。开启后仍会尝试加载。估算可能偏高也可能偏低:超大加载可能失败、耗尽内存、导致电脑大量换页或无响应,或使 Studio 停止运行。默认关闭。",mediaIdleUnloadDescription:"空闲达到该秒数后卸载图像和视频模型以释放 VRAM。设为 0 则保持加载,最小值为 60 秒。",mlockVetoed: "--mlock 保持关闭:锁定模型会为其全部内容预留内存。空闲自动卸载仍处于禁用状态。",diff --git a/studio/frontend/src/lib/unified-memory-load-refusal.ts b/studio/frontend/src/lib/unified-memory-load-refusal.tsnew file mode 100644index 00000000000..69bc19df352--- /dev/null+++ b/studio/frontend/src/lib/unified-memory-load-refusal.ts@@ -0,0 +1,82 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Unified-memory load refusal: sent as a code (`incompatible_code` / `error_code`) or the+// X-Unsloth-Refusal header on a 400; lifted by `allow_oversized_load`.++import { REFUSAL_HEADER, refusalHeadersOf } from "@/lib/multi-model-refusal";++/** Backend: diffusion_memory.UNIFIED_OVERSIZE_REFUSAL_CODE. */+export const UNIFIED_MEMORY_LOAD_REFUSAL = "unified-memory-load";+export const ALLOW_OVERSIZED_LOAD_STORAGE_KEY = "unsloth_allow_oversized_load";+/** Quoted by the backend refusal text; keep identical. */+export const ALLOW_OVERSIZED_LOAD_LABEL = "Allow oversized model loads";+export const UNIFIED_MEMORY_LOAD_TITLE = "Not enough memory to load this model";+export const LOAD_ANYWAY_LABEL = "Load anyway";+export const LOAD_ANYWAY_CONFIRM_TITLE = "Load this model anyway?";+export const LOAD_ANYWAY_WARNING =+ "Studio estimated that this model's weights do not fit the memory this device can safely give it after reserving room for the operating system. The check is an estimate and can be wrong, but loading past it can fail, use up all memory, make the computer swap heavily or stop responding, or stop Studio outright. Save your work in other applications first.";++export function readAllowOversizedLoad(): boolean {+ try {+ return localStorage.getItem(ALLOW_OVERSIZED_LOAD_STORAGE_KEY) === "true";+ } catch {+ return false;+ }+}++export function allowOversizedLoadField(+ persistedSetting: boolean,+ oneShot: boolean,+): true | undefined {+ return persistedSetting || oneShot ? true : undefined;+}++export function withAllowOversizedLoad<+ T extends { allow_oversized_load?: boolean },+>(body: T): T {+ if (body.allow_oversized_load !== undefined) return body;+ const field = allowOversizedLoadField(readAllowOversizedLoad(), false);+ return field ? { ...body, allow_oversized_load: field } : body;+}++export function isUnifiedMemoryLoadRefusal(input: {+ code?: string | null;+ failure?: unknown;+}): boolean {+ if ((input.code ?? "").trim().toLowerCase() === UNIFIED_MEMORY_LOAD_REFUSAL)+ return true;+ const headers = refusalHeadersOf(input.failure);+ if (!headers) return false;+ let value: string | null = null;+ if (typeof (headers as Headers).get === "function") {+ value = (headers as Headers).get(REFUSAL_HEADER);+ } else {+ for (const [name, v] of Object.entries(headers)) {+ if (name.toLowerCase() === REFUSAL_HEADER && typeof v === "string")+ value = v;+ }+ }+ return (value ?? "").trim().toLowerCase() === UNIFIED_MEMORY_LOAD_REFUSAL;+}++/** Not when the load already sent the override: then the refusal means something else changed. */+export function shouldOfferLoadAnyway(input: {+ code?: string | null;+ failure?: unknown;+ overrideSent: boolean;+}): boolean {+ return !input.overrideSent && isUnifiedMemoryLoadRefusal(input);+}++/** Runs only while its pick is still current: the toast outlives the refusal and must not supersede a newer pick. */+export function retryWhileCurrent(+ isCurrent: () => boolean,+ retry: () => void,+): () => void {+ return () => {+ if (isCurrent()) {+ retry();+ }+ };+}diff --git a/studio/frontend/tests/image-engine-choice.test.ts b/studio/frontend/tests/image-engine-choice.test.tsindex a9188150004..741bf6fd658 100644--- a/studio/frontend/tests/image-engine-choice.test.ts+++ b/studio/frontend/tests/image-engine-choice.test.ts@@ -141,7 +141,7 @@ test("the native reload targets the resident GGUF, not a stale page load anothertest("a refused load reseeds the Engine select from the resident build", () => {const source = readSrc("features/images/images-page.tsx");- assert.match(source, /setEngineSeed\(""\);[\s\S]{0,80}dismissLoadToast\(\);\s*reportLoadFailure\(err, "Failed to start load"\)/);+ assert.match(source, /setEngineSeed\(""\);[\s\S]{0,80}dismissLoadToast\(\);\s*(?:if \(!offerLoadAnywayFor\(err\)\) )?reportLoadFailure\(err, "Failed to start load"\)/);});test("a staged pick snapshots its resolved engine for both the plan and the load", () => {diff --git a/studio/frontend/tests/image-generate-no-resend.test.ts b/studio/frontend/tests/image-generate-no-resend.test.tsindex f70d95de17f..1eb8d7ffd30 100644--- a/studio/frontend/tests/image-generate-no-resend.test.ts+++ b/studio/frontend/tests/image-generate-no-resend.test.ts@@ -40,6 +40,7 @@ function loadApis(): ImagesApi {"@/features/auth": { authFetch: auth.authFetch },"@/lib/format-fastapi-error": { readFastApiError: async () => "" },"@/lib/multi-model-refusal": { parseLoadJson: async () => ({}) },+ "@/lib/unified-memory-load-refusal": { withAllowOversizedLoad: (body: unknown) => body },},{ relativePassthrough: true },);diff --git a/studio/frontend/tests/image-model-recall.test.ts b/studio/frontend/tests/image-model-recall.test.tsindex ea9e1f9ef6b..885a61abbc5 100644--- a/studio/frontend/tests/image-model-recall.test.ts+++ b/studio/frontend/tests/image-model-recall.test.ts@@ -306,9 +306,15 @@ test("a new model pick cancels recalled generation and retires the staged load",stagedLoadDeferred: { current: true },stagedQuantRevert: { current: { prev: "Q8_0" } },pickToast: { dismissed: 0, dismissAll() { this.dismissed += 1; } },+ // An older pick's Load anyway toast and dialog retire with it.+ loadAnyway: { dismissed: 0 },+ dismissLoadAnyway: () => {+ scope.loadAnyway.dismissed += 1;+ },};new Function(...Object.keys(scope), outputText)(...Object.values(scope));assert.equal(scope.pickToast.dismissed, 1);+ assert.equal(scope.loadAnyway.dismissed, 1);assert.equal(scope.pendingRecalledGeneration.current, null);assert.equal(scope.pickSeq.current, 5);assert.equal(scope.pendingStagedLoad.current, null);diff --git a/studio/frontend/tests/unified-memory-load-refusal.test.ts b/studio/frontend/tests/unified-memory-load-refusal.test.tsnew file mode 100644index 00000000000..1c1ce971a7d--- /dev/null+++ b/studio/frontend/tests/unified-memory-load-refusal.test.ts@@ -0,0 +1,202 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// Unified-memory load refusal (#14267).++import assert from "node:assert/strict";+import { register } from "node:module";+import test, { afterEach } from "node:test";++import { readSrc, readText } from "./helpers/kit.ts";++register("./helpers/settings-api-resolver.mjs", import.meta.url);++const refusal = await import("../src/lib/unified-memory-load-refusal.ts");+const {+ ALLOW_OVERSIZED_LOAD_LABEL,+ ALLOW_OVERSIZED_LOAD_STORAGE_KEY,+ UNIFIED_MEMORY_LOAD_REFUSAL,+ allowOversizedLoadField,+ isUnifiedMemoryLoadRefusal,+ shouldOfferLoadAnyway,+ withAllowOversizedLoad,+} = refusal;+const images = await import("../src/features/images/api.ts");+const video = await import("../src/features/video/api.ts");++// Settles the load notice's background load-progress poll once a test's own stub is gone.+const settledFetch = (async () =>+ new Response(JSON.stringify({ phase: "ready" }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ })) as typeof fetch;+const store = new Map<string, string>();+Object.defineProperty(globalThis, "localStorage", {+ configurable: true,+ value: {+ getItem: (k: string) => store.get(k) ?? null,+ setItem: (k: string, v: string) => void store.set(k, String(v)),+ removeItem: (k: string) => void store.delete(k),+ },+});+afterEach(() => {+ globalThis.fetch = settledFetch;+ store.clear();+});++function captureFetch(reply: object): Record<string, unknown>[] {+ const sent: Record<string, unknown>[] = [];+ globalThis.fetch = (async (_url: unknown, init?: RequestInit) => {+ // Only the POST bodies: the load notice also polls load-progress, which sends none.+ if (init?.body) sent.push(JSON.parse(String(init.body)));+ return new Response(JSON.stringify(reply), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ });+ }) as typeof fetch;+ return sent;+}++test("the refusal is recognised from its code or its header, and nothing else", () => {+ assert.equal(isUnifiedMemoryLoadRefusal({ code: UNIFIED_MEMORY_LOAD_REFUSAL }), true);+ assert.equal(isUnifiedMemoryLoadRefusal({ code: " Unified-Memory-Load " }), true);+ assert.equal(isUnifiedMemoryLoadRefusal({ code: null }), false);+ assert.equal(isUnifiedMemoryLoadRefusal({ code: "memory-estimate" }), false);+ const tagged = Object.assign(new Error("needs about 56 GB"), {+ headers: { "x-unsloth-refusal": "unified-memory-load" },+ });+ assert.equal(isUnifiedMemoryLoadRefusal({ failure: tagged }), true);+ const other = Object.assign(new Error("x"), {+ headers: { "x-unsloth-refusal": "multi-model-always" },+ });+ assert.equal(isUnifiedMemoryLoadRefusal({ failure: other }), false);+ assert.equal(isUnifiedMemoryLoadRefusal({ failure: new Error("needs about 56 GB") }), false);+ // Wording alone never qualifies: only the backend's code may offer an override.+ assert.equal(+ isUnifiedMemoryLoadRefusal({ failure: "UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD" }),+ false,+ );+});++test("Load anyway is offered for the refusal, and not again once the override was sent", () => {+ const code = UNIFIED_MEMORY_LOAD_REFUSAL;+ assert.equal(shouldOfferLoadAnyway({ code, overrideSent: false }), true);+ assert.equal(shouldOfferLoadAnyway({ code, overrideSent: true }), false);+ assert.equal(shouldOfferLoadAnyway({ code: null, overrideSent: false }), false);+});++test("allow_oversized_load is sent only when the setting or a one-shot retry asks for it", () => {+ assert.equal(allowOversizedLoadField(false, false), undefined);+ assert.equal(allowOversizedLoadField(true, false), true);+ assert.equal(allowOversizedLoadField(false, true), true);+ const plain: { model_path: string; allow_oversized_load?: boolean } = { model_path: "m" };+ assert.deepEqual(withAllowOversizedLoad(plain), { model_path: "m" });+ store.set(ALLOW_OVERSIZED_LOAD_STORAGE_KEY, "true");+ assert.deepEqual(withAllowOversizedLoad(plain), {+ model_path: "m",+ allow_oversized_load: true,+ });+ // An explicit value from the caller wins over the setting.+ assert.deepEqual(withAllowOversizedLoad({ model_path: "m", allow_oversized_load: false }), {+ model_path: "m",+ allow_oversized_load: false,+ });+});++const LOADS = [+ ["Images load", () => images.loadDiffusionModel({ model_path: "Qwen/Qwen-Image" })],+ ["Images plan", () => images.getDiffusionDownloadPlan({ model_path: "Qwen/Qwen-Image" })],+ ["Video load", () => video.loadVideoModel({ model_path: "Lightricks/LTX-2" })],+ ["Video plan", () => video.getVideoDownloadPlan({ model_path: "Lightricks/LTX-2" })],+] as const;++for (const [name, call] of LOADS) {+ test(`${name}: the default sends no override, the setting and a retry send it`, async () => {+ // phase "ready" ends the load notice's own load-progress poll.+ const sent = captureFetch({ entries: [], total_bytes: 0, loaded: false, phase: "ready" });+ await call();+ assert.equal("allow_oversized_load" in sent[0], false, "default must still refuse");+ store.set(ALLOW_OVERSIZED_LOAD_STORAGE_KEY, "true");+ await call();+ assert.equal(sent[1].allow_oversized_load, true);+ });+}++test("a one-shot retry forwards the field without the setting", async () => {+ const sent = captureFetch({ entries: [], total_bytes: 0 });+ await images.getDiffusionDownloadPlan({ model_path: "Qwen/Qwen-Image", allow_oversized_load: true });+ await video.getVideoDownloadPlan({ model_path: "Lightricks/LTX-2", allow_oversized_load: true });+ assert.deepEqual(+ sent.map((b) => b.allow_oversized_load),+ [true, true],+ );+});++test("the plan and load-progress codes are parsed through", async () => {+ captureFetch({+ entries: [],+ total_bytes: 0,+ incompatible_reason: "needs about 56 GB",+ incompatible_code: UNIFIED_MEMORY_LOAD_REFUSAL,+ });+ const plan = await images.getDiffusionDownloadPlan({ model_path: "Qwen/Qwen-Image" });+ assert.equal(plan.incompatible_code, UNIFIED_MEMORY_LOAD_REFUSAL);+ captureFetch({ phase: "error", error: "needs about 56 GB", error_code: UNIFIED_MEMORY_LOAD_REFUSAL });+ assert.equal((await images.getDiffusionLoadProgress()).error_code, UNIFIED_MEMORY_LOAD_REFUSAL);+ assert.equal((await video.getVideoLoadProgress()).error_code, UNIFIED_MEMORY_LOAD_REFUSAL);+});++test("the label matches the setting the backend's refusal names", () => {+ const en = readSrc("i18n/locales/en.ts");+ assert.ok(en.includes(`allowOversizedLoad: "${ALLOW_OVERSIZED_LOAD_LABEL}"`));+ const backend = readText("../../backend/core/inference/diffusion_memory.py");+ assert.ok(backend.includes(ALLOW_OVERSIZED_LOAD_LABEL), "the refusal names a setting the UI does not show");+ assert.ok(backend.includes(`"${UNIFIED_MEMORY_LOAD_REFUSAL}"`));+});++test("both pages offer Load anyway behind a confirmation, and the setting lives in Model memory", () => {+ for (const page of ["features/images/images-page.tsx", "features/video/video-page.tsx"]) {+ const src = readSrc(page);+ assert.match(src, /useLoadAnywayPrompt\(\)/, page);+ assert.match(src, /\{loadAnywayDialog\}/, page);+ assert.match(src, /allow_oversized_load: advanced\.allow_oversized_load/, page);+ assert.match(src, /plan\.incompatible_code/, page);+ assert.match(src, /p\.error_code/, page);+ }+ const dialog = readSrc("components/load-anyway-dialog.tsx");+ // The toast action only opens the confirmation; Confirm is the one place that retries.+ assert.match(dialog, /onClick: \(\) => setPending\(\{ message, retry \}\)/);+ assert.match(dialog, /LOAD_ANYWAY_WARNING/);+ const section = readSrc("features/settings/components/model-memory-section.tsx");+ assert.match(section, /usePersistedToggle\(\s*ALLOW_OVERSIZED_LOAD_STORAGE_KEY/);+});++test("a Load anyway retry from an older pick never starts once a newer pick or load began", () => {+ const { retryWhileCurrent } = refusal;+ const pickSeq = { current: 1 };+ const started: string[] = [];+ const pick = pickSeq.current;+ const stale = retryWhileCurrent(() => pick === pickSeq.current, () => started.push("old"));+ pickSeq.current += 1; // the user picks another model before confirming+ stale();+ assert.equal(started.length, 0, "a stale confirm started the superseded model");+ const newer = pickSeq.current;+ const current = retryWhileCurrent(() => newer === pickSeq.current, () => started.push("new"));+ current();+ assert.deepEqual(started, ["new"], "a current confirm must still retry its pick");+});++test("both pages gate every Load anyway retry on the pick and retire old prompts on a new pick", () => {+ const dialog = readSrc("components/load-anyway-dialog.tsx");+ assert.match(dialog, /return \{ offer, dismiss, dialog \}/);+ for (const page of ["features/images/images-page.tsx", "features/video/video-page.tsx"]) {+ const src = readSrc(page);+ // The plan refusal's retry and the load refusal's retry both re-check the pick.+ assert.match(src, /offerLoadAnyway\(incompatible, retryWhileCurrent\(\(\) => pick === pickSeq\.current,/, page);+ assert.match(src, /retryWhileCurrent\(\s*\(\) => retryPick === pickSeq\.current && startLoad === loadSeq\.current,/, page);+ const beginPick = src.slice(src.indexOf("const beginPick = useCallback"));+ assert.match(beginPick.slice(0, beginPick.indexOf("}, [")), /dismissLoadAnyway\(\);/, page);+ const handleLoad = src.slice(src.indexOf("const handleLoad = useCallback"));+ assert.match(handleLoad.slice(0, handleLoad.indexOf("const settle =")), /dismissLoadAnyway\(\);/, page);+ }+});