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
Point dsh at Unsloth through a --patch overlay instead of settings.yaml (#12145)
Daniel Han2c030204c079
diff --git a/.github/scripts/agent-guides-drive.sh b/.github/scripts/agent-guides-drive.shindex 6c05cf9aa70..ebe03872ed1 100755--- a/.github/scripts/agent-guides-drive.sh+++ b/.github/scripts/agent-guides-drive.sh@@ -354,12 +354,14 @@ crosscheck_contract() {|| guide_fail "dsh env key is no longer UNSLOTH_API_KEY (start.py _DSH_ENV_KEY)"home="$(raw_env DSH_HOME)"[ -n "$home" ] || guide_fail "DSH_HOME missing from connect output (start.py dsh())"- cfg="$home/settings.yaml"- if [ -f "$cfg" ]; then- grep -q 'openai-completions' "$cfg" \- || echo "::warning::dsh provider api is no longer 'openai-completions' (write_dsh_config)"- cp "$cfg" "$REDACTED_DIR/dsh-settings.yaml"- fi+ # A --patch overlay, not settings.yaml: dsh 0.1.7 imports that only after the first boot.+ cfg="$home/unsloth.patch.yml"+ [ -f "$cfg" ] || guide_fail "dsh patch $cfg missing (start.py write_dsh_patch)"+ grep -qF -- "--patch $cfg" "$raw" \+ || guide_fail "dsh launch command no longer passes --patch $cfg (start.py _dsh_command)"+ grep -q 'openai-completions' "$cfg" \+ || echo "::warning::dsh provider api is no longer 'openai-completions' (write_dsh_patch)"+ cp "$cfg" "$REDACTED_DIR/dsh-patch.yml";;esacredact "$REDACTED_DIR"/* 2>/dev/null || truediff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.pyindex a0c4557f6ae..6eeaf620609 100644--- a/unsloth_cli/commands/start.py+++ b/unsloth_cli/commands/start.py@@ -77,6 +77,7 @@ _HERMES_POSIX_INSTALL_HINT = (_HERMES_MIN_CONTEXT = 65536_DSH_PROVIDER = "unsloth"_DSH_ENV_KEY = "UNSLOTH_API_KEY"+_DSH_PATCH_FILE = "unsloth.patch.yml"_DSH_PACKAGE = "@deepseek-ai/dsh"# dsh picks its sandbox+approval preset from DSH_PERMISSION_MODE via ??, so omitting it would inherit a danger-full-access exported in the parent shell, and "" is not unset to ??. Pin the mode in both directions instead of only setting it for --yolo._DSH_SAFE_PERMISSION_MODE = "workspace-write"@@ -569,11 +570,22 @@ _DSH_LAUNCHER_ARGS = frozenset()-def _dsh_command(args: list[str]) -> list[str]:+# Launcher invocations that boot no profile, so they take no --patch overlay.+_DSH_NO_PROFILE_ARGS = frozenset("-V --version plugin".split())+++def _dsh_command(args: list[str], patch: Optional[str] = None) -> list[str]:head = args[0] if args else ""if head in _DSH_LAUNCHER_ARGS or head.startswith(("--profile=", "--patch=")):- return ["dsh", *args]- return ["dsh", "web", *args]+ command = ["dsh", *args]+ else:+ command = ["dsh", "web", *args]+ if patch is not None and command[1] not in _DSH_NO_PROFILE_ARGS:+ # `dsh <name>` only expands to `--profile <name>` when the name comes first, so the+ # overlay goes after a bare profile name and ahead of a leading launcher option.+ at = 1 if command[1].startswith("-") else 2+ command[at:at] = ["--patch", patch]+ return commandclass LoadOptions(NamedTuple):@@ -4953,37 +4965,47 @@ def write_pi_subagent_config()-def write_dsh_config(base: str, model: dict, path: Path) -> None:+def write_dsh_patch(base: str, model: dict, path: Path) -> None:+ """Write the dsh loader patch that points the booted profile at Unsloth.++ dsh 0.1.7 dropped `settings.yaml`: it now imports a leftover one into the profile only+ after the first boot has settled, so that boot still runs on the DeepSeek default. A+ `--patch` overlay is read at boot on every dsh release this supports, and the file is+ Unsloth's own, so it is rewritten whole rather than merged.+ """import yaml- config = _read_yaml_object(path)- if config is None:- typer.echo(- f"Warning: couldn't parse {path} — add an '{_DSH_PROVIDER}' provider "- "there yourself, or move the file aside and re-run.",- err = True,- )- returnmodel_entry = {"id": model["id"]}window = model.get("context_length") or model.get("max_context_length")if window:window = int(window)model_entry["contextWindow"] = windowmodel_entry["maxTokens"] = min(window // 4, 8192)- _subdict(_subdict(config, "llm-pi-ai"), "providers")[_DSH_PROVIDER] = {- "displayName": "Unsloth Studio",- "api": "openai-completions",- "baseURL": f"{base}/v1",- "apiKeyEnv": _DSH_ENV_KEY,- # pi-ai reads an unknown base URL as OpenAI itself.- "compat": {"supportsDeveloperRole": False, "maxTokensField": "max_tokens"},- "models": [model_entry],- }- _subdict(config, "agent-default-model").update(- provider = _DSH_PROVIDER,- model = model["id"],- )- text = yaml.safe_dump(config, sort_keys = False)+ entries = [+ {+ "id": "llm-pi-ai",+ "name": "@deepseek-ai/dsh-llm-pi-ai",+ "config": {+ "providers": {+ _DSH_PROVIDER: {+ "displayName": "Unsloth Studio",+ "api": "openai-completions",+ "baseURL": f"{base}/v1",+ "apiKeyEnv": _DSH_ENV_KEY,+ # pi-ai reads an unknown base URL as OpenAI itself.+ "compat": {"supportsDeveloperRole": False, "maxTokensField": "max_tokens"},+ "models": [model_entry],+ }+ }+ },+ },+ {+ "id": "agent-default-model",+ "name": "@deepseek-ai/dsh-agent-default-model",+ "config": {"provider": _DSH_PROVIDER, "model": model["id"]},+ },+ ]+ text = yaml.safe_dump(entries, sort_keys = False)if not path.exists() or path.read_text(encoding = "utf-8") != text:path.parent.mkdir(parents = True, exist_ok = True)path.write_text(text, encoding = "utf-8")@@ -5709,7 +5731,6 @@ def dsh("""Point DeepSeek Harness (dsh) at the running Unsloth server and start it."""model, ctx.args[:] = _consume_positional_model(model, ctx.args)_reject_as_subagent("dsh", ctx.args)- command = _dsh_command(ctx.args)install_hint = _npm_install_hint(_DSH_PACKAGE)_require_agent_for_launch("dsh", install_hint, launch)base, key, entry = _connect(@@ -5735,7 +5756,10 @@ def dsh(),)with _session_config("dsh", launch, persist = persist) as home:- write_dsh_config(base, entry, home / "settings.yaml")+ patch = home / _DSH_PATCH_FILE+ write_dsh_patch(base, entry, patch)+ # A Windows dsh under WSL gets DSH_HOME translated through WSLENV, but not argv.+ command = _dsh_command(ctx.args, _agent_config_path(patch, ["dsh"]))env = {_DSH_ENV_KEY: key,"DSH_HOME": str(home),diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.pyindex e805687d854..bb8d0dc10b0 100644--- a/unsloth_cli/tests/test_start.py+++ b/unsloth_cli/tests/test_start.py@@ -6212,62 +6212,56 @@ def test_connect_pi_no_launch_windows_relocates_userprofile(fake_studio, tmp_pat@pytest.fixture()-def dsh_settings(tmp_path):- return tmp_path / "settings.yaml"+def dsh_patch(tmp_path):+ return tmp_path / "unsloth.patch.yml"-def test_write_dsh_config_fresh(dsh_settings):+def _dsh_entries(path):yaml = pytest.importorskip("yaml")- start.write_dsh_config(BASE, MODEL, dsh_settings)- config = yaml.safe_load(dsh_settings.read_text())- provider = config["llm-pi-ai"]["providers"]["unsloth"]+ entries = yaml.safe_load(path.read_text())+ # A loader patch is a top-level list of id-targeted entries, not a settings mapping.+ assert isinstance(entries, list), entries+ return {entry["id"]: entry for entry in entries}+++def test_write_dsh_patch_fresh(dsh_patch):+ start.write_dsh_patch(BASE, MODEL, dsh_patch)+ entries = _dsh_entries(dsh_patch)+ assert set(entries) == {"llm-pi-ai", "agent-default-model"}+ assert entries["llm-pi-ai"]["name"] == "@deepseek-ai/dsh-llm-pi-ai"+ assert entries["agent-default-model"]["name"] == "@deepseek-ai/dsh-agent-default-model"+ provider = entries["llm-pi-ai"]["config"]["providers"]["unsloth"]assert provider["api"] == "openai-completions"assert provider["baseURL"] == f"{BASE}/v1"assert provider["apiKeyEnv"] == "UNSLOTH_API_KEY"- assert "sk-unsloth" not in dsh_settings.read_text()+ assert "sk-unsloth" not in dsh_patch.read_text()assert provider["compat"] == {"supportsDeveloperRole": False, "maxTokensField": "max_tokens"}assert provider["models"] == [{"id": MODEL["id"], "contextWindow": MODEL["context_length"], "maxTokens": 8192}]- assert config["agent-default-model"] == {"provider": "unsloth", "model": MODEL["id"]}+ assert entries["agent-default-model"]["config"] == {"provider": "unsloth", "model": MODEL["id"]}-def test_write_dsh_config_without_window_omits_limits(dsh_settings):- yaml = pytest.importorskip("yaml")- start.write_dsh_config(BASE, {"id": "unsloth/unknown-window"}, dsh_settings)- config = yaml.safe_load(dsh_settings.read_text())- assert config["llm-pi-ai"]["providers"]["unsloth"]["models"] == [- {"id": "unsloth/unknown-window"}- ]+def test_write_dsh_patch_without_window_omits_limits(dsh_patch):+ start.write_dsh_patch(BASE, {"id": "unsloth/unknown-window"}, dsh_patch)+ provider = _dsh_entries(dsh_patch)["llm-pi-ai"]["config"]["providers"]["unsloth"]+ assert provider["models"] == [{"id": "unsloth/unknown-window"}]-def test_write_dsh_config_preserves_and_idempotent(dsh_settings):- yaml = pytest.importorskip("yaml")- dsh_settings.write_text(- yaml.safe_dump(- {- "ui-onboarding": {"welcomeNoticeVersion": "2026-08-13.1"},- "llm-pi-ai": {"providers": {"anthropic": {"apiKeyEnv": "ANTHROPIC_API_KEY"}}},- }- )- )- start.write_dsh_config(BASE, MODEL, dsh_settings)- config = yaml.safe_load(dsh_settings.read_text())- assert config["ui-onboarding"] == {"welcomeNoticeVersion": "2026-08-13.1"}- assert config["llm-pi-ai"]["providers"]["anthropic"] == {"apiKeyEnv": "ANTHROPIC_API_KEY"}- assert config["llm-pi-ai"]["providers"]["unsloth"]["baseURL"] == f"{BASE}/v1"- before = dsh_settings.read_text()- start.write_dsh_config(BASE, MODEL, dsh_settings)- assert dsh_settings.read_text() == before---def test_write_dsh_config_preserves_non_mapping_file(dsh_settings, capsys):- pytest.importorskip("yaml")- original = "- just\n- a\n- list\n" # valid YAML, but not a mapping- dsh_settings.write_text(original)- start.write_dsh_config(BASE, MODEL, dsh_settings)- assert dsh_settings.read_text() == original # user-managed file left untouched- assert "couldn't parse" in capsys.readouterr().err+def test_write_dsh_patch_is_idempotent_and_follows_the_server(dsh_patch, capsys):+ start.write_dsh_patch(BASE, MODEL, dsh_patch)+ before = dsh_patch.read_text()+ capsys.readouterr()+ start.write_dsh_patch(BASE, MODEL, dsh_patch)+ assert dsh_patch.read_text() == before+ assert "Updated" not in capsys.readouterr().out+ # Unsloth owns this file: a new server or model replaces the old one, it does not pile up.+ start.write_dsh_patch("http://127.0.0.1:9999", {"id": "other"}, dsh_patch)+ entries = _dsh_entries(dsh_patch)+ provider = entries["llm-pi-ai"]["config"]["providers"]["unsloth"]+ assert provider["baseURL"] == "http://127.0.0.1:9999/v1"+ assert provider["models"] == [{"id": "other"}]+ assert entries["agent-default-model"]["config"]["model"] == "other"@pytest.mark.parametrize(@@ -6289,6 +6283,39 @@ def test_dsh_command_selects_web_only_for_app_arguments(args, expected):assert start._dsh_command(args) == expected+ ("args", "expected"),+ [+ # A bare profile name must stay first so dsh expands it to --profile <name>.+ ([], ["dsh", "web", "--patch", "P"]),+ (["--no-open"], ["dsh", "web", "--patch", "P", "--no-open"]),+ (["web", "--no-open"], ["dsh", "web", "--patch", "P", "--no-open"]),+ (+ ["--profile", "headless", "fix the bug"],+ ["dsh", "--patch", "P", "--profile", "headless", "fix the bug"],+ ),+ (["--profile=headless", "fix"], ["dsh", "--patch", "P", "--profile=headless", "fix"]),+ (["--dump-config"], ["dsh", "--patch", "P", "--dump-config"]),+ # --patch repeats and composes in order, so a caller's own overlay lands after ours+ # and wins only on the keys it sets; the Unsloth provider stays defined.+ (+ ["--patch", "mine.yml", "--profile", "headless"],+ ["dsh", "--patch", "P", "--patch", "mine.yml", "--profile", "headless"],+ ),+ (["--patch=mine.yml", "web"], ["dsh", "--patch", "P", "--patch=mine.yml", "web"]),+ # Nothing boots a profile here, so there is nothing for an overlay to apply to.+ (+ ["plugin", "--profile", "web", "add", "x"],+ ["dsh", "plugin", "--profile", "web", "add", "x"],+ ),+ (["-V"], ["dsh", "-V"]),+ (["--version"], ["dsh", "--version"]),+ ],+)+def test_dsh_command_places_the_patch_where_dsh_parses_it(args, expected):+ assert start._dsh_command(args, "P") == expected++def test_connect_dsh_no_launch(fake_studio, tmp_path):yaml = pytest.importorskip("yaml")result = CliRunner().invoke(start.start_app, ["dsh", "--no-launch"])@@ -6297,10 +6324,28 @@ def test_connect_dsh_no_launch(fake_studio, tmp_path):home = tmp_path / "agents" / "dsh"_assert_env_set(result.output, "DSH_HOME", str(home))_assert_env_set(result.output, "DSH_TELEMETRY_DISABLED", "1")- assert _launch_command(result.output) == ["dsh", "web"]- config = yaml.safe_load((home / "settings.yaml").read_text())- assert config["agent-default-model"] == {"provider": "unsloth", "model": MODEL["id"]}- assert config["llm-pi-ai"]["providers"]["unsloth"]["baseURL"] == f"{BASE}/v1"+ patch = home / "unsloth.patch.yml"+ assert _launch_command(result.output) == ["dsh", "web", "--patch", str(patch)]+ entries = {entry["id"]: entry for entry in yaml.safe_load(patch.read_text())}+ assert entries["agent-default-model"]["config"] == {"provider": "unsloth", "model": MODEL["id"]}+ assert entries["llm-pi-ai"]["config"]["providers"]["unsloth"]["baseURL"] == f"{BASE}/v1"+ # dsh 0.1.7 imports a settings.yaml into the profile only after boot, so none is written.+ assert not (home / "settings.yaml").exists()++[email protected](os.name == "nt", reason = "WSL scenario")+def test_dsh_under_wsl_gets_the_windows_patch_path(fake_studio, monkeypatch):+ # WSLENV translates DSH_HOME for a Windows dsh, but a path on the command line reaches+ # the Windows Node process verbatim, where a Linux path does not open.+ windows_path = r"\\wsl.localhost\Ubuntu\tmp\unsloth.patch.yml"+ monkeypatch.setenv("WSL_DISTRO_NAME", "Ubuntu")+ shim = "/mnt/c/Users/x/AppData/Roaming/npm/dsh"+ monkeypatch.setattr(start.shutil, "which", lambda _: shim)+ monkeypatch.setattr(start, "is_deepseek_harness_executable", lambda _: True)+ monkeypatch.setattr(start.subprocess, "check_output", lambda *args, **kwargs: windows_path)+ captured = _capture_launch(monkeypatch, ["dsh", "--profile", "headless", "hi"])+ command = captured["command"]+ assert command[command.index("--patch") + 1] == windows_path, commanddef test_dsh_yolo_sets_permission_mode(fake_studio):