From 0860a0661a1300fca3091fda37f5446763f6d49e Mon Sep 17 00:00:00 2001 From: Daniel Hanchen Date: Mon, 9 Feb 2026 16:02:18 +0000 Subject: [PATCH] Silence peft target_parameters RuntimeWarning for MoE models Wrap _get_peft_model calls with warnings.catch_warnings() to suppress the "target_parameters were set but no parameter was matched" warning. This fires on MoE models where expert layers use nn.Parameter naming that peft warns about but handles correctly. --- unsloth/models/llama.py | 5 ++++- unsloth/models/vision.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index 61771e4567..eac1b5502c 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -3070,7 +3070,10 @@ class FastLlamaModel: gc.collect() clean_gpu_cache() - model = _get_peft_model(model, lora_config) + import warnings as _w + with _w.catch_warnings(): + _w.filterwarnings("ignore", message=".*target_parameters.*were set but no parameter was matched.*") + model = _get_peft_model(model, lora_config) # Fix LoraConfig.auto_mapping is None fix_lora_auto_mapping(model) diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 2c1371a4a2..1466a59ab0 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -1209,7 +1209,10 @@ class FastBaseModel: model, use_gradient_checkpointing = use_gradient_checkpointing, ) - model = _get_peft_model(model, lora_config) + import warnings as _w + with _w.catch_warnings(): + _w.filterwarnings("ignore", message=".*target_parameters.*were set but no parameter was matched.*") + model = _get_peft_model(model, lora_config) # Apply QAT + LoRA if specified if qat_scheme is not None: print("Unsloth: Applying QAT to mitigate quantization degradation")