Skip to content

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.

Forget the last NVML inventory between backend tests (#15072)

Daniel Hana4f015bd7b6f
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index b12c8de4603..643a6c2ac57 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -226,6 +226,12 @@ def _reset_gpu_query_cache():
if amd is not None and hasattr(amd, "_hip_id_map_lock"):
with amd._hip_id_map_lock:
amd._hip_id_map_cache = None
+ # The last NVML inventory is class state the launch pins the child from: a MIG
+ # probe test leaving its slices there pinned later launches to MIG-dddd4444-0.
+ llama = sys.modules.get("core.inference.llama_cpp")
+ backend = getattr(llama, "LlamaCppBackend", None)
+ if backend is not None and "_NVML_ROWS" in vars(backend):
+ backend._NVML_ROWS = []
_reset()
yield
diff --git a/studio/backend/tests/test_nvml_rows_reset_between_tests.py b/studio/backend/tests/test_nvml_rows_reset_between_tests.py
new file mode 100644
index 00000000000..d5247445a88
--- /dev/null
+++ b/studio/backend/tests/test_nvml_rows_reset_between_tests.py
@@ -0,0 +1,51 @@
+# 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 NVML inventory a probe test leaves behind does not pin the next test's launch.
+
+``LlamaCppBackend._NVML_ROWS`` is the last NVML inventory, class state that
+``_child_visibility_for`` maps indices through. A MIG probe test in
+test_gpu_memory_nvml_fallback.py left its slices there, and placement tests that later ran on
+the same xdist worker with CUDA_VISIBLE_DEVICES unset launched on ``MIG-dddd4444-0`` instead
+of ``0``. The two tests below run in order on one worker: the first leaves rows behind the way
+a real probe does, the second fails unless conftest forgot them in between.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from core.inference.llama_cpp import LlamaCppBackend
+
+pytestmark = pytest.mark.xdist_group("nvml_rows_reset_between_tests")
+
+
+def _mig_row(uuid, free):
+ return {
+ "index": "0",
+ "uuid": uuid,
+ "mig": "1",
+ "memory_total_mib": "20480",
+ "memory_free_mib": str(free),
+ }
+
+
+def test_a_probe_leaves_its_mig_inventory_behind(monkeypatch):
+ monkeypatch.delenv("CUDA_VISIBLE_DEVICES", raising = False)
+ # Assigned, not monkeypatched: _get_gpu_memory writes the class attribute the same way.
+ LlamaCppBackend._NVML_ROWS = [
+ {
+ "index": "0",
+ "uuid": "GPU-aaaa1111-0",
+ "memory_total_mib": "81920",
+ "memory_free_mib": "60000",
+ },
+ _mig_row("MIG-cccc3333-0", 9000),
+ _mig_row("MIG-dddd4444-0", 4000),
+ ]
+ assert LlamaCppBackend._child_visibility_for([0]) == "MIG-dddd4444-0"
+
+
+def test_the_next_test_starts_without_that_inventory(monkeypatch):
+ monkeypatch.delenv("CUDA_VISIBLE_DEVICES", raising = False)
+ assert LlamaCppBackend._NVML_ROWS == []
+ assert LlamaCppBackend._child_visibility_for([0]) == "0"