Skip to content

Fix: restore requires_grad after _save_converted_model to work around peft inject_adapter side effect#1

Merged
kiritozc merged 1 commit into
mainfrom
fix/restore-requires-grad-after-save-converted
May 30, 2026
Merged

Fix: restore requires_grad after _save_converted_model to work around peft inject_adapter side effect#1
kiritozc merged 1 commit into
mainfrom
fix/restore-requires-grad-after-save-converted

Conversation

@kiritozc

Copy link
Copy Markdown
Owner

Problem

When using PiSSA/OLoRA/LoRA-GA with peft >= 0.18.1, the first save_checkpoint freezes the training adapter's parameters due to a side effect in peft's inject_adapter. After saving, grad_norm drops to 0 and training effectively stops.

Trigger path: _save_converted_modelmodel.save_pretrained(path_initial_model_for_weight_conversion=...)save_mutated_as_loraload_adapterinject_adapter → freezes active adapter

Root cause: peft 0.18.1 introduced a regression where inject_adapter passes the new adapter's inference_mode=True to set_adapter(self.active_adapters, inference_mode=True), which incorrectly sets requires_grad=False on the training adapter. See huggingface/peft#3290 for the upstream fix.

Fix

Save and restore requires_grad state of all parameters around the save_pretrained call in _save_converted_model. This applies to both the pissa/olora and lora-ga branches.

This is a defensive workaround that protects against the peft side effect without depending on any specific peft version. Once the upstream peft fix is merged and adopted, this workaround becomes a no-op safety net.

Related

@kiritozc kiritozc merged commit 608563f into main May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant