Repository: huggingface/peft

Issue:
No Trainable Parameters when PeftModel.from_pretrained()
Example (using transformers master and peft master):

```python
from peft import PeftModel
from transformers import LlamaForCausalLM
import torch

orig_model = LlamaForCausalLM.from_pretrained(
   'decapoda-research/llama-7b-hf',
    load_in_8bit=True,
    torch_dtype=torch.float16,
    device_map="auto",
)

out = PeftModel.from_pretrained(orig_model, "tloen/alpaca-lora-7b")
print(out.print_trainable_parameters())
# trainable params: 0 || all params: 6755201024 || trainable%: 0.0
```

This issue was not there a few days ago so I'm guessing a recent commit broke it!



Discussion:
Can confirm that peft==0.2.0 does not have this issue. The above code snippet gives me 

```
trainable params: 16777216 || all params: 6755192832 || trainable%: 0.24836028248556738
```
Using this commit `pip install git+https://github.com/huggingface/peft.git@d5feb8b787624bd9b886a4eb447eabf6d01b8bb2`

gives 
```
trainable params: 262410240 || all params: 6755192832 || trainable%: 3.8845706780854186
```

which is even more worrying...

Resolving patch:
diff --git a/src/peft/peft_model.py b/src/peft/peft_model.py
--- a/src/peft/peft_model.py
+++ b/src/peft/peft_model.py
@@ -132,7 +132,7 @@ def save_pretrained(self, save_directory, **kwargs):
             peft_config.inference_mode = inference_mode
 
     @classmethod
-    def from_pretrained(cls, model, model_id, adapter_name="default", **kwargs):
+    def from_pretrained(cls, model, model_id, adapter_name="default", is_trainable=False, **kwargs):
         r"""
         Instantiate a [`LoraModel`] from a pretrained Lora configuration and weights.
 
@@ -159,6 +159,11 @@ def from_pretrained(cls, model, model_id, adapter_name="default", **kwargs):
         ) > 0:
             remove_hook_from_submodules(model)
 
+        if isinstance(config, PromptLearningConfig) and is_trainable:
+            raise ValueError("Cannot set a prompt learning adapter to trainable when loading pretrained adapter.")
+        else:
+            config.inference_mode = not is_trainable
+
         if config.task_type not in MODEL_TYPE_TO_PEFT_MODEL_MAPPING.keys():
             model = cls(model, config, adapter_name)
         else:
diff --git a/src/peft/tuners/adalora.py b/src/peft/tuners/adalora.py
--- a/src/peft/tuners/adalora.py
+++ b/src/peft/tuners/adalora.py
@@ -117,11 +117,11 @@ def add_adapter(self, adapter_name, config=None):
                 "When using multiple adapters, set inference_mode to True for all adapters except the one you want to train."
             )
 
+        mark_only_lora_as_trainable(self.model, self.peft_config[adapter_name].bias)
         if self.peft_config[adapter_name].inference_mode:
             _freeze_adapter(self.model, adapter_name)
         else:
             self.trainable_adapter_name = adapter_name
-            mark_only_lora_as_trainable(self.model, self.peft_config[adapter_name].bias)
             self.rankallocator = RankAllocator(self.model, self.peft_config[adapter_name], self.trainable_adapter_name)
 
     def _find_and_replace(self, adapter_name):
diff --git a/src/peft/tuners/lora.py b/src/peft/tuners/lora.py
--- a/src/peft/tuners/lora.py
+++ b/src/peft/tuners/lora.py
@@ -143,10 +143,9 @@ def add_adapter(self, adapter_name, config=None):
             raise ValueError(
                 "LoraModel supports only 1 adapter with bias. When using multiple adapters, set bias to 'none' for all adapters."
             )
+        mark_only_lora_as_trainable(self.model, self.peft_config[adapter_name].bias)
         if self.peft_config[adapter_name].inference_mode:
             _freeze_adapter(self.model, adapter_name)
-        else:
-            mark_only_lora_as_trainable(self.model, self.peft_config[adapter_name].bias)
 
     def _find_and_replace(self, adapter_name):
         lora_config = self.peft_config[adapter_name]


Test patch: