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
Studio: ask Laya questions without instructions by their id (#16496)
Nilayd0a83c473eb9
diff --git a/studio/backend/core/systemone/laya_runtime.py b/studio/backend/core/systemone/laya_runtime.pyindex 002f8f11b3f..cf204a58edd 100644--- a/studio/backend/core/systemone/laya_runtime.py+++ b/studio/backend/core/systemone/laya_runtime.py@@ -1661,8 +1661,12 @@ def _agent_for(checkpoint: Checkpoint, wait: float):return _agent-def _to_laya(question: dict[str, Any]) -> dict[str, Any]:- out = {"type": question["type"], "instructions": question.get("instructions") or ""}+def _to_laya(question: dict[str, Any], name = "") -> dict[str, Any]:+ instructions = question.get("instructions")+ out = {+ "type": question["type"],+ "instructions": str(name) if instructions in (None, "") else instructions,+ }if question.get("criteria") is not None:out["criteria"] = question["criteria"]return out@@ -2350,7 +2354,7 @@ def _decide(}if checkpoint.layout == "clef":return _decide_clef(checkpoint, agent, state, questions)- laya_questions = {name: _to_laya(q) for name, q in questions.items()}+ laya_questions = {name: _to_laya(q, name) for name, q in questions.items()}try:if isinstance(agent, LayaWorker):result, truncated = agent.predict(state, laya_questions)diff --git a/studio/backend/tests/test_systemone.py b/studio/backend/tests/test_systemone.pyindex 4d613058063..e5671ed9111 100644--- a/studio/backend/tests/test_systemone.py+++ b/studio/backend/tests/test_systemone.py@@ -201,7 +201,36 @@ def test_model_loaded_once_and_questions_forwarded(client, runtime):assert runtime == ["laya-multilingual"]state, questions = laya_runtime._agent.calls[-1]assert state == {"subject": "Charged twice"}- assert questions == {"q": {"type": "noul", "instructions": ""}}+ assert questions == {"q": {"type": "noul", "instructions": "q"}}++[email protected]("instructions", [None, ""])+def test_question_without_instructions_is_asked_by_its_id(client, runtime, instructions):+ _post(+ client,+ questions = {+ "refund": {"type": "noul", "instructions": instructions},+ "team": {"type": "choice", "criteria": {"a": "first"}},+ "late": {"type": "noul", "instructions": "Is it late?"},+ },+ )+ _, questions = laya_runtime._agent.calls[-1]+ assert {name: q["instructions"] for name, q in questions.items()} == {+ "refund": "refund",+ "team": "team",+ "late": "Is it late?",+ }++[email protected]("instructions", [{}, [], {"prompt": "Refund?"}, ["Refund?"]])+def test_structured_question_instructions_are_forwarded_unchanged(client, instructions):+ response = _post(+ client,+ questions = {"refund": {"type": "noul", "instructions": instructions}},+ )+ assert response.status_code == 200, response.text+ _, questions = laya_runtime._agent.calls[-1]+ assert questions["refund"]["instructions"] == instructionsdef test_named_checkpoint_swaps_the_resident_model(client, runtime):diff --git a/tests/test_decision_model.py b/tests/test_decision_model.pyindex 4dbd3641890..763cdad2614 100644--- a/tests/test_decision_model.py+++ b/tests/test_decision_model.py@@ -569,6 +569,29 @@ def test_compiled_layers_checkpoint_with_torch_and_get_unsloths_back(assert all(layer._gradient_checkpointing_func is offloaded for layer in layers)[email protected]("instructions", [None, ""])+def test_a_question_without_instructions_is_read_by_its_id(checkpoint, instructions):+ model, tokenizer = FastDecisionModel.from_pretrained(+ str(checkpoint), use_gradient_checkpointing = False+ )+ state = "the server is down again"+ blank = {"type": "noul", "instructions": instructions}+ named = {name: {"type": "noul", "instructions": name} for name in ("outage", "billing")}++ answers = FastDecisionModel.predict(model, tokenizer, state, dict.fromkeys(named, blank))+ assert answers == FastDecisionModel.predict(model, tokenizer, state, named)++ def tokens(questions):+ gold = dict.fromkeys(questions, {"label": "true"})+ row = {"state": state, "questions": questions, "gold": gold}+ return [+ item["input_ids"]+ for item in FastDecisionModel.build_dataset([row], tokenizer, model)[0]+ ]++ assert tokens(dict.fromkeys(named, blank)) == tokens(named)++def test_a_resized_laya_vocabulary_saves_and_reloads(checkpoint, tmp_path):model, tokenizer = FastDecisionModel.from_pretrained(str(checkpoint), use_gradient_checkpointing = Falsediff --git a/tests/test_decision_model_mlx.py b/tests/test_decision_model_mlx.pyindex 40d4b671127..bc45421ea53 100644--- a/tests/test_decision_model_mlx.py+++ b/tests/test_decision_model_mlx.py@@ -405,6 +405,27 @@ def test_predict_answers_at_the_calibrated_temperatures(checkpoint, monkeypatch)FastDecisionModel.predict(model, tokenizer, "s", {})[email protected]("instructions", [None, ""])+def test_a_question_without_instructions_is_read_by_its_id(checkpoint, instructions):+ model, tokenizer = FastDecisionModel.from_pretrained(str(checkpoint))+ state = "the server is down again"+ blank = {"type": "noul", "instructions": instructions}+ named = {name: {"type": "noul", "instructions": name} for name in ("outage", "billing")}++ answers = FastDecisionModel.predict(model, tokenizer, state, dict.fromkeys(named, blank))+ assert answers == FastDecisionModel.predict(model, tokenizer, state, named)++ def tokens(questions):+ gold = dict.fromkeys(questions, "true")+ row = {"state": state, "questions": questions, "gold": gold}+ return [+ item["input_ids"]+ for item in FastDecisionModel.build_dataset([row], tokenizer, model)[0]+ ]++ assert tokens(dict.fromkeys(named, blank)) == tokens(named)++def test_the_images_of_a_row_reach_the_clef_trainer_and_predict(clef_checkpoint, checkpoint, monkeypatch, tmp_path):diff --git a/unsloth/models/_decision_common.py b/unsloth/models/_decision_common.pyindex 043bb4b3be5..e3826f909b5 100644--- a/unsloth/models/_decision_common.py+++ b/unsloth/models/_decision_common.py@@ -261,7 +261,7 @@ def _row_images(row: dict) -> list:return found-def _internal(question) -> dict:+def _internal(question, name = "") -> dict:if not isinstance(question, dict) or question.get("type") not in QUESTION_TYPES:raise DecisionDataError("is not a valid question")kind, criteria = question["type"], question.get("criteria")@@ -275,7 +275,11 @@ def _internal(question) -> dict:raise DecisionDataError("needs a list of criteria levels")if kind == "noul" and criteria is not None and not isinstance(criteria, dict):raise DecisionDataError('criteria may only have "true" and "false"')- laya_question = {"type": kind, "instructions": question.get("instructions") or ""}+ instructions = question.get("instructions")+ laya_question = {+ "type": kind,+ "instructions": str(name) if instructions in (None, "") else instructions,+ }if criteria is not None:laya_question["criteria"] = criteriareturn _laya().agent.Agent._to_internal(laya_question)diff --git a/unsloth/models/decision.py b/unsloth/models/decision.pyindex 2db0cd4e39e..3ac49d0d7b5 100644--- a/unsloth/models/decision.py+++ b/unsloth/models/decision.py@@ -625,7 +625,7 @@ def _laya_decide(max_len = int(config.get("max_len", 512))items, keys = [], []for name, question in questions.items():- internal = _internal(question)+ internal = _internal(question, name)ids, markers = common.build_sequence(tokenizer, _parsed(state), internal, max_len, int(config.get("head_max_len", 192)))@@ -1795,7 +1795,7 @@ class FastDecisionModel:try:if validate is not None:validate(name, question)- internal = _internal(question)+ internal = _internal(question, name)target, label = _target(internal, _parsed(gold[name]))ids, markers = common.build_sequence(tokenizer, state, internal, max_len, head_max_lendiff --git a/unsloth/models/decision_mlx.py b/unsloth/models/decision_mlx.pyindex ea77caf6ebc..7c6b205fd7f 100644--- a/unsloth/models/decision_mlx.py+++ b/unsloth/models/decision_mlx.py@@ -182,7 +182,7 @@ def _decision_dataset(try:if validate is not None:validate(name, question)- internal = _internal(question)+ internal = _internal(question, name)target, label = _target(internal, _parsed(gold[name]))ids, markers = common.build_sequence(tokenizer, state, internal, max_len, head_max_len@@ -912,7 +912,7 @@ class FastDecisionModel:tokenizer = getattr(tokenizer, "tokenizer", tokenizer)items, keys = [], []for name, question in questions.items():- internal = _internal(question)+ internal = _internal(question, name)ids, markers = common.build_sequence(tokenizer, state, internal, max_len, int(config.get("head_max_len", 192)))