Removes the previously passed weight given to the LoRA layers of the model. Args: model (`torch.nn.Module`): The model to scale. weight (`float`, *optional*): The weight to be given to the LoRA layers. If no scale is passed the scale of the lora laye
(model, weight: float | None = None)
| 124 | |
| 125 | |
| 126 | def unscale_lora_layers(model, weight: float | None = None): |
| 127 | """ |
| 128 | Removes the previously passed weight given to the LoRA layers of the model. |
| 129 | |
| 130 | Args: |
| 131 | model (`torch.nn.Module`): |
| 132 | The model to scale. |
| 133 | weight (`float`, *optional*): |
| 134 | The weight to be given to the LoRA layers. If no scale is passed the scale of the lora layer will be |
| 135 | re-initialized to the correct value. If 0.0 is passed, we will re-initialize the scale with the correct |
| 136 | value. |
| 137 | """ |
| 138 | from peft.tuners.tuners_utils import BaseTunerLayer |
| 139 | |
| 140 | if weight is None or weight == 1.0: |
| 141 | return |
| 142 | |
| 143 | for module in model.modules(): |
| 144 | if isinstance(module, BaseTunerLayer): |
| 145 | if weight != 0: |
| 146 | module.unscale_layer(weight) |
| 147 | else: |
| 148 | for adapter_name in module.active_adapters: |
| 149 | # if weight == 0 unscale should re-set the scale to the original value. |
| 150 | module.set_scale(adapter_name, 1.0) |
| 151 | |
| 152 | |
| 153 | def get_peft_kwargs( |
no outgoing calls
no test coverage detected
searching dependent graphs…