From b234532d9f02e232c973aa1cf6d137530b0b8d27 Mon Sep 17 00:00:00 2001 From: NanoCode012 Date: Fri, 28 Nov 2025 18:54:48 +0700 Subject: [PATCH] Feat: add peft_ensure_weight_tying (#3278) * feat: upgrade peft to 0.18.0 * feat: add peft_ensure_weight_tying * fix: default * chore: adjust kwarg per feedback --- requirements.txt | 2 +- src/axolotl/loaders/adapter.py | 2 ++ src/axolotl/utils/schemas/peft.py | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 08759279d..f020aaffc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ liger-kernel==0.6.3 packaging==23.2 huggingface_hub>=0.36.0 -peft>=0.17.1 +peft>=0.18.0 tokenizers>=0.22.1 transformers==4.57.1 accelerate==1.11.0 diff --git a/src/axolotl/loaders/adapter.py b/src/axolotl/loaders/adapter.py index 8e8177b62..dca688bb2 100644 --- a/src/axolotl/loaders/adapter.py +++ b/src/axolotl/loaders/adapter.py @@ -102,6 +102,8 @@ def load_lora( lora_config_kwargs["layer_replication"] = cfg.peft_layer_replication if cfg.peft_trainable_token_indices: lora_config_kwargs["trainable_token_indices"] = cfg.peft_trainable_token_indices + if cfg.peft_ensure_weight_tying is not None: + lora_config_kwargs["ensure_weight_tying"] = cfg.peft_ensure_weight_tying # Determine the correct PEFT task type model_cls = type(model).__name__ diff --git a/src/axolotl/utils/schemas/peft.py b/src/axolotl/utils/schemas/peft.py index af22913fd..fd16dec3f 100644 --- a/src/axolotl/utils/schemas/peft.py +++ b/src/axolotl/utils/schemas/peft.py @@ -100,6 +100,15 @@ class LoraConfig(BaseModel): ) }, ) + peft_ensure_weight_tying: bool | None = Field( + default=None, + json_schema_extra={ + "description": ( + "Whether to tie adapter weights for tied model weights. " + "See https://github.com/huggingface/peft/issues/2864" + ) + }, + ) qlora_sharded_model_loading: bool | None = Field( default=False,