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
Ask the repo, not sys.path, whether a stubbed name is third-party (#9133)
Daniel Han019a4819d411
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 5c5542d8590..5a6a41db55a 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -7018,7 +7018,9 @@ class LlamaCppBackend:# memory.current includes file-backed cache. Inactive file pages# are reclaimable under pressure, so price the launch against the# cgroup working set rather than charging cached GGUF pages twice.- used = max(0, used - _stat_integer(os.path.join(directory, "memory.stat"), "inactive_file"))+ used = max(+ 0, used - _stat_integer(os.path.join(directory, "memory.stat"), "inactive_file")+ )remaining.append(limit if used is None else limit - used)v1_root = os.path.join(_CGROUP_ROOT, "memory")@@ -7043,7 +7045,9 @@ class LlamaCppBackend:0,used- _stat_integer(- os.path.join(directory, "memory.stat"), "total_inactive_file", "inactive_file"+ os.path.join(directory, "memory.stat"),+ "total_inactive_file",+ "inactive_file",),)remaining.append(limit if used is None else limit - used)@@ -7059,7 +7063,6 @@ class LlamaCppBackend:available = Nonetry:import psutil-available = int(psutil.virtual_memory().available // (1024 * 1024))except Exception:pass@@ -14322,11 +14325,7 @@ class LlamaCppBackend:# Vulkan reports total 0 only for integrated GPUs. Their# free "VRAM" is the same host pool the RAM guard prices._shared_gpu_ids = (- {- idx- for idx, _free in _detected_gpus- if total_by_idx.get(idx, 1) <= 0- }+ {idx for idx, _free in _detected_gpus if total_by_idx.get(idx, 1) <= 0}if is_vulkan_backendelse set())diff --git a/tests/studio/test_backend_ci_parallel_isolation.py b/tests/studio/test_backend_ci_parallel_isolation.pyindex 8b1b8e4c055..2ee2c8f5b81 100644--- a/tests/studio/test_backend_ci_parallel_isolation.py+++ b/tests/studio/test_backend_ci_parallel_isolation.py@@ -151,8 +151,10 @@ BENIGN_TIMING = {# A 600-second expiry checked against the wall clock. Reading both sides of that gap# late by whole seconds still leaves it true, and it only reaches this scan at all# because the widened operand walk now reads `x > time.time()` as a bound.- ("test_openai_codex_subscription.py",- "test_account_claim_and_token_response_are_validated_without_returning_raw_body"),+ (+ "test_openai_codex_subscription.py",+ "test_account_claim_and_token_response_are_validated_without_returning_raw_body",+ ),}@@ -569,14 +571,32 @@ def _assigned_into_sys_modules(tree: ast.AST) -> set:return names-def _is_installed(name: str) -> bool:- """Whether a stub for this name would shadow something real.+def _is_repo_module(name: str) -> bool:+ """Whether studio/backend itself provides this name.++ `loggers`, `utils`, `routes` and friends are the backend's OWN modules. A test that+ stands one of them up as a stub is not shadowing a third-party library, which is what+ the check below is about; it is substituting for repo code on purpose.+ """+ return (BACKEND_TESTS.parent / name).is_dir() or (BACKEND_TESTS.parent / f"{name}.py").is_file()+- Anything the machinery cannot resolve counts as absent, including the errors it- raises rather than returning None for: an in-repo name such as `utils` or `loggers`- is importable only with studio/backend on sys.path, which this test does not have and- should not add.+def _is_installed(name: str) -> bool:+ """Whether a stub for this name would shadow a real third-party library.++ Asked of the REPO first, and that ordering is the whole fix. The previous version+ asked importlib alone and reasoned that an in-repo name resolves only with+ studio/backend on sys.path, "which this test does not have and should not add". That+ was simply untrue in the job that runs it: under `pytest tests/ -n 4` from the repo+ root, studio/backend does end up on sys.path, `loggers` resolved, and the guard+ failed on main for a stub that shadows nothing. It passed locally, where the path+ happens to differ, which is the worst shape a CI-only assertion can have.++ So the question is answered from the tree, which is the same everywhere, and+ importlib is consulted only for names the repo does not define."""+ if _is_repo_module(name):+ return Falsetry:return importlib.util.find_spec(name) is not Noneexcept (ImportError, ValueError):