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.

Stop the slot re-fit tests encoding the fit floor as a literal (#9845)

Daniel Han551756523f43
diff --git a/studio/backend/tests/test_slot_reduction_context_refit.py b/studio/backend/tests/test_slot_reduction_context_refit.py
index 814a3bd9d2f..5b0867e4f3b 100644
--- a/studio/backend/tests/test_slot_reduction_context_refit.py
+++ b/studio/backend/tests/test_slot_reduction_context_refit.py
@@ -249,6 +249,14 @@ class TestWhatMustNotMove:
assert (got["slots"], got["ctx"]) == (slots, ctx)
+# Multiples of the fit floor rather than literals. _AUTO_OFFLOAD_CTX is documented
+# to sit at or above _FIT_MIN_CTX, so sweeping it below the floor would drive the
+# planner through a state the product never reaches and call whatever came back a
+# regression. Identical to [4096, 8192, 16384, 32768] while the floor is 4096, and
+# still the intended sweep after it moves.
+_OFFLOAD_SWEEP = [llama_cpp._FIT_MIN_CTX * step for step in (1, 2, 4, 8)]
+
+
class TestTheReductionIsPricedAtTheFitFloor:
"""The search that picks the slot count must not be priced at _AUTO_OFFLOAD_CTX.
@@ -278,7 +286,7 @@ class TestTheReductionIsPricedAtTheFitFloor:
(10_500, DENSE),
]
- @pytest.mark.parametrize("offload_ctx", [4096, 8192, 16384, 32768])
+ @pytest.mark.parametrize("offload_ctx", _OFFLOAD_SWEEP)
def test_moving_the_offload_fallback_does_not_move_the_placement(
self, tmp_path, monkeypatch, offload_ctx
):
@@ -292,7 +300,7 @@ class TestTheReductionIsPricedAtTheFitFloor:
assert (got["slots"], got["fit"], got["ctx"], got["devices"]) == (2, "off", 7_680, "0")
@pytest.mark.parametrize("weights_mib,metadata", RESCUED)
- @pytest.mark.parametrize("offload_ctx", [4096, 8192])
+ @pytest.mark.parametrize("offload_ctx", _OFFLOAD_SWEEP[:2])
def test_a_load_the_reduction_can_rescue_never_offloads(
self, tmp_path, monkeypatch, weights_mib, metadata, offload_ctx
):
@@ -393,15 +401,26 @@ class TestAGgufWithNoNativeContext:
"""Cover slot reduction when native-context metadata is absent."""
@pytest.mark.parametrize(
- "vram_mib,weights_mib,asked,slots",
+ "vram_mib,weights_mib,asked",
[
- (12 * 1024, 9_000, 8, 3),
- (16 * 1024, 12_000, 8, 5),
+ (12 * 1024, 9_000, 8),
+ (16 * 1024, 12_000, 8),
],
)
def test_the_reduction_still_pins_without_a_native_context(
- self, tmp_path, vram_mib, weights_mib, asked, slots
+ self, tmp_path, vram_mib, weights_mib, asked
):
+ """Without native-context metadata the search has no length to expand to,
+ so the reduction pins at the fit floor itself.
+
+ The floor is read, not spelled 4096, for the reason
+ test_weights_that_fit_nowhere_still_offload gives about _AUTO_OFFLOAD_CTX:
+ a literal here is a re-edit every time the constant moves, and the re-edit
+ is indistinguishable from noticing that placement changed. The exact
+ surviving slot count is left unpinned for the same reason -- it is
+ arithmetic against the floor, not the claim in this test's name. What must
+ hold is that a reduction happened at all and that it stayed resident.
+ """
got = _plan(
tmp_path,
weights_mib = weights_mib,
@@ -410,7 +429,10 @@ class TestAGgufWithNoNativeContext:
vram_mib = vram_mib,
metadata = NO_NATIVE_CTX,
)
- assert (got["slots"], got["fit"], got["ctx"]) == (slots, "off", 4096)
+ assert (got["fit"], got["ctx"]) == ("off", llama_cpp._FIT_MIN_CTX)
+ assert (
+ 1 <= got["slots"] < asked
+ ), f"the reduction did not fire: asked for {asked}, kept {got['slots']}"
def test_no_planner_exception_is_swallowed(self, tmp_path, monkeypatch):
"""The broad placement handler must not hide a planner failure."""
diff --git a/studio/backend/tests/test_slot_refit_ctx_checkpoints.py b/studio/backend/tests/test_slot_refit_ctx_checkpoints.py
index f69dd23e52e..68ad68cce82 100644
--- a/studio/backend/tests/test_slot_refit_ctx_checkpoints.py
+++ b/studio/backend/tests/test_slot_refit_ctx_checkpoints.py
@@ -177,12 +177,29 @@ class TestTheRefitDoesNotSpendTheReserve:
self, tmp_path, checkpoints
):
"""Unpriced, the two stay identical however large --ctx-checkpoints gets,
- while the child allocates it anyway."""
+ while the child allocates it anyway.
+
+ The claim is that the reserve is CHARGED, not that context specifically is
+ what pays. There are three ways to pay, and which one applies depends on how
+ big the reserve is relative to the budget: give up context at the same slot
+ count, give up a slot, or give up residency and offload. At 16 and 32
+ checkpoints this fixture already takes the third -- `--fit on` at the offload
+ fallback -- and `charged["ctx"] < free["ctx"]` only held there by arithmetic
+ coincidence, because the fallback happens to be shorter than the resident
+ plan's context. Naming the three keeps a real regression (nothing was
+ charged: same slots, same context, same residency) distinguishable from the
+ planner picking a different axis, which a raised fit floor can do on its own.
+ """
free = _plan(tmp_path, weights_mib = 9_200, n_parallel = 4, ctx_checkpoints = 0)
charged = _plan(tmp_path, weights_mib = 9_200, n_parallel = 4, ctx_checkpoints = checkpoints)
assert charged["reserve_bytes"] > 0
assert charged["checkpoints"] == str(checkpoints)
- assert charged["ctx"] < free["ctx"], (free, charged)
+ if charged["fit"] != free["fit"]:
+ assert charged["fit"] == "on", (free, charged)
+ elif charged["slots"] != free["slots"]:
+ assert charged["slots"] < free["slots"], (free, charged)
+ else:
+ assert charged["ctx"] < free["ctx"], (free, charged)
def test_a_plan_with_room_for_it_still_stays_on_gpu(self, tmp_path):
"""The reserve costs context, not the GPU pin, while there is room."""
diff --git a/studio/backend/tests/test_slot_refit_platform_matrix.py b/studio/backend/tests/test_slot_refit_platform_matrix.py
index ea8b43612a6..db4d42bfbac 100644
--- a/studio/backend/tests/test_slot_refit_platform_matrix.py
+++ b/studio/backend/tests/test_slot_refit_platform_matrix.py
@@ -95,13 +95,22 @@ class _RefitSpy:
return False
+# The shared fixture the platform cells run on: a load that does not fit at the
+# asked slot count but does fit at a reduced one, so the re-fit has something to do.
+# Named because whether it still sits in that band depends on _FIT_MIN_CTX, and
+# test_the_fixture_still_reaches_the_refit_at_this_fit_floor reports it by name when
+# a floor change moves it out.
+_FIXTURE_WEIGHTS_MIB = 10_200
+_FIXTURE_SLOTS = 4
+
+
def _plan(
tmp_path,
*,
os_key,
vendor,
- weights_mib = 10_200,
- n_parallel = 4,
+ weights_mib = _FIXTURE_WEIGHTS_MIB,
+ n_parallel = _FIXTURE_SLOTS,
vram_mib = CARD_MIB,
n_ctx = 0,
tensor_parallel = False,
@@ -169,14 +178,40 @@ def _plan(
class TestWhoTheRefitIsAllowedToTouch:
+ def test_the_fixture_still_reaches_the_refit_at_this_fit_floor(self, tmp_path):
+ """Anti-vacuity, and the first thing to read when the cells below go red.
+
+ Every REACHABLE cell shares one fixture, and whether that fixture reaches
+ the re-fit at all depends on _FIT_MIN_CTX: the probe prices each candidate
+ at the floor, so raising the floor can leave no slot count that fits, and
+ `if not _uf_slots:` then skips the whole reduction. That turns all nine
+ cells red at once with `assert 0 > 0`, which reads like the re-fit was
+ deleted when the block is untouched and only the fixture went stale.
+ """
+ got, entries = _plan(tmp_path, os_key = "linux", vendor = "nvidia")
+ assert entries > 0, (
+ f"the shared fixture ({_FIXTURE_WEIGHTS_MIB} MiB of weights on a "
+ f"{CARD_MIB} MiB card, asking {_FIXTURE_SLOTS} slots) no longer produces "
+ f"a reducible plan at _FIT_MIN_CTX={llama_mod._FIT_MIN_CTX}. The planner "
+ f"returned {got}. Resize the fixture into the reducible band -- the nine "
+ f"cells below are about WHICH hosts may re-fit, and cannot answer that "
+ f"question from a fixture where nobody can."
+ )
+
@pytest.mark.parametrize("os_key,vendor", ALL_CELLS, ids = [f"{o}-{v}" for o, v in ALL_CELLS])
def test_only_a_gpu_host_enters_the_refit(self, tmp_path, os_key, vendor):
"""Metal and CPU-only hosts must not reach the new block at all."""
- _, entries = _plan(tmp_path, os_key = os_key, vendor = vendor)
+ got, entries = _plan(tmp_path, os_key = os_key, vendor = vendor)
if (os_key, vendor) in REACHABLE:
- assert entries > 0, f"{os_key}/{vendor} should re-fit"
+ assert entries > 0, (
+ f"{os_key}/{vendor} should re-fit but made no reduced-slot probe. "
+ f"If every REACHABLE cell failed together the fixture is stale, not "
+ f"the platform gate -- see "
+ f"test_the_fixture_still_reaches_the_refit_at_this_fit_floor. "
+ f"Plan: {got}"
+ )
else:
- assert entries == 0, f"{os_key}/{vendor} must not re-fit"
+ assert entries == 0, f"{os_key}/{vendor} must not re-fit, but did. Plan: {got}"
@pytest.mark.parametrize("os_key", ["macos_arm", "macos_intel"])
def test_macos_plans_exactly_as_it_did(self, tmp_path, os_key):