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
Let a decode failure degrade instead of escaping a fail-closed helper (#7487)
Daniel Han1daaa5cbb4fd
diff --git a/studio/backend/colab.py b/studio/backend/colab.pyindex df1285b7494..bf4a6a44b5e 100644--- a/studio/backend/colab.py+++ b/studio/backend/colab.py@@ -109,7 +109,7 @@ def _load_colab_login_credentials() -> "tuple[str, str] | None":lines = path.read_text(encoding = "utf-8").splitlines()if len(lines) >= 2 and lines[0] and lines[1]:return lines[0], lines[1]- except OSError as e:+ except (OSError, UnicodeDecodeError) as e:logger.info(f"Could not load Colab login credentials ({e}).")return Nonediff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex f286a2e4c59..0621a7f9c8a 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -246,7 +246,7 @@ def _wsl_system_rocm_lib_dirs() -> "list[str]":with open("/proc/version", encoding = "utf-8", errors = "replace") as fh:if "microsoft" not in fh.read().lower():return []- except OSError:+ except (OSError, UnicodeDecodeError):return []out: "list[str]" = []for d in ("/opt/rocm/lib", "/opt/rocm/lib64"):@@ -573,7 +573,7 @@ def _load_swa_cache() -> dict:_SWA_CACHE = json.load(f)if not isinstance(_SWA_CACHE, dict):_SWA_CACHE = {}- except (FileNotFoundError, json.JSONDecodeError, OSError):+ except (FileNotFoundError, json.JSONDecodeError, OSError, UnicodeDecodeError):_SWA_CACHE = {}return _SWA_CACHE@@ -586,7 +586,7 @@ def _save_swa_cache(cache: dict) -> None:with open(tmp, "w", encoding = "utf-8") as f:json.dump(cache, f, indent = 2, sort_keys = True)tmp.replace(path)- except OSError:+ except (OSError, UnicodeDecodeError):pass@@ -5138,7 +5138,7 @@ class LlamaCppBackend:self._llama_log_path = log_dir / f"diffusion-{int(time.time())}-port-{self._port}.log"self._llama_log_fh = open(self._llama_log_path, "w", encoding = "utf-8", buffering = 1)logger.info(f"diffusion runner stdout/stderr -> {self._llama_log_path}")- except OSError as e:+ except (OSError, UnicodeDecodeError) as e:logger.debug(f"Could not open diffusion runner log file: {e}")# The shim (and its visual server) die with this backend process, so a@@ -6355,7 +6355,7 @@ class LlamaCppBackend:buffering = 1,)logger.info(f"llama-server stdout/stderr -> {self._llama_log_path}")- except OSError as e:+ except (OSError, UnicodeDecodeError) as e:# Best-effort; never block the load on logging.logger.debug(f"Could not open llama-server log file: {e}")self._llama_log_path = None@@ -8302,7 +8302,7 @@ class LlamaCppBackend:buffering = 1,)logger.info(f"llama-server stdout/stderr -> {self._llama_log_path}")- except OSError as e:+ except (OSError, UnicodeDecodeError) as e:# Best-effort; never block the load on logging.logger.debug(f"Could not open llama-server log file: {e}")self._llama_log_path = Nonediff --git a/studio/backend/hub/services/models/ollama.py b/studio/backend/hub/services/models/ollama.pyindex 190aef0c71d..56275c22a9d 100644--- a/studio/backend/hub/services/models/ollama.py+++ b/studio/backend/hub/services/models/ollama.py@@ -216,7 +216,7 @@ def _ollama_model_info_from_manifest(try:manifest = json.loads(tag_file.read_text(encoding = "utf-8"))- except (json.JSONDecodeError, OSError) as e:+ except (json.JSONDecodeError, OSError, UnicodeDecodeError) as e:logger.debug("Skipping unreadable/invalid Ollama manifest %s: %s", tag_file, e)return None@@ -231,7 +231,7 @@ def _ollama_model_info_from_manifest(cfg = json.loads(config_blob.read_text(encoding = "utf-8"))model_type = cfg.get("model_type", "")file_type = cfg.get("file_type", "")- except (json.JSONDecodeError, OSError) as e:+ except (json.JSONDecodeError, OSError, UnicodeDecodeError) as e:logger.debug("Could not parse Ollama config blob %s: %s", config_blob, e)layers = manifest.get("layers") or []diff --git a/studio/backend/hub/utils/download_registry.py b/studio/backend/hub/utils/download_registry.pyindex 243caab8f72..39c27208b1d 100644--- a/studio/backend/hub/utils/download_registry.py+++ b/studio/backend/hub/utils/download_registry.py@@ -463,7 +463,7 @@ def _read_marker_value(marker: Path) -> Optional[str]:if not marker.exists():return Nonevalue = marker.read_text(encoding = "utf-8").strip()- except OSError:+ except (OSError, UnicodeDecodeError):return Nonereturn value if value in VALID_TRANSPORTS else Nonediff --git a/studio/backend/main.py b/studio/backend/main.pyindex bcf5c281df6..e632c9525bb 100644--- a/studio/backend/main.py+++ b/studio/backend/main.py@@ -362,7 +362,7 @@ def get_unsloth_version() -> str:for line in version_file.read_text(encoding = "utf-8").splitlines():if line.startswith("__version__ = "):return line.split("=", 1)[1].strip().strip('"').strip("'")- except OSError:+ except (OSError, UnicodeDecodeError):passreturn "dev"diff --git a/studio/backend/plugins/data-designer-unstructured-seed/src/data_designer_unstructured_seed/impl.py b/studio/backend/plugins/data-designer-unstructured-seed/src/data_designer_unstructured_seed/impl.pyindex 6016f5611fd..ce0c88e5bfe 100644--- a/studio/backend/plugins/data-designer-unstructured-seed/src/data_designer_unstructured_seed/impl.py+++ b/studio/backend/plugins/data-designer-unstructured-seed/src/data_designer_unstructured_seed/impl.py@@ -29,7 +29,7 @@ class UnstructuredSeedReader(SeedReader[UnstructuredSeedSource]):try:meta = json_mod.loads(meta_path.read_text(encoding = "utf-8"))orig_name = meta.get("original_filename", path_obj.name)- except (json_mod.JSONDecodeError, OSError):+ except (json_mod.JSONDecodeError, OSError, UnicodeDecodeError):passfile_entries.append((path_obj, orig_name))diff --git a/studio/backend/routes/models.py b/studio/backend/routes/models.pyindex dc850becf0e..96c5b96d739 100644--- a/studio/backend/routes/models.py+++ b/studio/backend/routes/models.py@@ -723,7 +723,7 @@ def _scan_ollama_dir(ollama_dir: Path, limit: Optional[int] = None) -> List[Locatry:manifest = json.loads(tag_file.read_text(encoding = "utf-8"))- except (json.JSONDecodeError, OSError) as e:+ except (json.JSONDecodeError, OSError, UnicodeDecodeError) as e:logger.debug("Skipping unreadable/invalid Ollama manifest %s: %s",tag_file,@@ -741,7 +741,7 @@ def _scan_ollama_dir(ollama_dir: Path, limit: Optional[int] = None) -> List[Locacfg = json.loads(config_blob.read_text(encoding = "utf-8"))model_type = cfg.get("model_type", "")file_type = cfg.get("file_type", "")- except (json.JSONDecodeError, OSError) as e:+ except (json.JSONDecodeError, OSError, UnicodeDecodeError) as e:logger.debug("Could not parse Ollama config blob %s: %s",config_blob,diff --git a/studio/backend/run.py b/studio/backend/run.pyindex 2189388cf96..5dfab9346a8 100644--- a/studio/backend/run.py+++ b/studio/backend/run.py@@ -786,7 +786,7 @@ def _remove_pid_file():stored = _PID_FILE.read_text(encoding = "utf-8").strip()if stored == str(os.getpid()):_PID_FILE.unlink(missing_ok = True)- except OSError:+ except (OSError, UnicodeDecodeError):pass@@ -934,7 +934,7 @@ def _iter_frontend_fallback_candidates() -> "list[Path]":for finder in sp.glob("__editable___*_finder.py"):try:src = finder.read_text(encoding = "utf-8")- except OSError:+ except (OSError, UnicodeDecodeError):continue# Tolerate single/multi-line dict literals; [^}]* rejects nested# dicts, which the setuptools editable template never emits.diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.pyindex f3b968c8df8..b270a8e6714 100644--- a/studio/backend/utils/hardware/hardware.py+++ b/studio/backend/utils/hardware/hardware.py@@ -903,7 +903,7 @@ def _rocm_kfd_gpu_pci_ids() -> list[str]:props[parts[0]] = int(parts[1])except ValueError:continue- except OSError:+ except (OSError, UnicodeDecodeError):return [] # unreadable node could be a GPU: fail closed, don't shiftif props.get("simd_count", 0) <= 0:continue # CPU node, not a GPUdiff --git a/studio/backend/utils/paths/storage_roots.py b/studio/backend/utils/paths/storage_roots.pyindex ab888ec49ee..ae1319d296c 100644--- a/studio/backend/utils/paths/storage_roots.py+++ b/studio/backend/utils/paths/storage_roots.py@@ -126,7 +126,7 @@ def _xdg_user_dir(key: str) -> Path | None:config = Path.home() / ".config" / "user-dirs.dirs"try:lines = config.read_text(encoding = "utf-8").splitlines()- except OSError:+ except (OSError, UnicodeDecodeError):return Noneprefix = f"{key}="for line in lines:diff --git a/studio/backend/utils/utils.py b/studio/backend/utils/utils.pyindex 2d9306f6eda..e4964b8d04b 100644--- a/studio/backend/utils/utils.py+++ b/studio/backend/utils/utils.py@@ -114,7 +114,7 @@ def hf_cache_snapshot_dir(model_name: str) -> Optional[Path]:snapshot = repo_dir / "snapshots" / commitif snapshot.is_dir():return snapshot- except OSError:+ except (OSError, UnicodeDecodeError):continuereturn Nonediff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex 47ad4bfc66c..9b787dbb158 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -2508,7 +2508,7 @@ def detect_host() -> HostInfo:if _vf.read().strip().lower() == "0x8086":has_intel_gpu = Truebreak- except OSError:+ except (OSError, UnicodeDecodeError):continueelif is_windows:# Registry first (in-process; see windows_intel_gpu_in_registry).@@ -4264,7 +4264,7 @@ def free_local_port() -> int:def read_log_excerpt(log_path: Path, *, max_lines: int = 60) -> str:try:content = log_path.read_text(encoding = "utf-8", errors = "replace")- except FileNotFoundError:+ except (FileNotFoundError, UnicodeDecodeError):return ""return "\n".join(content.splitlines()[-max_lines:])@@ -4680,7 +4680,7 @@ def _wsl_system_rocm_lib_dirs() -> list[str]:with open("/proc/version", encoding = "utf-8", errors = "replace") as fh:if "microsoft" not in fh.read().lower():return []- except OSError:+ except (OSError, UnicodeDecodeError):return []out: list[str] = []for d in ("/opt/rocm/lib", "/opt/rocm/lib64"):diff --git a/studio/install_node_prebuilt.py b/studio/install_node_prebuilt.pyindex 948743c63ca..82ca1d2c68b 100644--- a/studio/install_node_prebuilt.py+++ b/studio/install_node_prebuilt.py@@ -535,7 +535,9 @@ def install_lock(lock_path: Path) -> Iterator[None]:breakexcept FileExistsError:try:- raw = lock_path.read_text(encoding = "utf-8").strip()+ # errors="replace" so an undecodable lock reaches the int()+ # below and is treated as a stale PID, not retried forever.+ raw = lock_path.read_text(encoding = "utf-8", errors = "replace").strip()except FileNotFoundError:continuestale = False@@ -669,7 +671,7 @@ def load_metadata(install_dir: Path) -> dict | None:return Nonetry:data = json.loads(path.read_text(encoding = "utf-8"))- except (json.JSONDecodeError, OSError):+ except (json.JSONDecodeError, OSError, UnicodeDecodeError):return Nonereturn data if isinstance(data, dict) else Nonediff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex 5e9adb79d11..a91f26910ff 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -776,7 +776,7 @@ def _linux_amd_gfx_from_cpuinfo() -> "str | None":"""Infer gfx arch from /proc/cpuinfo on integrated AMD APUs (Strix Halo/Point)."""try:text = Path("/proc/cpuinfo").read_text(encoding = "utf-8", errors = "replace")- except OSError:+ except (OSError, UnicodeDecodeError):return Noneif re.search(r"Ryzen AI Max|Radeon 80[0-9][05]S|Strix Halo", text, re.IGNORECASE):return "gfx1151"@@ -828,7 +828,7 @@ def _is_wsl() -> bool:try:with open("/proc/version", encoding = "utf-8", errors = "replace") as fh:return "microsoft" in fh.read().lower()- except OSError:+ except (OSError, UnicodeDecodeError):return False@@ -856,7 +856,7 @@ def _linux_amd_display_device_present() -> bool:continueif (dev / "class").read_text(encoding = "utf-8").strip().startswith("0x03"):return True- except OSError:+ except (OSError, UnicodeDecodeError):continueexcept OSError:pass@@ -1069,7 +1069,7 @@ def _has_rocm_gpu() -> bool:try:with open(gpu_id_path, encoding = "utf-8") as fh:gpu_id = fh.read().strip()- except OSError:+ except (OSError, UnicodeDecodeError):continueif not gpu_id or gpu_id == "0": # gpu_id 0 = CPU nodecontinue@@ -1081,7 +1081,7 @@ def _has_rocm_gpu() -> bool:try:with open(props_path, encoding = "utf-8") as fh:props = fh.read()- except OSError:+ except (OSError, UnicodeDecodeError):continue # can't confirm vendor -- skipif not re.search(r"\bvendor_id\s+4098\b", props):continuediff --git a/studio/prebuilt_core.py b/studio/prebuilt_core.pyindex 1f711d14f02..d7075815d3f 100644--- a/studio/prebuilt_core.py+++ b/studio/prebuilt_core.py@@ -1078,7 +1078,9 @@ def install_lock(lock_path: Path) -> Iterator[None]:except FileExistsError:stale = Falsetry:- raw = lock_path.read_text(encoding = "utf-8").strip()+ # errors="replace" so an undecodable lock reaches the int()+ # below and is treated as a corrupt PID, not retried forever.+ raw = lock_path.read_text(encoding = "utf-8", errors = "replace").strip()except FileNotFoundError:# Lock vanished between our open and read -- retrycontinue@@ -2070,7 +2072,7 @@ def load_prebuilt_metadata(ops: ModuleOps, install_dir: Path) -> dict[str, Any]return Nonetry:payload = json.loads(path.read_text(encoding = "utf-8"))- except (json.JSONDecodeError, OSError):+ except (json.JSONDecodeError, OSError, UnicodeDecodeError):return Nonereturn payload if isinstance(payload, dict) else Nonediff --git a/unsloth_cli/_inference.py b/unsloth_cli/_inference.pyindex 32b16941296..3ad901542c9 100644--- a/unsloth_cli/_inference.py+++ b/unsloth_cli/_inference.py@@ -100,7 +100,7 @@ def _json_rank_count_from_env(name: str) -> Optional[int]:else:with open(value, "r", encoding = "utf-8") as f:data = json.load(f)- except (OSError, json.JSONDecodeError):+ except (json.JSONDecodeError, OSError, UnicodeDecodeError):return Noneif isinstance(data, list):return len(data)diff --git a/unsloth_cli/commands/studio.py b/unsloth_cli/commands/studio.pyindex 323e7130786..d66dfd7e07a 100644--- a/unsloth_cli/commands/studio.py+++ b/unsloth_cli/commands/studio.py@@ -335,7 +335,7 @@ def _iter_editable_studio_source_roots(venv_dir: Path):for finder in sp.glob("__editable___*_finder.py"):try:src = finder.read_text(encoding = "utf-8")- except OSError:+ except (OSError, UnicodeDecodeError):continue# Tolerate single- or multi-line dict literals; [^}]* still# rejects nested dicts, which the setuptools template never