Skip to content

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.

Guard OpenVINO exports on PEFT-wrapped bases (#17471)

DimitriChrysafis35b87ecae513
diff --git a/tests/saving/test_peft_base_export_guard.py b/tests/saving/test_peft_base_export_guard.py
index 3e7c24c532e..34c801b3809 100644
--- a/tests/saving/test_peft_base_export_guard.py
+++ b/tests/saving/test_peft_base_export_guard.py
@@ -20,6 +20,8 @@ _EXPORT_FUNCTIONS = {
"unsloth_generic_save_pretrained_merged",
"unsloth_generic_push_to_hub_merged",
"unsloth_save_pretrained_torchao",
+ "unsloth_save_pretrained_openvino",
+ "unsloth_push_to_hub_openvino",
}
@@ -105,6 +107,27 @@ def test_a_full_fine_tune_is_allowed(peft_guard_env):
guard(_Model(object()))
+# PeftModel defines its own save_pretrained / push_to_hub, so those never forward to the base; the GGML LoRA exports refuse a non-PeftModel themselves.
+_UNGUARDED_BINDINGS = {
+ "unsloth_model_save_pretrained",
+ "unsloth_push_to_hub",
+ "unsloth_tokenizer_save_pretrained",
+ "unsloth_convert_lora_to_ggml_and_push_to_hub",
+ "unsloth_convert_lora_to_ggml_and_save_locally",
+}
+
+
+def test_every_bound_export_is_guarded_or_exempt():
+ bound = {
+ node.args[0].id
+ for node in ast.walk(_function("patch_saving_functions"))
+ if isinstance(node, ast.Call)
+ and getattr(node.func, "id", None) == "_bind_saving_method"
+ and isinstance(node.args[0], ast.Name)
+ }
+ assert bound - _UNGUARDED_BINDINGS == _EXPORT_FUNCTIONS
+
+
@pytest.mark.parametrize("name", sorted(_EXPORT_FUNCTIONS))
def test_export_entrypoints_install_the_guard(name):
source = ast.get_source_segment(_SOURCE, _function(name))
diff --git a/unsloth/save.py b/unsloth/save.py
index 3cb5c3a48f8..2bfa13f8776 100644
--- a/unsloth/save.py
+++ b/unsloth/save.py
@@ -9034,6 +9034,7 @@ def unsloth_save_pretrained_openvino(
- is_main_process: Only the main process exports under multi-GPU / DDP.
- **kwargs: Other `optimum-cli export openvino` options, with underscores for dashes, e.g. group_size = 64, ratio = 0.8, sym = False, awq = True, dataset = "wikitext2". They override the quantization_type preset.
"""
+ _assert_export_target_is_not_base_with_lora_layers(self)
return _unsloth_save_openvino(
model = self,
save_directory = save_directory,
@@ -9060,6 +9061,7 @@ def unsloth_push_to_hub_openvino(
**kwargs,
):
"""Export the model to OpenVINO IR format and push it to the Hugging Face Hub. Takes the same options as save_pretrained_openvino."""
+ _assert_export_target_is_not_base_with_lora_layers(self)
return _unsloth_save_openvino(
model = self,
save_directory = repo_id,