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
OpenVINO export: trust remote code only for a remote-code model, and decode the bounds probe as UTF-8 (#12012)
Daniel Hanad3038b43495
diff --git a/tests/saving/test_openvino_export.py b/tests/saving/test_openvino_export.pyindex 9e0eba93054..e9af1811187 100644--- a/tests/saving/test_openvino_export.py+++ b/tests/saving/test_openvino_export.py@@ -86,6 +86,18 @@ def test_options_vlm_task_remote_code_token_and_missing_tokenizer(run, monkeypatassert len(warnings) == 1 and "openvino_tokenizer.xml" in warnings[0]+def test_a_custom_tokenizer_alone_does_not_trust_the_model(run, monkeypatch):+ # optimum-cli has one --trust-remote-code for both loads, so it follows the model: granting it+ # for an approved custom tokenizer would let the reload run a built-in model's unvetted auto_map.+ tokenizer = SimpleNamespace()+ monkeypatch.setattr(save_mod, "_loaded_via_remote_code", lambda obj: obj is tokenizer)+ monkeypatch.setattr(save_mod.logger, "warning_once", (warnings := []).append)+ run(tokenizer = tokenizer)+ (cmd,) = run.seen.cmds+ assert "--trust-remote-code" not in cmd+ assert len(warnings) == 1 and "tokenizer" in warnings[0]++@pytest.mark.parametrize("case", [*_CASES, *_BOUNDS, "no optimum", "child fails", "no model"])def test_failures_come_before_the_merge_or_clean_up(run, monkeypatch, case):if case in _BOUNDS: # optimum-intel's transformers bounds for this architecturediff --git a/unsloth/save.py b/unsloth/save.pyindex ca6849776e9..171e4fb60c6 100644--- a/unsloth/save.py+++ b/unsloth/save.py@@ -7009,6 +7009,8 @@ def _openvino_transformers_mismatch(model_type, task):[sys.executable, "-c", _OPENVINO_BOUNDS_PROBE, model_type, task],capture_output = True,text = True,+ encoding = "utf-8",+ errors = "replace",timeout = 300,)low, high = json.loads(probe.stdout.strip().splitlines()[-1])@@ -7054,10 +7056,15 @@ def _unsloth_save_openvino(if not is_main_process:return None- # Everything that can reject the request runs before the merge, which writes a full 16bit checkpoint. Remote code is trusted only when the model or tokenizer was already loaded through it.+ # Everything that can reject the request runs before the merge, which writes a full 16bit checkpoint. optimum-cli takes one --trust-remote-code for the model and tokenizer loads together, so it follows the model's approved load decision, as the GGUF-LoRA converter does: a custom tokenizer alone must not let the reload run a built-in-loaded model's unvetted auto_map code.export_kwargs = dict(export_kwargs)- if _loaded_via_remote_code(model) or _loaded_via_remote_code(tokenizer):+ if _loaded_via_remote_code(model):export_kwargs.setdefault("trust_remote_code", True)+ elif _loaded_via_remote_code(tokenizer) and "trust_remote_code" not in export_kwargs:+ logger.warning_once(+ "Unsloth: the tokenizer was loaded through remote code but the model was not, so the "+ "OpenVINO export runs without trust_remote_code and may skip converting the tokenizer."+ )export_kwargs.setdefault("library", "transformers")# optimum-cli cannot infer the task from a local directory. Same VLM test as the torchao and compressed exports: a bare *ForConditionalGeneration also matches text seq2seq.config = getattr(model, "config", None)