We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Deepcopy not copying the LoraConfig
I'm trying to make a deepcopy (using copy.deepcopy) of a LoraModel on the version '0.2.0'. But the values in PeftConfig remain the default ones (e.g. r = 8), not the ones of the copied model. Is it normal ? Am I supposed to do a `model_copy = get_peft_model(model_copy, peft_config)` ?
It is possible to implement `__deepcopy__` and `__copy__` if necessary.

Here is a reproduction example :
``` Python
import copy
from transformers import AutoModelForCausalLM
from peft import get_peft_config, get_peft_model, LoraConfig, TaskType
model_name_or_path = "gpt2"
tokenizer_name_or_path = "gpt2"
peft_config = LoraConfig(task_type=TaskType.CAUSAL_LM, inference_mode=False, r=87, lora_alpha=32, lora_dropout=0.1)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
model = get_peft_model(model, peft_config)

model_copy = copy.deepcopy(model)
assert(model.peft_config.r == model_copy.peft_config.r)
```

Moreover, I also get an AssertionError if I continue with :
``` Python
model_copy = get_peft_model(model_copy, peft_config)
assert(model == model_copy)
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/peft/utils/config.py`
Content:
```
1 # coding=utf-8
2 # Copyright 2023-present the HuggingFace Inc. team.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 import enum
16 import inspect
17 import json
18 import os
19 from dataclasses import asdict, dataclass, field
20 from typing import Optional, Union
21 
22 from huggingface_hub import hf_hub_download
23 from transformers.utils import PushToHubMixin
24 
25 from .other import CONFIG_NAME
26 
27 
28 class PeftType(str, enum.Enum):
29     PROMPT_TUNING = "PROMPT_TUNING"
30     P_TUNING = "P_TUNING"
31     PREFIX_TUNING = "PREFIX_TUNING"
32     LORA = "LORA"
33     ADALORA = "ADALORA"
34     ADAPTION_PROMPT = "ADAPTION_PROMPT"
35 
36 
37 class TaskType(str, enum.Enum):
38     SEQ_CLS = "SEQ_CLS"
39     SEQ_2_SEQ_LM = "SEQ_2_SEQ_LM"
40     CAUSAL_LM = "CAUSAL_LM"
41     TOKEN_CLS = "TOKEN_CLS"
42     QUESTION_ANS = "QUESTION_ANS"
43 
44 
45 @dataclass
46 class PeftConfigMixin(PushToHubMixin):
47     r"""
48     This is the base configuration class for PEFT adapter models. It contains all the methods that are common to all
49     PEFT adapter models. This class inherits from [`~transformers.utils.PushToHubMixin`] which contains the methods to
50     push your model to the Hub. The method `save_pretrained` will save the configuration of your adapter model in a
51     directory. The method `from_pretrained` will load the configuration of your adapter model from a directory.
52 
53     Args:
54         peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.
55     """
56     peft_type: Optional[PeftType] = field(default=None, metadata={"help": "The type of PEFT model."})
57 
58     @property
59     def __dict__(self):
60         return asdict(self)
61 
62     def to_dict(self):
63         return self.__dict__
64 
65     def save_pretrained(self, save_directory, **kwargs):
66         r"""
67         This method saves the configuration of your adapter model in a directory.
68 
69         Args:
70             save_directory (`str`):
71                 The directory where the configuration will be saved.
72             kwargs (additional keyword arguments, *optional*):
73                 Additional keyword arguments passed along to the [`~transformers.utils.PushToHubMixin.push_to_hub`]
74                 method.
75         """
76         if os.path.isfile(save_directory):
77             raise AssertionError(f"Provided path ({save_directory}) should be a directory, not a file")
78 
79         os.makedirs(save_directory, exist_ok=True)
80 
81         output_dict = self.__dict__
82         output_path = os.path.join(save_directory, CONFIG_NAME)
83 
84         # save it
85         with open(output_path, "w") as writer:
86             writer.write(json.dumps(output_dict, indent=2, sort_keys=True))
87 
88     @classmethod
89     def from_pretrained(cls, pretrained_model_name_or_path, subfolder=None, **kwargs):
90         r"""
91         This method loads the configuration of your adapter model from a directory.
92 
93         Args:
94             pretrained_model_name_or_path (`str`):
95                 The directory or the Hub repository id where the configuration is saved.
96             kwargs (additional keyword arguments, *optional*):
97                 Additional keyword arguments passed along to the child class initialization.
98         """
99         path = (
100             os.path.join(pretrained_model_name_or_path, subfolder)
101             if subfolder is not None
102             else pretrained_model_name_or_path
103         )
104 
105         hf_hub_download_kwargs, class_kwargs, other_kwargs = cls._split_kwargs(kwargs)
106 
107         if os.path.isfile(os.path.join(path, CONFIG_NAME)):
108             config_file = os.path.join(path, CONFIG_NAME)
109         else:
110             try:
111                 config_file = hf_hub_download(
112                     pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **hf_hub_download_kwargs
113                 )
114             except Exception:
115                 raise ValueError(f"Can't find '{CONFIG_NAME}' at '{pretrained_model_name_or_path}'")
116 
117         loaded_attributes = cls.from_json_file(config_file)
118 
119         config = cls(**class_kwargs)
120 
121         for key, value in loaded_attributes.items():
122             if hasattr(config, key):
123                 setattr(config, key, value)
124 
125         return config
126 
127     @classmethod
128     def from_json_file(cls, path_json_file, **kwargs):
129         r"""
130         Loads a configuration file from a json file.
131 
132         Args:
133             path_json_file (`str`):
134                 The path to the json file.
135         """
136         with open(path_json_file, "r") as file:
137             json_object = json.load(file)
138 
139         return json_object
140 
141     @classmethod
142     def _split_kwargs(cls, kwargs):
143         hf_hub_download_kwargs = {}
144         class_kwargs = {}
145         other_kwargs = {}
146 
147         for key, value in kwargs.items():
148             if key in inspect.signature(hf_hub_download).parameters:
149                 hf_hub_download_kwargs[key] = value
150             elif key in list(cls.__annotations__):
151                 class_kwargs[key] = value
152             else:
153                 other_kwargs[key] = value
154 
155         return hf_hub_download_kwargs, class_kwargs, other_kwargs
156 
157     @classmethod
158     def _get_peft_type(
159         cls,
160         model_id,
161         subfolder: Optional[str] = None,
162         revision: Optional[str] = None,
163         cache_dir: Optional[str] = None,
164     ):
165         path = os.path.join(model_id, subfolder) if subfolder is not None else model_id
166 
167         if os.path.isfile(os.path.join(path, CONFIG_NAME)):
168             config_file = os.path.join(path, CONFIG_NAME)
169         else:
170             try:
171                 config_file = hf_hub_download(
172                     model_id, CONFIG_NAME, subfolder=subfolder, revision=revision, cache_dir=cache_dir
173                 )
174             except Exception:
175                 raise ValueError(f"Can't find '{CONFIG_NAME}' at '{model_id}'")
176 
177         loaded_attributes = cls.from_json_file(config_file)
178         return loaded_attributes["peft_type"]
179 
180 
181 @dataclass
182 class PeftConfig(PeftConfigMixin):
183     """
184     This is the base configuration class to store the configuration of a [`PeftModel`].
185 
186     Args:
187         peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.
188         task_type (Union[[`~peft.utils.config.TaskType`], `str`]): The type of task to perform.
189         inference_mode (`bool`, defaults to `False`): Whether to use the Peft model in inference mode.
190     """
191 
192     base_model_name_or_path: str = field(default=None, metadata={"help": "The name of the base model to use."})
193     revision: str = field(default=None, metadata={"help": "The specific model version to use."})
194     peft_type: Union[str, PeftType] = field(default=None, metadata={"help": "Peft type"})
195     task_type: Union[str, TaskType] = field(default=None, metadata={"help": "Task type"})
196     inference_mode: bool = field(default=False, metadata={"help": "Whether to use inference mode"})
197 
198 
199 @dataclass
200 class PromptLearningConfig(PeftConfig):
201     """
202     This is the base configuration class to store the configuration of [`PrefixTuning`], [`PromptEncoder`], or
203     [`PromptTuning`].
204 
205     Args:
206         num_virtual_tokens (`int`): The number of virtual tokens to use.
207         token_dim (`int`): The hidden embedding dimension of the base transformer model.
208         num_transformer_submodules (`int`): The number of transformer submodules in the base transformer model.
209         num_attention_heads (`int`): The number of attention heads in the base transformer model.
210         num_layers (`int`): The number of layers in the base transformer model.
211     """
212 
213     num_virtual_tokens: int = field(default=None, metadata={"help": "Number of virtual tokens"})
214     token_dim: int = field(
215         default=None, metadata={"help": "The hidden embedding dimension of the base transformer model"}
216     )
217     num_transformer_submodules: Optional[int] = field(
218         default=None, metadata={"help": "Number of transformer submodules"}
219     )
220     num_attention_heads: Optional[int] = field(default=None, metadata={"help": "Number of attention heads"})
221     num_layers: Optional[int] = field(default=None, metadata={"help": "Number of transformer layers"})
222
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/peft/utils/config.py b/src/peft/utils/config.py
--- a/src/peft/utils/config.py
+++ b/src/peft/utils/config.py
@@ -55,12 +55,8 @@
     """
     peft_type: Optional[PeftType] = field(default=None, metadata={"help": "The type of PEFT model."})
 
-    @property
-    def __dict__(self):
-        return asdict(self)
-
     def to_dict(self):
-        return self.__dict__
+        return asdict(self)
 
     def save_pretrained(self, save_directory, **kwargs):
         r"""
@@ -78,7 +74,7 @@
 
         os.makedirs(save_directory, exist_ok=True)
 
-        output_dict = self.__dict__
+        output_dict = asdict(self)
         output_path = os.path.join(save_directory, CONFIG_NAME)
 
         # save it

{"golden_diff": "diff --git a/src/peft/utils/config.py b/src/peft/utils/config.py\n--- a/src/peft/utils/config.py\n+++ b/src/peft/utils/config.py\n@@ -55,12 +55,8 @@\n     \"\"\"\n     peft_type: Optional[PeftType] = field(default=None, metadata={\"help\": \"The type of PEFT model.\"})\n \n-    @property\n-    def __dict__(self):\n-        return asdict(self)\n-\n     def to_dict(self):\n-        return self.__dict__\n+        return asdict(self)\n \n     def save_pretrained(self, save_directory, **kwargs):\n         r\"\"\"\n@@ -78,7 +74,7 @@\n \n         os.makedirs(save_directory, exist_ok=True)\n \n-        output_dict = self.__dict__\n+        output_dict = asdict(self)\n         output_path = os.path.join(save_directory, CONFIG_NAME)\n \n         # save it\n", "issue": "Deepcopy not copying the LoraConfig\nI'm trying to make a deepcopy (using copy.deepcopy) of a LoraModel on the version '0.2.0'. But the values in PeftConfig remain the default ones (e.g. r = 8), not the ones of the copied model. Is it normal ? Am I supposed to do a `model_copy = get_peft_model(model_copy, peft_config)` ?\r\nIt is possible to implement `__deepcopy__` and `__copy__` if necessary.\r\n\r\nHere is a reproduction example :\r\n``` Python\r\nimport copy\r\nfrom transformers import AutoModelForCausalLM\r\nfrom peft import get_peft_config, get_peft_model, LoraConfig, TaskType\r\nmodel_name_or_path = \"gpt2\"\r\ntokenizer_name_or_path = \"gpt2\"\r\npeft_config = LoraConfig(task_type=TaskType.CAUSAL_LM, inference_mode=False, r=87, lora_alpha=32, lora_dropout=0.1)\r\nmodel = AutoModelForCausalLM.from_pretrained(model_name_or_path)\r\nmodel = get_peft_model(model, peft_config)\r\n\r\nmodel_copy = copy.deepcopy(model)\r\nassert(model.peft_config.r == model_copy.peft_config.r)\r\n```\r\n\r\nMoreover, I also get an AssertionError if I continue with :\r\n``` Python\r\nmodel_copy = get_peft_model(model_copy, peft_config)\r\nassert(model == model_copy)\r\n```\n", "before_files": [{"content": "# coding=utf-8\n# Copyright 2023-present the HuggingFace Inc. team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport enum\nimport inspect\nimport json\nimport os\nfrom dataclasses import asdict, dataclass, field\nfrom typing import Optional, Union\n\nfrom huggingface_hub import hf_hub_download\nfrom transformers.utils import PushToHubMixin\n\nfrom .other import CONFIG_NAME\n\n\nclass PeftType(str, enum.Enum):\n    PROMPT_TUNING = \"PROMPT_TUNING\"\n    P_TUNING = \"P_TUNING\"\n    PREFIX_TUNING = \"PREFIX_TUNING\"\n    LORA = \"LORA\"\n    ADALORA = \"ADALORA\"\n    ADAPTION_PROMPT = \"ADAPTION_PROMPT\"\n\n\nclass TaskType(str, enum.Enum):\n    SEQ_CLS = \"SEQ_CLS\"\n    SEQ_2_SEQ_LM = \"SEQ_2_SEQ_LM\"\n    CAUSAL_LM = \"CAUSAL_LM\"\n    TOKEN_CLS = \"TOKEN_CLS\"\n    QUESTION_ANS = \"QUESTION_ANS\"\n\n\n@dataclass\nclass PeftConfigMixin(PushToHubMixin):\n    r\"\"\"\n    This is the base configuration class for PEFT adapter models. It contains all the methods that are common to all\n    PEFT adapter models. This class inherits from [`~transformers.utils.PushToHubMixin`] which contains the methods to\n    push your model to the Hub. The method `save_pretrained` will save the configuration of your adapter model in a\n    directory. The method `from_pretrained` will load the configuration of your adapter model from a directory.\n\n    Args:\n        peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.\n    \"\"\"\n    peft_type: Optional[PeftType] = field(default=None, metadata={\"help\": \"The type of PEFT model.\"})\n\n    @property\n    def __dict__(self):\n        return asdict(self)\n\n    def to_dict(self):\n        return self.__dict__\n\n    def save_pretrained(self, save_directory, **kwargs):\n        r\"\"\"\n        This method saves the configuration of your adapter model in a directory.\n\n        Args:\n            save_directory (`str`):\n                The directory where the configuration will be saved.\n            kwargs (additional keyword arguments, *optional*):\n                Additional keyword arguments passed along to the [`~transformers.utils.PushToHubMixin.push_to_hub`]\n                method.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            raise AssertionError(f\"Provided path ({save_directory}) should be a directory, not a file\")\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        output_dict = self.__dict__\n        output_path = os.path.join(save_directory, CONFIG_NAME)\n\n        # save it\n        with open(output_path, \"w\") as writer:\n            writer.write(json.dumps(output_dict, indent=2, sort_keys=True))\n\n    @classmethod\n    def from_pretrained(cls, pretrained_model_name_or_path, subfolder=None, **kwargs):\n        r\"\"\"\n        This method loads the configuration of your adapter model from a directory.\n\n        Args:\n            pretrained_model_name_or_path (`str`):\n                The directory or the Hub repository id where the configuration is saved.\n            kwargs (additional keyword arguments, *optional*):\n                Additional keyword arguments passed along to the child class initialization.\n        \"\"\"\n        path = (\n            os.path.join(pretrained_model_name_or_path, subfolder)\n            if subfolder is not None\n            else pretrained_model_name_or_path\n        )\n\n        hf_hub_download_kwargs, class_kwargs, other_kwargs = cls._split_kwargs(kwargs)\n\n        if os.path.isfile(os.path.join(path, CONFIG_NAME)):\n            config_file = os.path.join(path, CONFIG_NAME)\n        else:\n            try:\n                config_file = hf_hub_download(\n                    pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **hf_hub_download_kwargs\n                )\n            except Exception:\n                raise ValueError(f\"Can't find '{CONFIG_NAME}' at '{pretrained_model_name_or_path}'\")\n\n        loaded_attributes = cls.from_json_file(config_file)\n\n        config = cls(**class_kwargs)\n\n        for key, value in loaded_attributes.items():\n            if hasattr(config, key):\n                setattr(config, key, value)\n\n        return config\n\n    @classmethod\n    def from_json_file(cls, path_json_file, **kwargs):\n        r\"\"\"\n        Loads a configuration file from a json file.\n\n        Args:\n            path_json_file (`str`):\n                The path to the json file.\n        \"\"\"\n        with open(path_json_file, \"r\") as file:\n            json_object = json.load(file)\n\n        return json_object\n\n    @classmethod\n    def _split_kwargs(cls, kwargs):\n        hf_hub_download_kwargs = {}\n        class_kwargs = {}\n        other_kwargs = {}\n\n        for key, value in kwargs.items():\n            if key in inspect.signature(hf_hub_download).parameters:\n                hf_hub_download_kwargs[key] = value\n            elif key in list(cls.__annotations__):\n                class_kwargs[key] = value\n            else:\n                other_kwargs[key] = value\n\n        return hf_hub_download_kwargs, class_kwargs, other_kwargs\n\n    @classmethod\n    def _get_peft_type(\n        cls,\n        model_id,\n        subfolder: Optional[str] = None,\n        revision: Optional[str] = None,\n        cache_dir: Optional[str] = None,\n    ):\n        path = os.path.join(model_id, subfolder) if subfolder is not None else model_id\n\n        if os.path.isfile(os.path.join(path, CONFIG_NAME)):\n            config_file = os.path.join(path, CONFIG_NAME)\n        else:\n            try:\n                config_file = hf_hub_download(\n                    model_id, CONFIG_NAME, subfolder=subfolder, revision=revision, cache_dir=cache_dir\n                )\n            except Exception:\n                raise ValueError(f\"Can't find '{CONFIG_NAME}' at '{model_id}'\")\n\n        loaded_attributes = cls.from_json_file(config_file)\n        return loaded_attributes[\"peft_type\"]\n\n\n@dataclass\nclass PeftConfig(PeftConfigMixin):\n    \"\"\"\n    This is the base configuration class to store the configuration of a [`PeftModel`].\n\n    Args:\n        peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.\n        task_type (Union[[`~peft.utils.config.TaskType`], `str`]): The type of task to perform.\n        inference_mode (`bool`, defaults to `False`): Whether to use the Peft model in inference mode.\n    \"\"\"\n\n    base_model_name_or_path: str = field(default=None, metadata={\"help\": \"The name of the base model to use.\"})\n    revision: str = field(default=None, metadata={\"help\": \"The specific model version to use.\"})\n    peft_type: Union[str, PeftType] = field(default=None, metadata={\"help\": \"Peft type\"})\n    task_type: Union[str, TaskType] = field(default=None, metadata={\"help\": \"Task type\"})\n    inference_mode: bool = field(default=False, metadata={\"help\": \"Whether to use inference mode\"})\n\n\n@dataclass\nclass PromptLearningConfig(PeftConfig):\n    \"\"\"\n    This is the base configuration class to store the configuration of [`PrefixTuning`], [`PromptEncoder`], or\n    [`PromptTuning`].\n\n    Args:\n        num_virtual_tokens (`int`): The number of virtual tokens to use.\n        token_dim (`int`): The hidden embedding dimension of the base transformer model.\n        num_transformer_submodules (`int`): The number of transformer submodules in the base transformer model.\n        num_attention_heads (`int`): The number of attention heads in the base transformer model.\n        num_layers (`int`): The number of layers in the base transformer model.\n    \"\"\"\n\n    num_virtual_tokens: int = field(default=None, metadata={\"help\": \"Number of virtual tokens\"})\n    token_dim: int = field(\n        default=None, metadata={\"help\": \"The hidden embedding dimension of the base transformer model\"}\n    )\n    num_transformer_submodules: Optional[int] = field(\n        default=None, metadata={\"help\": \"Number of transformer submodules\"}\n    )\n    num_attention_heads: Optional[int] = field(default=None, metadata={\"help\": \"Number of attention heads\"})\n    num_layers: Optional[int] = field(default=None, metadata={\"help\": \"Number of transformer layers\"})\n", "path": "src/peft/utils/config.py"}], "after_files": [{"content": "# coding=utf-8\n# Copyright 2023-present the HuggingFace Inc. team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport enum\nimport inspect\nimport json\nimport os\nfrom dataclasses import asdict, dataclass, field\nfrom typing import Optional, Union\n\nfrom huggingface_hub import hf_hub_download\nfrom transformers.utils import PushToHubMixin\n\nfrom .other import CONFIG_NAME\n\n\nclass PeftType(str, enum.Enum):\n    PROMPT_TUNING = \"PROMPT_TUNING\"\n    P_TUNING = \"P_TUNING\"\n    PREFIX_TUNING = \"PREFIX_TUNING\"\n    LORA = \"LORA\"\n    ADALORA = \"ADALORA\"\n    ADAPTION_PROMPT = \"ADAPTION_PROMPT\"\n\n\nclass TaskType(str, enum.Enum):\n    SEQ_CLS = \"SEQ_CLS\"\n    SEQ_2_SEQ_LM = \"SEQ_2_SEQ_LM\"\n    CAUSAL_LM = \"CAUSAL_LM\"\n    TOKEN_CLS = \"TOKEN_CLS\"\n    QUESTION_ANS = \"QUESTION_ANS\"\n\n\n@dataclass\nclass PeftConfigMixin(PushToHubMixin):\n    r\"\"\"\n    This is the base configuration class for PEFT adapter models. It contains all the methods that are common to all\n    PEFT adapter models. This class inherits from [`~transformers.utils.PushToHubMixin`] which contains the methods to\n    push your model to the Hub. The method `save_pretrained` will save the configuration of your adapter model in a\n    directory. The method `from_pretrained` will load the configuration of your adapter model from a directory.\n\n    Args:\n        peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.\n    \"\"\"\n    peft_type: Optional[PeftType] = field(default=None, metadata={\"help\": \"The type of PEFT model.\"})\n\n    def to_dict(self):\n        return asdict(self)\n\n    def save_pretrained(self, save_directory, **kwargs):\n        r\"\"\"\n        This method saves the configuration of your adapter model in a directory.\n\n        Args:\n            save_directory (`str`):\n                The directory where the configuration will be saved.\n            kwargs (additional keyword arguments, *optional*):\n                Additional keyword arguments passed along to the [`~transformers.utils.PushToHubMixin.push_to_hub`]\n                method.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            raise AssertionError(f\"Provided path ({save_directory}) should be a directory, not a file\")\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        output_dict = asdict(self)\n        output_path = os.path.join(save_directory, CONFIG_NAME)\n\n        # save it\n        with open(output_path, \"w\") as writer:\n            writer.write(json.dumps(output_dict, indent=2, sort_keys=True))\n\n    @classmethod\n    def from_pretrained(cls, pretrained_model_name_or_path, subfolder=None, **kwargs):\n        r\"\"\"\n        This method loads the configuration of your adapter model from a directory.\n\n        Args:\n            pretrained_model_name_or_path (`str`):\n                The directory or the Hub repository id where the configuration is saved.\n            kwargs (additional keyword arguments, *optional*):\n                Additional keyword arguments passed along to the child class initialization.\n        \"\"\"\n        path = (\n            os.path.join(pretrained_model_name_or_path, subfolder)\n            if subfolder is not None\n            else pretrained_model_name_or_path\n        )\n\n        hf_hub_download_kwargs, class_kwargs, other_kwargs = cls._split_kwargs(kwargs)\n\n        if os.path.isfile(os.path.join(path, CONFIG_NAME)):\n            config_file = os.path.join(path, CONFIG_NAME)\n        else:\n            try:\n                config_file = hf_hub_download(\n                    pretrained_model_name_or_path, CONFIG_NAME, subfolder=subfolder, **hf_hub_download_kwargs\n                )\n            except Exception:\n                raise ValueError(f\"Can't find '{CONFIG_NAME}' at '{pretrained_model_name_or_path}'\")\n\n        loaded_attributes = cls.from_json_file(config_file)\n\n        config = cls(**class_kwargs)\n\n        for key, value in loaded_attributes.items():\n            if hasattr(config, key):\n                setattr(config, key, value)\n\n        return config\n\n    @classmethod\n    def from_json_file(cls, path_json_file, **kwargs):\n        r\"\"\"\n        Loads a configuration file from a json file.\n\n        Args:\n            path_json_file (`str`):\n                The path to the json file.\n        \"\"\"\n        with open(path_json_file, \"r\") as file:\n            json_object = json.load(file)\n\n        return json_object\n\n    @classmethod\n    def _split_kwargs(cls, kwargs):\n        hf_hub_download_kwargs = {}\n        class_kwargs = {}\n        other_kwargs = {}\n\n        for key, value in kwargs.items():\n            if key in inspect.signature(hf_hub_download).parameters:\n                hf_hub_download_kwargs[key] = value\n            elif key in list(cls.__annotations__):\n                class_kwargs[key] = value\n            else:\n                other_kwargs[key] = value\n\n        return hf_hub_download_kwargs, class_kwargs, other_kwargs\n\n    @classmethod\n    def _get_peft_type(\n        cls,\n        model_id,\n        subfolder: Optional[str] = None,\n        revision: Optional[str] = None,\n        cache_dir: Optional[str] = None,\n    ):\n        path = os.path.join(model_id, subfolder) if subfolder is not None else model_id\n\n        if os.path.isfile(os.path.join(path, CONFIG_NAME)):\n            config_file = os.path.join(path, CONFIG_NAME)\n        else:\n            try:\n                config_file = hf_hub_download(\n                    model_id, CONFIG_NAME, subfolder=subfolder, revision=revision, cache_dir=cache_dir\n                )\n            except Exception:\n                raise ValueError(f\"Can't find '{CONFIG_NAME}' at '{model_id}'\")\n\n        loaded_attributes = cls.from_json_file(config_file)\n        return loaded_attributes[\"peft_type\"]\n\n\n@dataclass\nclass PeftConfig(PeftConfigMixin):\n    \"\"\"\n    This is the base configuration class to store the configuration of a [`PeftModel`].\n\n    Args:\n        peft_type (Union[[`~peft.utils.config.PeftType`], `str`]): The type of Peft method to use.\n        task_type (Union[[`~peft.utils.config.TaskType`], `str`]): The type of task to perform.\n        inference_mode (`bool`, defaults to `False`): Whether to use the Peft model in inference mode.\n    \"\"\"\n\n    base_model_name_or_path: str = field(default=None, metadata={\"help\": \"The name of the base model to use.\"})\n    revision: str = field(default=None, metadata={\"help\": \"The specific model version to use.\"})\n    peft_type: Union[str, PeftType] = field(default=None, metadata={\"help\": \"Peft type\"})\n    task_type: Union[str, TaskType] = field(default=None, metadata={\"help\": \"Task type\"})\n    inference_mode: bool = field(default=False, metadata={\"help\": \"Whether to use inference mode\"})\n\n\n@dataclass\nclass PromptLearningConfig(PeftConfig):\n    \"\"\"\n    This is the base configuration class to store the configuration of [`PrefixTuning`], [`PromptEncoder`], or\n    [`PromptTuning`].\n\n    Args:\n        num_virtual_tokens (`int`): The number of virtual tokens to use.\n        token_dim (`int`): The hidden embedding dimension of the base transformer model.\n        num_transformer_submodules (`int`): The number of transformer submodules in the base transformer model.\n        num_attention_heads (`int`): The number of attention heads in the base transformer model.\n        num_layers (`int`): The number of layers in the base transformer model.\n    \"\"\"\n\n    num_virtual_tokens: int = field(default=None, metadata={\"help\": \"Number of virtual tokens\"})\n    token_dim: int = field(\n        default=None, metadata={\"help\": \"The hidden embedding dimension of the base transformer model\"}\n    )\n    num_transformer_submodules: Optional[int] = field(\n        default=None, metadata={\"help\": \"Number of transformer submodules\"}\n    )\n    num_attention_heads: Optional[int] = field(default=None, metadata={\"help\": \"Number of attention heads\"})\n    num_layers: Optional[int] = field(default=None, metadata={\"help\": \"Number of transformer layers\"})\n", "path": "src/peft/utils/config.py"}]}