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 tests: keep GGUF loads off the host's Metal budget unless a test asks (#15910)
Daniel Handa8ec323b19c
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.pyindex 0308c38c46d..d96adf5c9fd 100644--- a/studio/backend/tests/conftest.py+++ b/studio/backend/tests/conftest.py@@ -590,17 +590,43 @@ def _hf_cache_is_empty(_empty_hf_hub_cache, monkeypatch):monkeypatch.setattr(constants, "HF_HUB_CACHE", _empty_hf_hub_cache)+_REAL_APPLE_METAL_BUDGET = None++@pytest.fixture(autouse = True)def _no_live_metal_wired_ceiling(monkeypatch):"""Keep Metal context verdicts off the host's live GPU memory."""+ import inspect+from core.inference.llama_cpp import LlamaCppBackend+ global _REAL_APPLE_METAL_BUDGET+ if _REAL_APPLE_METAL_BUDGET is None:+ _REAL_APPLE_METAL_BUDGET = inspect.getattr_static(+ LlamaCppBackend, "_apple_metal_memory_budget_bytes"+ )monkeypatch.setattr(LlamaCppBackend, "_apple_metal_wired_ceiling_bytes", staticmethod(lambda: 0))monkeypatch.setattr(LlamaCppBackend, "_apple_metal_wired_headroom_bytes", staticmethod(lambda: None))+ # On a Mac the real budget is non-zero, which sends every GGUF load down the Metal+ # context-fit path and adds its "cannot size the KV cache" notice to loads that tests+ # written against a CPU or CUDA host expect to be silent. Tests of the budget itself,+ # or of the Metal path, set it explicitly or ask for real_apple_metal_budget.+ monkeypatch.setattr(+ LlamaCppBackend, "_apple_metal_memory_budget_bytes", staticmethod(lambda: 0)+ )+++def real_apple_metal_budget(monkeypatch):+ """The real budget probe, for the tests of the probe itself."""+ from core.inference.llama_cpp import LlamaCppBackend+ monkeypatch.setattr(+ LlamaCppBackend, "_apple_metal_memory_budget_bytes", _REAL_APPLE_METAL_BUDGET+ )@pytest.fixture(autouse = True)diff --git a/studio/backend/tests/test_health_reports_unified_memory.py b/studio/backend/tests/test_health_reports_unified_memory.pyindex 238facd5af8..faeb2daf660 100644--- a/studio/backend/tests/test_health_reports_unified_memory.py+++ b/studio/backend/tests/test_health_reports_unified_memory.py@@ -107,7 +107,7 @@ def test_an_unauthenticated_reply_carries_neither(monkeypatch):assert "apple_silicon" not in body-def test_the_gate_is_the_one_the_metal_budget_uses(monkeypatch):+def test_the_gate_is_the_one_the_metal_budget_uses(monkeypatch, real_apple_metal_budget):"""Not a second definition of Apple Silicon. If these ever diverge, the UI startsdescribing a memory model the loader is not enforcing."""import inspectdiff --git a/studio/backend/tests/test_llama_cpp_context_fit.py b/studio/backend/tests/test_llama_cpp_context_fit.pyindex e5825bffc8a..6ab55a361ea 100644--- a/studio/backend/tests/test_llama_cpp_context_fit.py+++ b/studio/backend/tests/test_llama_cpp_context_fit.py@@ -667,6 +667,7 @@ def _install_fake_psutil(monkeypatch.setitem(sys.modules, "psutil", fake)[email protected]("real_apple_metal_budget")class TestAppleUnifiedMemoryBudget:def test_zero_off_apple_silicon(self, monkeypatch):import platform as _platformdiff --git a/studio/backend/tests/test_loads_stay_off_the_host_metal_budget.py b/studio/backend/tests/test_loads_stay_off_the_host_metal_budget.pynew file mode 100644index 00000000000..d849f1da4cd--- /dev/null+++ b/studio/backend/tests/test_loads_stay_off_the_host_metal_budget.py@@ -0,0 +1,25 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The suite runs on a macos-15 leg too. There the real unified-memory budget is non-zero, and+every GGUF load a test drives takes the Metal context-fit path, which the tests were not+written for. conftest pins the budget to 0; these check the pin holds on any host."""++import utils.hardware as hardware+import utils.hardware.hardware as hardware_impl+from core.inference.llama_cpp import LlamaCppBackend+++def _host_is_apple_silicon(monkeypatch):+ monkeypatch.setattr(hardware, "is_apple_silicon", lambda: True)+ monkeypatch.setattr(hardware_impl, "_metal_recommended_working_set_bytes", lambda: 16 * 1024**3)+++def test_a_load_on_apple_silicon_sees_no_metal_budget_by_default(monkeypatch):+ _host_is_apple_silicon(monkeypatch)+ assert LlamaCppBackend._apple_metal_memory_budget_bytes() == 0+++def test_the_real_probe_is_back_when_a_test_asks_for_it(monkeypatch, real_apple_metal_budget):+ _host_is_apple_silicon(monkeypatch)+ assert LlamaCppBackend._apple_metal_memory_budget_bytes() > 0