MCPcopy
hub / github.com/huggingface/transformers / update_fsdp_plugin_peft

Function update_fsdp_plugin_peft

src/transformers/integrations/fsdp.py:73–92  ·  view source on GitHub ↗

Updates the FSDP plugin for PEFT LoRA/QLoRA compatibility. When using FSDP with PEFT LoRA, the auto wrap policy needs to be updated to additionally wrap LoRA trainable layers separately. When using FSDP with QLoRA, the mixed precision policy needs to be updated to use the quantizat

(model, accelerator)

Source from the content-addressed store, hash-verified

71
72
73def update_fsdp_plugin_peft(model, accelerator):
74 """
75 Updates the FSDP plugin for PEFT LoRA/QLoRA compatibility.
76
77 When using FSDP with PEFT LoRA, the auto wrap policy needs to be updated to additionally wrap
78 LoRA trainable layers separately. When using FSDP with QLoRA, the mixed precision policy needs
79 to be updated to use the quantization storage data type.
80 """
81 from peft import PeftConfig
82 from peft.utils.other import fsdp_auto_wrap_policy
83
84 if isinstance(model.active_peft_config, PeftConfig):
85 accelerator.state.fsdp_plugin.auto_wrap_policy = fsdp_auto_wrap_policy(model)
86 if (
87 getattr(model, "quantization_method", None) == QuantizationMethod.BITS_AND_BYTES
88 and model.hf_quantizer.quantization_config.bnb_4bit_quant_storage.is_floating_point
89 ):
90 accelerator.state.fsdp_plugin.set_mixed_precision(
91 model.hf_quantizer.quantization_config.bnb_4bit_quant_storage, override=True
92 )

Callers 1

_prepare_for_trainingMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected