Silence peft target_parameters RuntimeWarning for MoE models (#4008)

* 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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Daniel Hanchen <danielhanchen@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Daniel Han 2026-02-09 08:25:40 -08:00 committed by GitHub
commit 97967eca81
2 changed files with 16 additions and 2 deletions

View file

@ -3072,7 +3072,14 @@ 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)

View file

@ -1209,7 +1209,14 @@ 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")