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
Remove unreferenced private helpers, constants and an if False block (#16569)
Daniel Hanc093e0278996
diff --git a/studio/backend/core/inference/diffusion_engine_router.py b/studio/backend/core/inference/diffusion_engine_router.pyindex ea302d77b0c..d0ca6530f88 100644--- a/studio/backend/core/inference/diffusion_engine_router.py+++ b/studio/backend/core/inference/diffusion_engine_router.py@@ -420,10 +420,6 @@ def mlx_mode() -> str:return MLX_OFF-def _mlx_requested() -> bool:- return mlx_mode() != MLX_OFF--def _mlx_host_refusal() -> Optional[str]:if sys.platform != "darwin":return "the MLX engine runs on macOS only"diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 99c19386711..a178dddda5b 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -1422,17 +1422,6 @@ def _has_unclosed_code_fence(text: str) -> bool:return active_char is not None-def _has_unclosed_markup_block(text: str) -> bool:- """Counted rather than matched, so a closed block followed by an open one still counts as unclosed."""- opens_html = len(re.findall(r"<html\b", text, re.IGNORECASE))- closes_html = len(re.findall(r"</html\s*>", text, re.IGNORECASE))- if opens_html > closes_html:- return True- opens_svg = len(re.findall(r"<svg\b", text, re.IGNORECASE))- closes_svg = len(re.findall(r"</svg\s*>", text, re.IGNORECASE))- return opens_svg > closes_svg--# "First, I'll create an <html></html> skeleton" is a plan, not a page._EMPTY_MARKUP_SKELETON = re.compile(r"<(html|svg)\b[^>]*>\s*</\1\s*>",diff --git a/studio/backend/core/inference/mlx_diffusion_convert.py b/studio/backend/core/inference/mlx_diffusion_convert.pyindex 317938671b7..8188e8a1d15 100644--- a/studio/backend/core/inference/mlx_diffusion_convert.py+++ b/studio/backend/core/inference/mlx_diffusion_convert.py@@ -67,7 +67,6 @@ _BLOCK_BITS = {"Q6_K": 8,}_QK_K = 256-_DENSE_TYPES = frozenset({"BF16", "F16", "F32"})_PAD_TOKENS = ("cap_pad_token", "x_pad_token")_QKV_PARTS = ("to_q", "to_k", "to_v")diff --git a/studio/backend/core/inference/sd_cpp_backend.py b/studio/backend/core/inference/sd_cpp_backend.pyindex 838a9755e5e..a8c7f3240ec 100644--- a/studio/backend/core/inference/sd_cpp_backend.py+++ b/studio/backend/core/inference/sd_cpp_backend.py@@ -1635,12 +1635,6 @@ _RUNTIME_FINGERPRINT_MEMO: Optional[dict] = None_HOST_FINGERPRINT_MEMO: Optional[dict] = None-def _reset_host_fingerprint() -> None:- global _HOST_FINGERPRINT_MEMO, _RUNTIME_FINGERPRINT_MEMO- _HOST_FINGERPRINT_MEMO = None- _RUNTIME_FINGERPRINT_MEMO = None--def _runtime_fingerprint() -> dict:global _RUNTIME_FINGERPRINT_MEMOif _RUNTIME_FINGERPRINT_MEMO is not None:diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.pyindex fa8be61e064..330a1c42a13 100644--- a/studio/backend/core/inference/tools.py+++ b/studio/backend/core/inference/tools.py@@ -2131,11 +2131,6 @@ _AUTO_EXEC_MCP_VERB_ONLY_RE = re.compile(r"powershell|pwsh|terminal|subprocess|interpreter)(?:[_\-]|$)",re.IGNORECASE,)-_AUTO_EXEC_MCP_RUNTIME_NOUN_RE = re.compile(- r"(?:^|[_\-])(?:python[0-9.]*|node|nodejs|deno|bun|ruby|perl|php|code|"- r"script|repl|sandbox|notebook)(?:[_\-]|$)",- re.IGNORECASE,-)# Code/command runners run on the MCP server outside the sandbox; whole segments only._AUTO_EXEC_MCP_TOOL_RE = re.compile(r"(?:^|[_\-])(?:"@@ -3302,20 +3297,6 @@ def _references_studio_credential(text: str) -> bool:# Any run of text that could be a path argument, used to read one token at a time._PATH_TOKEN_RE = re.compile(r"[^\s'\"()\[\]{},;|&<>]+")-# Only traversal is worth resolving: a relative path without `..` stays inside the sandbox.-_TRAVERSAL_TOKEN_RE = re.compile(r"[^\s'\"()\[\]{},;|&<>]*\.\.[^\s'\"()\[\]{},;|&<>]*")-# Used only after a `cd`, where `auth/auth.db` stops meaning "inside the sandbox".-_RELATIVE_PATH_TOKEN_RE = re.compile(r"[^\s'\"()\[\]{},;|&<>]*[/\\][^\s'\"()\[\]{},;|&<>]*")-# Case-insensitive: the shell is `cmd /c` on Windows without a trusted bash.-_CD_TARGET_RE = re.compile(- # `builtin cd`, `command cd`, `! cd` and `time cd` move like a bare `cd`.- r"(?:^\s*|[;&|({\n]\s*|\b(?:then|do|else|if|elif|while|until)\s+)"- # Bash allows assignment words before a special builtin, so `X=1 cd ../..` moves like a bare `cd`.- r"(?:(?:builtin|command|exec|nohup)\s+|time\s+(?:-p\s+)?|!\s*|[A-Za-z_]\w*=[^\s;&|()]*\s+)*"- r"(?:cd|pushd)\s+"- r"(?:(?:-[LPe@]+|--|/d)\s+)*([^\s;&|)]+)",- re.IGNORECASE,-)# `cd -` and `popd` return; matched in one pass so order is kept._DIRECTORY_MOVE_RE = re.compile(r"(?:^\s*|[;&|({\n]\s*|\b(?:then|do|else|if|elif|while|until)\s+)"@@ -6609,8 +6590,6 @@ _HIGH_RISK_FORWARDING_COMMANDS = frozenset("valgrind",})-# Tracers and profilers run the rest of the line as a child.-_TRACER_LAUNCHERS = frozenset({"strace", "ltrace", "ktrace", "dtruss", "perf", "valgrind"})_EXEC_FLAG_FORWARDING_COMMANDS = frozenset({"find", "fd"})_EXEC_FORWARD_FLAGS = frozenset({"-exec", "-execdir", "-ok", "-okdir", "--exec", "--exec-batch", "-x", "-X"}@@ -6718,7 +6697,6 @@ _INLINE_CODE_INTERPRETERS = frozenset("php",})-_INLINE_CODE_FLAGS = frozenset({"-c", "-e", "-E", "-r", "--eval", "--exec"})# Flags are per interpreter (`python -E` is not eval). Value: (exact flags, cluster letters)._INLINE_CODE_FLAG_SPEC = {"python": (frozenset({"-c"}), "c"),@@ -10067,15 +10045,6 @@ def live_project_owns(return False-def _project_exists(project_id: str) -> bool:- """Whether a project of the user's is stored under this exact id."""- try:- from storage.studio_db import get_chat_project- return get_chat_project(project_id) is not None- except Exception: # noqa: BLE001 - a storage hiccup must not delete files- return True--def _is_managed_project_workdir(session_id: "str | None", workdir: str) -> bool:"""Compares with the sandbox path, not the working-folder setting, which can change before the chmod."""if not session_id or not session_id.startswith(_PROJECT_SESSION_PREFIX):diff --git a/studio/backend/core/inference/video_minimax_h3_ref_encode.py b/studio/backend/core/inference/video_minimax_h3_ref_encode.pyindex 8099b2f555c..393ba91233b 100644--- a/studio/backend/core/inference/video_minimax_h3_ref_encode.py+++ b/studio/backend/core/inference/video_minimax_h3_ref_encode.py@@ -13,7 +13,6 @@ import threadingfrom typing import Any, OptionalH3_CHUNKED_REF_ENCODE_ENV = "UNSLOTH_H3_CHUNKED_REF_ENCODE"-_ENCODERS_MODULE = "diffusers.modular_pipelines.minimax_h3.encoders"_FUNC = "encode_vae_condition"# sha256[:16] of inspect.getsource of the mirrored functions (diffusers 0.42.1).diff --git a/studio/backend/core/rag/office_formats.py b/studio/backend/core/rag/office_formats.pyindex 79810f164d7..f866fa4933c 100644--- a/studio/backend/core/rag/office_formats.py+++ b/studio/backend/core/rag/office_formats.py@@ -406,10 +406,6 @@ def _apply_section(value: float, plan) -> str | None:return prefix + text + percent + suffix-def _format_section(value: float, tokens: list[tuple[str, str]]) -> str | None:- return _apply_section(value, _section_plan(tokens))--def _number_plan(code: str):"""Each section of a numeric format read once (with whether it has tokens), or None if unsupported."""tokens = _format_tokens(code) if code else None@@ -435,11 +431,6 @@ def _apply_number(value: float, plan) -> str | None:return None if text is None else ("-" + text if value < 0 else text)-def _format_number(value: float, code: str) -> str | None:- """``value`` as a numeric format displays it, or None for formats left as stored."""- return _apply_number(value, _number_plan(code))--_NUMBER_ERRORS = (ArithmeticError, ValueError, decimal.InvalidOperation)diff --git a/studio/backend/core/training/multi_lora_trainer.py b/studio/backend/core/training/multi_lora_trainer.pyindex 1f66b3ca171..2022a9a2bad 100644--- a/studio/backend/core/training/multi_lora_trainer.py+++ b/studio/backend/core/training/multi_lora_trainer.py@@ -23,7 +23,6 @@ from loggers import get_loggerlogger = get_logger(__name__)_DEFAULT_TARGETS = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]-_OPTIMIZERS = ("adamw_8bit", "adamw_torch", "adamw_torch_fused")@dataclassdiff --git a/studio/backend/routes/auth.py b/studio/backend/routes/auth.pyindex dc27ba2e40c..035c91e60a3 100644--- a/studio/backend/routes/auth.py+++ b/studio/backend/routes/auth.py@@ -135,7 +135,6 @@ _LOGIN_BUCKETS_LOCK = threading.Lock()_LOGIN_WINDOW_SECONDS = 60.0_LOGIN_MAX_FAILS = 5_LOGIN_IP_MAX_FAILS = 30-_LOGIN_LOCKOUT_SECONDS = 60# On overflow, reclaim expired buckets, then use sharded overflow rather than evict a hot bucket._LOGIN_MAX_BUCKETS = 4096# Last full stale-sweep time; rate-limits the O(n) sweep under a burst of new IPs.diff --git a/studio/backend/routes/data_recipe/jobs.py b/studio/backend/routes/data_recipe/jobs.pyindex f8aa5f521e3..41e8ec35ce2 100644--- a/studio/backend/routes/data_recipe/jobs.py+++ b/studio/backend/routes/data_recipe/jobs.py@@ -199,20 +199,6 @@ def _resolve_local_v1_endpoint(request: Request) -> str:return f"http://{host}:{int(port)}/v1"-def _request_has_desktop_access_token(request: Request) -> bool:- auth_header = request.headers.get("authorization")- if not auth_header:- return False-- parts = auth_header.split(None, 1)- if len(parts) != 2 or parts[0].lower() != "bearer":- return False-- from auth.authentication import is_desktop_access_token-- return is_desktop_access_token(parts[1])--def _used_llm_model_aliases(recipe: dict[str, Any]) -> set[str]:"""Return model_aliases actually referenced by an LLM column. Narrows the "Chat model loaded" gateso orphan model_config nodes don't block unrelated runs. The ``llm-`` prefix matchesdiff --git a/studio/backend/utils/hardware/gpu_query.py b/studio/backend/utils/hardware/gpu_query.pyindex 1fa54e66c30..b18cb6167f5 100644--- a/studio/backend/utils/hardware/gpu_query.py+++ b/studio/backend/utils/hardware/gpu_query.py@@ -134,10 +134,6 @@ def _query_fields(argv: Sequence[str]) -> list[str]:return []-def _nounits(argv: Sequence[str]) -> bool:- return any(arg.startswith("--format=") and "nounits" in arg for arg in argv[1:])--@dataclassclass _Entry:# None = the CLI's latest answer had no rows (failed or empty): never served, only orders writers.diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.pyindex a4be489cd7d..91743de6851 100644--- a/studio/backend/utils/hardware/hardware.py+++ b/studio/backend/utils/hardware/hardware.py@@ -5168,25 +5168,6 @@ def _reconcile_cuda_integrated_memory()-def _reconcile_primary_rocm_unified_memory(- utilization: Dict[str, Any], parent_visible_spec: Dict[str, Any]-) -> None:- """Same fix as _reconcile_rocm_unified_memory for the flat primary-GPU dict."""- numeric_ids = parent_visible_spec.get("numeric_ids")- if numeric_ids is None:- # No visibility env var set: torch ordinal 0 is the primary device.- primary_idx = [0]- elif len(numeric_ids) == 0:- # Empty mask: no GPU visible. Querying torch device 0 would raise or return stale data, so bail rather than write bad values.- return- else:- primary_idx = [int(numeric_ids[0])]- torch_devices = _torch_get_per_device_info(primary_idx)- if not torch_devices:- return- _apply_unified_memory_correction(utilization, torch_devices[0])--def _rocm_visibility_mask_active() -> bool:"""True when any ROCm/CUDA visibility variable filters the device set."""for var in (diff --git a/studio/backend/utils/llama_cpp_freshness.py b/studio/backend/utils/llama_cpp_freshness.pyindex 5f3133f1577..fd037d4478c 100644--- a/studio/backend/utils/llama_cpp_freshness.py+++ b/studio/backend/utils/llama_cpp_freshness.py@@ -47,10 +47,6 @@ def read_install_marker(binary_path: Optional[str]) -> Optional[dict]:)-def _load_disk_cache(repo: str) -> Optional[tuple[float, Optional[str]]]:- return _flow.load_disk_cache(repo, _cache_dir())--def _save_disk_cache(repo: str, latest_tag: Optional[str]) -> None:_flow.save_disk_cache(repo, latest_tag, _cache_dir(), log_message = "freshness cache write failed"@@ -129,10 +125,6 @@ def update_download_size_bytes(return None-def _parse_installed_at(value: object) -> Optional[datetime]:- return _flow.parse_installed_at(value)--def parse_base_build(tag: object) -> Optional[int]:"""Numeric base build from a release tag. Handles both a plain ``bNNNN`` and a mix-build tag like ``b9596-mix-<sha>`` (anchored at the start, so the mix suffix does not defeat it). None for anything not starting with ``bNNNN``."""if not isinstance(tag, str):diff --git a/studio/backend/utils/llama_cpp_update.py b/studio/backend/utils/llama_cpp_update.pyindex d043bb11c8b..cc8e35f0dc8 100644--- a/studio/backend/utils/llama_cpp_update.py+++ b/studio/backend/utils/llama_cpp_update.py@@ -61,7 +61,6 @@ class _LlamaPhaseError(RuntimeError):self.reload_required = reload_required-_JOB_IDLE = _flow.JOB_IDLE_JOB_RUNNING = _flow.JOB_RUNNING_JOB_SUCCESS = _flow.JOB_SUCCESS_JOB_ERROR = _flow.JOB_ERROR@@ -73,7 +72,6 @@ _job: dict = _flow.new_job()_ALREADY_RUNNING_MESSAGE = "Another llama.cpp install is already running."_utcnow = _flow.utcnow-_is_under = _flow.is_under_is_external_link = _flow.is_external_link_rocm_install_args = _flow.rocm_install_argsdiff --git a/studio/backend/utils/security/remote_code_scan.py b/studio/backend/utils/security/remote_code_scan.pyindex 02991f53b95..e9b586e748e 100644--- a/studio/backend/utils/security/remote_code_scan.py+++ b/studio/backend/utils/security/remote_code_scan.py@@ -673,11 +673,6 @@ def _auto_map_refs(cfg: dict) -> set:return out-def _auto_map_py(cfg: dict) -> set[str]:- """Own-repo ``.py`` filenames referenced by auto_map (external refs excluded)."""- return {fn for repo, fn in _auto_map_refs(cfg) if repo is None}--def external_auto_map_repos(model_name: str,hf_token: Optional[str] = None,diff --git a/studio/backend/utils/whisper_cpp_freshness.py b/studio/backend/utils/whisper_cpp_freshness.pyindex 6f417d4f9d3..124e633d05b 100644--- a/studio/backend/utils/whisper_cpp_freshness.py+++ b/studio/backend/utils/whisper_cpp_freshness.py@@ -49,10 +49,6 @@ def read_install_marker(binary_path: Optional[str]) -> Optional[dict]:return marker-def _load_disk_cache(repo: str) -> Optional[tuple[float, Optional[str]]]:- return _flow.load_disk_cache(repo, _cache_dir())--def _save_disk_cache(repo: str, latest_tag: Optional[str]) -> None:_flow.save_disk_cache(repo, latest_tag, _cache_dir(), log_message = "whisper freshness cache write failed"diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.pyindex 723ab0515ec..b3c12421e4a 100644--- a/unsloth/import_fixes.py+++ b/unsloth/import_fixes.py@@ -420,7 +420,6 @@ def fix_xformers_performance_issue():# flash-attn 4 makes flash_attn a namespace package without flash_attn_interface, which breaks# `import xformers.ops`; import xformers once with flash_attn hidden from find_spec._FLASH_ATTN_INTERFACE_NAME = "flash_attn_interface"-_FLASH_ATTN_INTERFACE_MODULE = "flash_attn." + _FLASH_ATTN_INTERFACE_NAME_FA4_NAMESPACE_WARNED = [False]diff --git a/unsloth/kernels/fast_lora.py b/unsloth/kernels/fast_lora.pyindex 4e66f235541..e15f5f7c4bd 100644--- a/unsloth/kernels/fast_lora.py+++ b/unsloth/kernels/fast_lora.py@@ -128,13 +128,6 @@ def _lora_dropout_p(return p if p < 1 else None-def _lora_B_bias(proj):- adapter = _active_lora_adapter(proj)- if adapter is None:- return None- return proj.lora_B[adapter].bias--def lora_bias_blocks_fused(proj):return not FUSED_LORA_BIAS and _has_active_lora_bias(proj)diff --git a/unsloth/kernels/moe/grouped_gemm/kernels/autotuning.py b/unsloth/kernels/moe/grouped_gemm/kernels/autotuning.pyindex cb05f502ad9..3ff335338d5 100644--- a/unsloth/kernels/moe/grouped_gemm/kernels/autotuning.py+++ b/unsloth/kernels/moe/grouped_gemm/kernels/autotuning.py@@ -46,16 +46,6 @@ def convert_args_to_list(args):return [val_to_list(arg) for arg in args]-def _triton_supports_tma():- """Check if current Triton version supports TMA API."""- import triton.language as tl-- # Both the old experimental and the new stable API names.- return hasattr(tl, "make_tensor_descriptor") or hasattr(- tl, "_experimental_make_tensor_descriptor"- )--# TMA disabled for now: incompatible with permute_x/permute_y in the MoE grouped GEMM passes._TRITON_HAS_TMA = Falsediff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 0de8d497a03..ff0ecc46928 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -2018,10 +2018,6 @@ def _get_flash_attention_disable_reason(config):return None-def _is_flash_attention_disabled(config):- return _get_flash_attention_disable_reason(config) is not None--def _is_flash_attention_requested(attn_implementation):return isinstance(attn_implementation, str) and attn_implementation.startswith("flash_attention"@@ -4908,20 +4904,6 @@ try:"```\n")- if False:- raise ImportError(- "Unsloth: If you are in Colab, we updated the top cell install instructions - please change it to below "- "then press Disconnect Runtime and then Restart it.\n"- "\n"- "%%capture\n"- "# Installs Unsloth, Xformers (Flash Attention) and all other packages!\n"- '!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"\n'- '!pip install --no-deps "xformers<=0.0.27" trl peft accelerate bitsandbytes\n'- "\n"- f"Otherwise in local machines, your xformers version of {xformers_version} is too new.\n"- 'Please downgrade xformers via `pip install --force-reinstall "xformers<=0.0.27"'- )-if Version(torch_version) < Version("2.2.0") and Version(xformers_version) >= Version("0.0.24"):raise ImportError(f"Unsloth: You have torch = {torch_version} but xformers = {xformers_version}.\n"@@ -5308,10 +5290,6 @@ def _download_statistics(names):# Do not retry without a time limit: it would freeze offline.-def _get_statistics(statistics = None, force_download = True):- _download_statistics([_statistics_environment(statistics)])--def get_statistics(local_files_only = False):# Basic stats on which environment is in use, and whether HuggingFace is down: a README.md is downloaded from HF, all data public. Disable with UNSLOTH_DISABLE_STATISTICS.import osdiff --git a/unsloth/parallel_capabilities.py b/unsloth/parallel_capabilities.pyindex 51caafc48cd..0fdeef28cfa 100644--- a/unsloth/parallel_capabilities.py+++ b/unsloth/parallel_capabilities.py@@ -656,7 +656,6 @@ _CP_DP = {k: v for k, v in _CP_TP.items() if k != "block_swap"}_CP_DP.update(tp = (1,), moe = (False,))_FSDP2_CP = _GLOO + "test_cp_with_native_fsdp2_matches_one_process"_HYBRID_FSDP2_CP = _GLOO + "test_hybrid_qwen3_5_cp_with_native_fsdp2_matches_one_process"-_MOE_CP = _GLOO + "test_moe_without_aux_loss_under_cp_matches_one_process"# Packed rows under generic Ulysses (HF attention, DDP over cp)._PACKED_CP = {"trainer": ("sft",),diff --git a/unsloth/utils/prefix_grouper_kernel.py b/unsloth/utils/prefix_grouper_kernel.pyindex 44bb264a344..cdc8fa165c7 100644--- a/unsloth/utils/prefix_grouper_kernel.py+++ b/unsloth/utils/prefix_grouper_kernel.py@@ -77,8 +77,6 @@ def _kernel_options_for_dtype(dtype, one_stage = False):return options-_FLEX_KERNEL_OPTIONS = {"BLOCK_M": _FP32_BLOCK_M, "BLOCK_N": _FP32_BLOCK_N}-# The compiled backward asserts unless T is a multiple of 128; pad tokens are fully masked and sliced off._PAD_MULTIPLE = 128_PAD_GROUP = -99 # sentinel group id / suffix id for pad tokens