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
Fix the Backend CI test failures after the branch-restore and Omni routing merges (#13173)
Daniel Han8002a80aaf34
diff --git a/tests/studio/test_new_chat_context_recount.py b/tests/studio/test_new_chat_context_recount.pyindex 595f5daae5f..e6370aaf393 100644--- a/tests/studio/test_new_chat_context_recount.py+++ b/tests/studio/test_new_chat_context_recount.py@@ -611,9 +611,23 @@ export async function hydrateThreadUsage(props: any): Promise<void> {// The loader is created per pane; a compare pane carries a pairId and never owns the bar.const modelType: string = props.modelType ?? "base";const pairId = props.pairId ?? undefined;- // The thread's stored messages, which the loader reads into `msgs` above the sliced block.- // The block prices them with `estimateContextUsage` when nothing saved is usable (#9475).- const msgs: any[] = props.messages ?? [];+ // The thread's stored messages, which the loader reads into `msgs` and sorts above the sliced+ // block (createdAt, then role, then id), so `msgs.at(-1)` below is the newest stored row.+ const roleOrder: Record<string, number> = { system: 0, user: 1, assistant: 2 };+ const msgs: any[] = [...(props.messages ?? [])].sort((a: any, b: any) => {+ if (a.createdAt !== b.createdAt) return a.createdAt - b.createdAt;+ const aOrder = roleOrder[a.role] ?? 99;+ const bOrder = roleOrder[b.role] ?? 99;+ if (aOrder !== bOrder) return aOrder - bOrder;+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;+ });+ // The branch the loader selects from `msgs` above the sliced block, which the block prices with+ // `estimateContextUsage` when nothing saved is usable (#9475, #13109). No head is saved here, so+ // it follows the newest stored row to its leaf, as the loader does without one.+ const branch: any[] = orderBySelectedBranch(+ msgs,+ resolveSavedBranchHead(msgs, props.savedHeadId ?? msgs.at(-1)?.id),+ );// Read once, as the loader does, just above the sliced block.const store = useChatRuntimeStore.getState();__RESTORE__@@ -1598,9 +1612,12 @@ def test_the_harness_binds_every_loader_local_the_history_restore_reads() -> Nonfor name in declared_above - declared_in_sliceif re.search(rf"(?<![\w$.]){re.escape(name)}\b", code))- assert {"msgs", "remoteId"} <= set(- read_from_above- ), "the guard no longer sees the restore read `msgs` and the destructured `remoteId`"+ # The block's own inputs change (#13109 moved the estimate from `msgs` to the selected+ # `branch`), so pin only what proves the scan works: the destructured `remoteId`, and at least+ # one plain `const` from above the slice.+ assert "remoteId" in read_from_above and set(read_from_above) - {+ "remoteId"+ }, f"the guard no longer sees the restore read loader locals, only {read_from_above}"bound = _declared_names(HARNESS_HISTORY)missing = [name for name in read_from_above if name not in bound]assert not missing, (diff --git a/tests/test_omni_auto_class_resolution.py b/tests/test_omni_auto_class_resolution.pyindex 6c8ed70275f..9a515ce5041 100644--- a/tests/test_omni_auto_class_resolution.py+++ b/tests/test_omni_auto_class_resolution.py@@ -251,6 +251,10 @@ def _route(tmp_path, monkeypatch, config):monkeypatch.setattr(loader.FastBaseModel, "from_pretrained", staticmethod(capture))# Its pinned host buffer needs an accelerator; CPU CI has none.monkeypatch.setattr(loader, "apply_unsloth_gradient_checkpointing", lambda value, *args: value)+ # The load repoints transformers' LOSS_MAPPING at Unsloth's Triton loss for the whole process+ # before the route is captured. Routing needs none of it, and left behind it sends every later+ # CPU forward with labels in this worker into Triton (test_omni_text_only_load failed that way).+ monkeypatch.setattr(loader, "patch_loss_functions", lambda *args, **kwargs: None)with pytest.raises(_Routed) as routed:loader.FastModel.from_pretrained(str(tmp_path), load_in_4bit = False)return routed.value.args[0]diff --git a/tests/test_omni_text_only_load.py b/tests/test_omni_text_only_load.pyindex 1e3782d6b09..4da9e8c363c 100644--- a/tests/test_omni_text_only_load.py+++ b/tests/test_omni_text_only_load.py@@ -23,6 +23,28 @@ VOCAB = 64DEVICE = "cuda" if has_real_cuda() else "cpu"[email protected](autouse = True)+def _stock_causal_lm_loss_on_cpu():+ """Any Unsloth load repoints LOSS_MAPPING at the Triton loss for the whole process, which a CPU+ host cannot run ("0 active drivers"): one earlier in this worker, or this file's own+ `_capture_fast_base_kwargs`. These tests are about where the forward goes, so on CPU they price it+ with transformers' own loss and put the whole mapping back afterwards, leaking nothing to the next+ test in the worker. On a GPU host they keep Unsloth's, as before."""+ if DEVICE != "cpu":+ yield+ return+ loss_utils = pytest.importorskip("transformers.loss.loss_utils")+ saved = dict(loss_utils.LOSS_MAPPING)+ for key, fn in saved.items():+ if getattr(fn, "__name__", "") != "ForCausalLMLoss" and "Unsloth" in repr(fn):+ loss_utils.LOSS_MAPPING[key] = loss_utils.ForCausalLMLoss+ try:+ yield+ finally:+ loss_utils.LOSS_MAPPING.clear()+ loss_utils.LOSS_MAPPING.update(saved)++def _tiny_config():text = dict(vocab_size = VOCAB,