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
Merge moe-lora-target-fix CI fixes
Datta Nimmaturi6f27ecc66e25
diff --git a/.github/workflows/consolidated-tests-ci.yml b/.github/workflows/consolidated-tests-ci.ymlindex bf7e62e2955..7e8d52525c0 100644--- a/.github/workflows/consolidated-tests-ci.yml+++ b/.github/workflows/consolidated-tests-ci.yml@@ -990,6 +990,7 @@ jobs:# First seen on transformers >=5,<6; each represents a slow# or recursive source-rewriter path the zoo can address."beit": "TimeoutError: compile exceeds per-model budget",+ "deepseek_ocr2": "TimeoutError: compile exceeds per-model budget","sam": "TimeoutError: compile exceeds per-model budget","sam_hq": "TimeoutError: compile exceeds per-model budget","deepseek_ocr2": "TimeoutError: compile exceeds per-model budget",diff --git a/.github/workflows/studio-inference-smoke.yml b/.github/workflows/studio-inference-smoke.ymlindex c1297b84ccb..3a4c76a2bb2 100644--- a/.github/workflows/studio-inference-smoke.yml+++ b/.github/workflows/studio-inference-smoke.yml@@ -20,7 +20,7 @@# enable_tools / enabled_tools, and enable_thinking on/off.## 3. JSON, images-# gemma-4-E2B-it UD-IQ3_XXS (~2.4 GiB) + mmproj-F16 (~986 MiB).+# Qwen3-VL-2B-Instruct UD-IQ2_XXS (~570 MiB) + mmproj-F16 (~780 MiB).# response_format JSON-schema decoding and OpenAI image_url# (data URI) plus Anthropic source/base64 image inputs.#@@ -791,9 +791,9 @@ jobs:runs-on: ubuntu-latesttimeout-minutes: 30env:- GGUF_REPO: unsloth/gemma-4-E2B-it-GGUF- GGUF_VARIANT: UD-IQ3_XXS- GGUF_FILE: gemma-4-E2B-it-UD-IQ3_XXS.gguf+ GGUF_REPO: unsloth/Qwen3-VL-2B-Instruct-GGUF+ GGUF_VARIANT: UD-IQ2_XXS+ GGUF_FILE: Qwen3-VL-2B-Instruct-UD-IQ2_XXS.ggufMMPROJ_FILE: mmproj-F16.ggufSTUDIO_PORT: '18890'HF_HOME: ${{ github.workspace }}/hf-cache@@ -888,13 +888,23 @@ jobs:-H 'content-type: application/json' \-d "{\"username\":\"unsloth\",\"password\":\"$NEW\"}" | jq -r .access_token)echo "API_KEY=$TOKEN" >> "$GITHUB_ENV"- # Load the GGUF (mmproj is auto-detected via the HF repo- # lookup, the cached file is pulled out of HF_HOME).- curl -fs -X POST "http://127.0.0.1:${STUDIO_PORT}/api/inference/load" \- -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \- --max-time 900 \- -d "{\"model_path\":\"$GGUF_REPO\",\"gguf_variant\":\"$GGUF_VARIANT\",\"is_lora\":false,\"max_seq_length\":2048}" \- | jq '{status, display_name, is_vision}'+ # Retry: llama-server startup can race process teardown after a+ # failed attempt. Keep curl out of a pipe so HTTP failures are not+ # masked by jq.+ LOAD_OK=0+ for attempt in 1 2 3; do+ HTTP=$(curl -s -o /tmp/load.json -w '%{http_code}' \+ -X POST "http://127.0.0.1:${STUDIO_PORT}/api/inference/load" \+ -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \+ --max-time 900 \+ -d "{\"model_path\":\"$GGUF_REPO\",\"gguf_variant\":\"$GGUF_VARIANT\",\"is_lora\":false,\"max_seq_length\":2048}")+ if [ "$HTTP" = "200" ]; then LOAD_OK=1; break; fi+ echo "::warning::/api/inference/load attempt $attempt returned $HTTP; response:"+ cat /tmp/load.json || true+ sleep 10+ done+ [ "$LOAD_OK" = "1" ] || { echo "::error::/api/inference/load failed 3 attempts"; exit 22; }+ jq '{status, display_name, is_vision}' /tmp/load.json- name: JSON schema decoding + image inputenv:diff --git a/.github/workflows/studio-windows-inference-smoke.yml b/.github/workflows/studio-windows-inference-smoke.ymlindex bbe6b9e33ad..6148856016f 100644--- a/.github/workflows/studio-windows-inference-smoke.yml+++ b/.github/workflows/studio-windows-inference-smoke.yml@@ -13,7 +13,7 @@# 2. Tool calling Tests# Qwen3.5-2B UD-Q4_K_XL (~890 MiB).# 3. JSON, images-# gemma-4-E2B-it UD-Q4_K_XL + mmproj-F16 (~3.4 GiB total).+# Qwen3-VL-2B-Instruct UD-IQ2_XXS + mmproj-F16 (~1.4 GiB total).# Within the 14 GB windows-latest SSD budget.name: Windows Studio GGUF CI@@ -843,9 +843,9 @@ jobs:run:shell: bashenv:- GGUF_REPO: unsloth/gemma-4-E2B-it-GGUF- GGUF_VARIANT: UD-Q4_K_XL- GGUF_FILE: gemma-4-E2B-it-UD-Q4_K_XL.gguf+ GGUF_REPO: unsloth/Qwen3-VL-2B-Instruct-GGUF+ GGUF_VARIANT: UD-IQ2_XXS+ GGUF_FILE: Qwen3-VL-2B-Instruct-UD-IQ2_XXS.ggufMMPROJ_FILE: mmproj-F16.ggufSTUDIO_PORT: '18899'HF_HOME: ${{ github.workspace }}/hf-cache@@ -1123,7 +1123,7 @@ jobs:)data_uri = f"data:image/png;base64,{PNG_64X64_RED_B64}"- # On Windows + the gemma-4-E2B mmproj, llama.cpp's vision+ # On Windows + the Qwen3-VL mmproj, llama.cpp's vision# path runs on CPU (no Metal involvement). The wrapper is# kept for resilience but the vision path is expected to# work on Windows; an exception here is a real regression.diff --git a/tests/test_moe_lora_targets.py b/tests/test_moe_lora_targets.pynew file mode 100644index 00000000000..994d39f2617--- /dev/null+++ b/tests/test_moe_lora_targets.py@@ -0,0 +1,51 @@+from types import SimpleNamespace++import pytest+import torch+++class _ExpertWeights(torch.nn.Module):+ def __init__(self):+ super().__init__()+ self.gate_up_proj = torch.nn.Parameter(torch.zeros(2, 4, 8))+ self.down_proj = torch.nn.Parameter(torch.zeros(2, 8, 4))+++class _Mlp(torch.nn.Module):+ def __init__(self):+ super().__init__()+ self.experts = _ExpertWeights()+++class _FakeMoeModel(torch.nn.Module):+ def __init__(self):+ super().__init__()+ self.config = SimpleNamespace(num_experts = 2, model_type = "qwen3_moe")+ self.mlp = _Mlp()+++ "target_modules",+ [+ ".*mlp.*proj",+ ".*ffn.*proj",+ r"(?:\bmodel\.layers\.[\d]{1,}\.(?:mlp)\.(?:gate_proj|up_proj|down_proj))",+ ],+)+def test_regex_mlp_targets_discover_moe_parameters(target_modules):+ from unsloth.models._utils import get_moe_target_parameters+ assert get_moe_target_parameters(_FakeMoeModel(), target_modules) == [+ "mlp.experts.gate_up_proj",+ "mlp.experts.down_proj",+ ]+++def test_explicit_dotted_module_target_does_not_discover_moe_parameters():+ from unsloth.models._utils import get_moe_target_parameters+ assert (+ get_moe_target_parameters(+ _FakeMoeModel(),+ "model.layers.0.mlp.shared_expert.down_proj",+ )+ is None+ )diff --git a/tests/version_compat/test_trl_grpo_pinned_symbols.py b/tests/version_compat/test_trl_grpo_pinned_symbols.pyindex 3f6c40f90d2..e49f9292e01 100644--- a/tests/version_compat/test_trl_grpo_pinned_symbols.py+++ b/tests/version_compat/test_trl_grpo_pinned_symbols.py@@ -554,11 +554,12 @@ def test_trl_kto_get_batch_logps_signature(tag: str):"trl/experimental/kto/kto_trainer.py","trl/experimental/kto/__init__.py",]+ checked_sources = []for path in candidates:src = fetch_text("huggingface/trl", tag, path)if src is None:continue- # Legacy: explicit get_batch_logps method.+ checked_sources.append((path, src))if has_def(src, "get_batch_logps", "func"):return# TRL 1.x: refactored into _compute_logps + selective_log_softmax.@@ -569,6 +570,15 @@ def test_trl_kto_get_batch_logps_signature(tag: str):# the exact shape kto_trainer_align_completion_logps patches.if "per_token_logps = selective_log_softmax(shift_logits" in src:return+ old_shape_check = (+ 'raise ValueError("Logits (batch and sequence length dim) and labels '+ 'must have the same shape.")'+ )+ if checked_sources and not any(old_shape_check in src for _, src in checked_sources):+ # TRL main inlined KTO log-prob computation and removed the old+ # helper/shape-check rewrite target. There is no skipped rewrite to+ # guard until a new concrete KTO shape mismatch target appears.+ returnpytest.fail(f"{tag}: KTO log-prob computation not found in any of {candidates}; "f"unsloth/models/rl_replacements.py KTO rewrite silently skipped"diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.pyindex 45b127a0679..c8be78bc3c1 100644--- a/unsloth/import_fixes.py+++ b/unsloth/import_fixes.py@@ -1597,6 +1597,8 @@ def patch_peft_weight_converter_compatibility():except (ImportError, AttributeError):return+ _patch_peft_moe_target_conversion(twc)+if getattr(twc, "_unsloth_weight_converter_compat_patch", False):return@@ -1666,6 +1668,47 @@ def patch_peft_weight_converter_compatibility():twc._unsloth_weight_converter_compat_patch = True+def _patch_peft_moe_target_conversion(twc):+ """Keep PEFT 0.19 MoE conversion from rewriting explicit Unsloth targets."""+ if getattr(twc, "_unsloth_moe_target_conversion_patch", False):+ return++ original_convert_moe = getattr(twc, "_convert_peft_config_moe", None)+ if original_convert_moe is None:+ return++ @functools.wraps(original_convert_moe)+ def _convert_peft_config_moe_unsloth(peft_config, model_type: str) -> None:+ if getattr(peft_config, "target_parameters", None):+ return++ target_modules = getattr(peft_config, "target_modules", None)+ if isinstance(target_modules, str):+ if "." in target_modules:+ return+ return original_convert_moe(peft_config, model_type)++ if not target_modules:+ return original_convert_moe(peft_config, model_type)++ explicit_targets = {+ target for target in target_modules if isinstance(target, str) and "." in target+ }+ if not explicit_targets:+ return original_convert_moe(peft_config, model_type)++ bare_targets = set(target_modules) - explicit_targets+ if not bare_targets:+ return++ peft_config.target_modules = bare_targets+ original_convert_moe(peft_config, model_type)+ peft_config.target_modules = set(peft_config.target_modules or ()) | explicit_targets++ twc._convert_peft_config_moe = _convert_peft_config_moe_unsloth+ twc._unsloth_moe_target_conversion_patch = True++CAUSAL_CONV1D_BROKEN = False_CAUSAL_CONV1D_PREFIX = "causal_conv1d"_CAUSAL_CONV1D_BLOCKER_SENTINEL = "_unsloth_causal_conv1d_blocker"diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 10f3ce0b1da..f8324bf8e01 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -3154,6 +3154,21 @@ def _resolve_moe_parameter_name(model, default_name: str, alternate_name: str) -return default_name+_MOE_BROAD_MLP_TARGETS = frozenset(("gate_proj", "up_proj", "down_proj", "gate_up_proj"))+++def _moe_target_set_from_string(target_modules: str) -> set[str]:+ if target_modules in _MOE_BROAD_MLP_TARGETS:+ return {target_modules}++ is_regex = re.search(r"[*+?()[\]{}|\\^$]", target_modules) is not None+ targets_mlp = "mlp" in target_modules or "ffn" in target_modules+ if is_regex and "proj" in target_modules and targets_mlp:+ return set(_MOE_BROAD_MLP_TARGETS)++ return set()++def get_moe_target_parameters(model, target_modules = None) -> Optional[List[str]]:"""Get the target_parameters for MoE expert layers if applicable.@@ -3193,20 +3208,18 @@ def get_moe_target_parameters(model, target_modules = None) -> Optional[List[strif num_experts is None:num_experts = 0- # Determine which MoE parameters to include based on target_modules- moe_params = []-- # Normalize target_modules to a set for efficient lookupif target_modules is None:- # If no target_modules specified, include all MoE params- target_set = {"gate_proj", "up_proj", "down_proj", "gate_up_proj"}+ return Noneelif isinstance(target_modules, str):- target_set = {target_modules}- # Heuristic for regex matching MLPs- if "proj" in target_modules and ("mlp" in target_modules or "ffn" in target_modules):- target_set.update({"gate_proj", "up_proj", "down_proj", "gate_up_proj"})+ target_set = _moe_target_set_from_string(target_modules)else:- target_set = set(target_modules) if target_modules else set()+ target_set = {+ target+ for target in target_modules or ()+ if (isinstance(target, str) and "." not in target and target in _MOE_BROAD_MLP_TARGETS)+ }++ moe_params = []gate_up_name = _resolve_moe_parameter_name(model,