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
Put the smart offload planner back behind its flag (#9862)
Daniel Han79452f37c3bb
diff --git a/studio/backend/core/inference/offload_planner.py b/studio/backend/core/inference/offload_planner.pyindex de8014414ea..249e95a45a8 100644--- a/studio/backend/core/inference/offload_planner.py+++ b/studio/backend/core/inference/offload_planner.py@@ -857,21 +857,29 @@ _SMART_OFFLOAD_ON = ("1", "true", "yes", "on", "enabled")def smart_offload_enabled(env: Optional[Mapping[str, str]] = None) -> bool:- """Whether the launch path may plan a spill. ON unless explicitly disabled.-- It shipped opt-in "until it has run on more than one machine". It has: 118- paired runs across T4, L4, RTX PRO 6000, A100, B200 and a real gfx1151 APU,- faster on generation in 111, and 100% KV cache retention in all 83 runs- where the layer-count arm would have split the cache to host RAM.-- Default does not mean it places every load: it abstains often, and every- abstain still falls through to ``--fit on``.-- An UNRECOGNISED value disables. The typos are not symmetric for an opt-OUT- flag: ``flase`` meaning off must not hand back the thing it was switching- off, while fumbling an on-spelling only keeps the old behaviour.+ """Whether the launch path may plan a spill. OFF unless explicitly enabled.++ This was briefly opt-OUT, on 118 paired runs across T4, L4, RTX PRO 6000,+ A100, B200 and a gfx1151 APU. Every one of those hosts is a large one, and+ that turned out to be the whole of the calibration set: #9861 measured 76+ paired cells on a 6-core desktop and the planner was slower in 40 of the 43+ it planned, by up to 8x on generation.++ The mechanism is not the host size alone. ``rank`` in offload_cost_model+ scores a placement as prefill PLUS generation, but the planner only ever+ calls ``generation_penalty_ms``, so prefill is not priced at all -- which is+ why #9861 measured prefill slower in 43 of 43 planned cells, without one+ exception. A gate that does not count half the request cannot be trusted to+ fire by default, so it goes back behind the flag until it does.++ Off does not mean the load is unplaced: every path that would have consulted+ the planner falls through to ``--fit on``, which is what the same report+ measured at 0.93x to 1.16x across all 33 cells where the planner declined.++ An UNRECOGNISED value disables, same as before, and now agrees with the+ default rather than reversing it."""raw = (os.environ if env is None else env).get("UNSLOTH_SMART_OFFLOAD")if raw is None:- return True+ return Falsereturn str(raw).strip().lower() in _SMART_OFFLOAD_ONdiff --git a/studio/backend/tests/test_offload_planner_seam.py b/studio/backend/tests/test_offload_planner_seam.pyindex 8abaa5db350..5cf6ce319e3 100644--- a/studio/backend/tests/test_offload_planner_seam.py+++ b/studio/backend/tests/test_offload_planner_seam.py@@ -212,15 +212,22 @@ def test_the_seam_reads_no_attribute_the_real_backend_lacks():assert "self._HOST_RAM_HEADROOM_MIB" not in source-def test_the_planner_is_on_by_default():- """No env, a plan. The flag is now opt-OUT."""- assert smart_offload_enabled({}) is True- # A load that fits is still PLANNED, it just spills nothing.- roomy = _Stub()._planned_tensor_spill(_inputs(), env = {})- assert roomy is not None and not roomy.spills_anything-- # A load that does not fit gets a real plan with no env set at all.- tight = _Stub()._planned_tensor_spill(_inputs(free_mib = 14 * 1024), env = {})+def test_the_planner_is_off_by_default():+ """No env, no plan. The flag is opt-IN again after #9861.++ A load that would otherwise get a real spill plan is the case that matters:+ if only the roomy one were checked, the default could flip back unnoticed,+ since a fitting load plans nothing either way.+ """+ assert smart_offload_enabled({}) is False+ assert _Stub()._planned_tensor_spill(_inputs(), env = {}) is None+ assert _Stub()._planned_tensor_spill(_inputs(free_mib = 14 * 1024), env = {}) is None++ # The same tight load still plans when asked explicitly, so the revert moved+ # the default and nothing else.+ tight = _Stub()._planned_tensor_spill(+ _inputs(free_mib = 14 * 1024), env = {"UNSLOTH_SMART_OFFLOAD": "1"}+ )assert tight is not None and tight.spills_anything@@ -238,9 +245,8 @@ def test_an_explicit_off_still_disables(value):@pytest.mark.parametrize("value", ["nope", "flase", "onn", "2"])def test_an_unrecognised_value_disables_rather_than_enables(value):- """The typos are not symmetric for an opt-OUT flag: `flase` meaning off must- not hand back the thing it was switching off, while fumbling an on-spelling- only keeps the previous behaviour."""+ """A fumbled on-spelling must not turn the planner on by accident, and now+ lands on the same answer as setting nothing at all."""assert smart_offload_enabled({"UNSLOTH_SMART_OFFLOAD": value}) is False