mirror of
https://github.com/huggingface/peft.git
synced 2025-10-20 23:43:47 +08:00
Deduplicate a lot of redundant code from PEFT method's model.py: merge_and_unload unload delete_adapter set_adapter enable_adapter_layers disable_adapter_layers _replace_module _unload_and_optionally_merge _mark_only_adapters_as_trainable _check_new_adapter_config _check_target_module_exists _prepare_adapter_config __getattr__ get_peft_config_as_dict (fully deleted) Related changes: A new module, functional.py, is introduced, which contains functions (just reimported from elsewhere) that can be useful for libraries that want to integrate PEFT. I would suggest that we should treat them as public API and thus guarantee backwards compatibility. I also deduplicated almost identical TRANSFORMERS_MODULES_TO_XXX_TARGET_MODULES_MAPPING constants by copying them from LoRA and only overriding a few values that differ. Moreover, some PEFT methods didn't have their own TRANSFORMERS_MODULES_TO_XXX_TARGET_MODULES_MAPPING but used the one from LoRA instead. They now each have their own constant, which is a copy from the one from LoRA.
1.0 KiB
1.0 KiB
Functions for PEFT integration
A collection of functions that could be useful for non-PeftModel models, e.g. transformers or diffusers integration
The functions provided here can be considered "public API" of PEFT and hence are safe to be used by packages that provide PEFT integrations.
Cast the adapter weight dtypes
autodoc functional.cast_adapter_dtype - all
Delete the PEFT adapter from model
autodoc functional.delete_adapter - all
Get the state dict of the PEFT adapter
autodoc functional.get_peft_model_state_dict - all
Inject a PEFT adapter into the model based on a PEFT config
autodoc functional.inject_adapter_in_model - all
Set the active PEFT adapter(s) of the model
autodoc functional.set_adapter - all
Load the weights of the PEFT state dict into the model
autodoc functional.set_peft_model_state_dict - all