Buckets:
| # PEFT[[transformers.integrations.PeftAdapterMixin]] | |
| The [PeftAdapterMixin](/docs/transformers/pr_33892/en/main_classes/peft#transformers.integrations.PeftAdapterMixin) provides functions from the [PEFT](https://huggingface.co/docs/peft/index) library for managing adapters with Transformers. This mixin currently supports LoRA, IA3, and AdaLora. Prefix tuning methods (prompt tuning, prompt learning) aren't supported because they can't be injected into a torch module. | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>class transformers.integrations.PeftAdapterMixin</name><anchor>transformers.integrations.PeftAdapterMixin</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L72</source><parameters>[]</parameters></docstring> | |
| A class containing all functions for loading and using adapters weights that are supported in PEFT library. For | |
| more details about adapters and injecting them on a transformer-based model, check out the documentation of PEFT | |
| library: https://huggingface.co/docs/peft/index | |
| Currently supported PEFT methods are all non-prompt learning methods (LoRA, IA³, etc.). Other PEFT models such as | |
| prompt tuning, prompt learning are out of scope as these adapters are not "injectable" into a torch module. For | |
| using these methods, please refer to the usage guide of PEFT library. | |
| With this mixin, if the correct PEFT version is installed, it is possible to: | |
| - Load an adapter stored on a local path or in a remote Hub repository, and inject it in the model | |
| - Attach new adapters in the model and train them with Trainer or by your own. | |
| - Attach multiple adapters and iteratively activate / deactivate them | |
| - Activate / deactivate all adapters from the model. | |
| - Get the `state_dict` of the active adapter. | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>load_adapter</name><anchor>transformers.integrations.PeftAdapterMixin.load_adapter</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L93</source><parameters>[{"name": "peft_model_id", "val": ": typing.Optional[str] = None"}, {"name": "adapter_name", "val": ": typing.Optional[str] = None"}, {"name": "revision", "val": ": typing.Optional[str] = None"}, {"name": "token", "val": ": typing.Optional[str] = None"}, {"name": "device_map", "val": ": str = 'auto'"}, {"name": "max_memory", "val": ": typing.Optional[str] = None"}, {"name": "offload_folder", "val": ": typing.Optional[str] = None"}, {"name": "offload_index", "val": ": typing.Optional[int] = None"}, {"name": "peft_config", "val": ": typing.Optional[dict[str, typing.Any]] = None"}, {"name": "adapter_state_dict", "val": ": typing.Optional[dict[str, 'torch.Tensor']] = None"}, {"name": "low_cpu_mem_usage", "val": ": bool = False"}, {"name": "is_trainable", "val": ": bool = False"}, {"name": "adapter_kwargs", "val": ": typing.Optional[dict[str, typing.Any]] = None"}]</parameters><paramsdesc>- **peft_model_id** (`str`, *optional*) -- | |
| The identifier of the model to look for on the Hub, or a local path to the saved adapter config file | |
| and adapter weights. | |
| - **adapter_name** (`str`, *optional*) -- | |
| The adapter name to use. If not set, will use the name "default". | |
| - **revision** (`str`, *optional*, defaults to `"main"`) -- | |
| The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a | |
| git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any | |
| identifier allowed by git. | |
| > [!TIP] | |
| > To test a pull request you made on the Hub, you can pass `revision="refs/pr/<pr_number>"`. | |
| - **token** (`str`, `optional`) -- | |
| Whether to use authentication token to load the remote folder. Useful to load private repositories | |
| that are on HuggingFace Hub. You might need to call `hf auth login` and paste your tokens to | |
| cache it. | |
| - **device_map** (`str` or `dict[str, Union[int, str, torch.device]]` or `int` or `torch.device`, *optional*) -- | |
| A map that specifies where each submodule should go. It doesn't need to be refined to each | |
| parameter/buffer name, once a given module name is inside, every submodule of it will be sent to the | |
| same device. If we only pass the device (*e.g.*, `"cpu"`, `"cuda:1"`, `"mps"`, or a GPU ordinal rank | |
| like `1`) on which the model will be allocated, the device map will map the entire model to this | |
| device. Passing `device_map = 0` means put the whole model on GPU 0. | |
| To have Accelerate compute the most optimized `device_map` automatically, set `device_map="auto"`. For | |
| more information about each option see [designing a device | |
| map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map). | |
| - **max_memory** (`Dict`, *optional*) -- | |
| A dictionary device identifier to maximum memory. Will default to the maximum memory available for each | |
| GPU and the available CPU RAM if unset. | |
| - **offload_folder** (`str` or `os.PathLike`, `optional`) -- | |
| If the `device_map` contains any value `"disk"`, the folder where we will offload weights. | |
| - **offload_index** (`int`, `optional`) -- | |
| `offload_index` argument to be passed to `accelerate.dispatch_model` method. | |
| - **peft_config** (`dict[str, Any]`, *optional*) -- | |
| The configuration of the adapter to add, supported adapters are all non-prompt learning configs (LoRA, | |
| IA³, etc). This argument is used in case users directly pass PEFT state dicts. | |
| - **adapter_state_dict** (`dict[str, torch.Tensor]`, *optional*) -- | |
| The state dict of the adapter to load. This argument is used in case users directly pass PEFT state | |
| dicts. | |
| - **low_cpu_mem_usage** (`bool`, *optional*, defaults to `False`) -- | |
| Reduce memory usage while loading the PEFT adapter. This should also speed up the loading process. | |
| Requires PEFT version 0.13.0 or higher. | |
| - **is_trainable** (`bool`, *optional*, defaults to `False`) -- | |
| Whether the adapter should be trainable or not. If `False`, the adapter will be frozen and can only be | |
| used for inference. | |
| - **adapter_kwargs** (`dict[str, Any]`, *optional*) -- | |
| Additional keyword arguments passed along to the `from_pretrained` method of the adapter config and | |
| `find_adapter_config_file` method.</paramsdesc><paramgroups>0</paramgroups></docstring> | |
| Load adapter weights from file or remote Hub folder. If you are not familiar with adapters and PEFT methods, we | |
| invite you to read more about them on PEFT official documentation: https://huggingface.co/docs/peft | |
| Requires PEFT to be installed as a backend to load the adapter weights. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>add_adapter</name><anchor>transformers.integrations.PeftAdapterMixin.add_adapter</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L311</source><parameters>[{"name": "adapter_config", "val": ""}, {"name": "adapter_name", "val": ": typing.Optional[str] = None"}]</parameters><paramsdesc>- **adapter_config** (`~peft.PeftConfig`) -- | |
| The configuration of the adapter to add, supported adapters are non-prompt learning methods (LoRA, | |
| IA³, etc.). | |
| - **adapter_name** (`str`, *optional*, defaults to `"default"`) -- | |
| The name of the adapter to add. If no name is passed, a default name is assigned to the adapter.</paramsdesc><paramgroups>0</paramgroups></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Adds a fresh new adapter to the current model for training purpose. If no adapter name is passed, a default | |
| name is assigned to the adapter to follow the convention of PEFT library (in PEFT we use "default" as the | |
| default adapter name). | |
| Note that the newly added adapter is not automatically activated. To activate it, use `model.set_adapter`. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>set_adapter</name><anchor>transformers.integrations.PeftAdapterMixin.set_adapter</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L350</source><parameters>[{"name": "adapter_name", "val": ": typing.Union[list[str], str]"}]</parameters><paramsdesc>- **adapter_name** (`Union[list[str], str]`) -- | |
| The name of the adapter to set. Can be also a list of strings to set multiple adapters.</paramsdesc><paramgroups>0</paramgroups></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Sets a specific adapter by forcing the model to use a that adapter and disable the other adapters. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>disable_adapters</name><anchor>transformers.integrations.PeftAdapterMixin.disable_adapters</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L395</source><parameters>[]</parameters></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Disable all adapters that are attached to the model. This leads to inferring with the base model only. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>enable_adapters</name><anchor>transformers.integrations.PeftAdapterMixin.enable_adapters</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L418</source><parameters>[]</parameters></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Enable adapters that are attached to the model. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>active_adapters</name><anchor>transformers.integrations.PeftAdapterMixin.active_adapters</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L440</source><parameters>[]</parameters></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Gets the current active adapters of the model. In case of multi-adapter inference (combining multiple adapters | |
| for inference) returns the list of all active adapters so that users can deal with them accordingly. | |
| For previous PEFT versions (that does not support multi-adapter inference), `module.active_adapter` will return | |
| a single string. | |
| </div> | |
| <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"> | |
| <docstring><name>get_adapter_state_dict</name><anchor>transformers.integrations.PeftAdapterMixin.get_adapter_state_dict</anchor><source>https://github.com/huggingface/transformers/blob/vr_33892/src/transformers/integrations/peft.py#L472</source><parameters>[{"name": "adapter_name", "val": ": typing.Optional[str] = None"}, {"name": "state_dict", "val": ": typing.Optional[dict] = None"}]</parameters><paramsdesc>- **adapter_name** (`str`, *optional*) -- | |
| The name of the adapter to get the state dict from. If no name is passed, the active adapter is used. | |
| - **state_dict** (nested dictionary of `torch.Tensor`, *optional*) -- | |
| The state dictionary of the model. Will default to `self.state_dict()`, but can be used if special | |
| precautions need to be taken when recovering the state dictionary of a model (like when using model | |
| parallelism).</paramsdesc><paramgroups>0</paramgroups></docstring> | |
| If you are not familiar with adapters and PEFT methods, we invite you to read more about them on the PEFT | |
| official documentation: https://huggingface.co/docs/peft | |
| Gets the adapter state dict that should only contain the weights tensors of the specified adapter_name adapter. | |
| If no adapter_name is passed, the active adapter is used. | |
| </div></div> | |
| <EditOnGithub source="https://github.com/huggingface/transformers/blob/main/docs/source/en/main_classes/peft.md" /> |
Xet Storage Details
- Size:
- 12.6 kB
- Xet hash:
- 4c66737c11ca5c122bc61a513f51eb7d1be9fa0ba5b5ddefc69fc214b1719b78
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.