Adjust the weightage given to the LoRA layers of the model. Args: model (`torch.nn.Module`): The model to scale. weight (`float`): The weight to be given to the LoRA layers.
(model, weight)
| 104 | |
| 105 | |
| 106 | def scale_lora_layers(model, weight): |
| 107 | """ |
| 108 | Adjust the weightage given to the LoRA layers of the model. |
| 109 | |
| 110 | Args: |
| 111 | model (`torch.nn.Module`): |
| 112 | The model to scale. |
| 113 | weight (`float`): |
| 114 | The weight to be given to the LoRA layers. |
| 115 | """ |
| 116 | from peft.tuners.tuners_utils import BaseTunerLayer |
| 117 | |
| 118 | if weight == 1.0: |
| 119 | return |
| 120 | |
| 121 | for module in model.modules(): |
| 122 | if isinstance(module, BaseTunerLayer): |
| 123 | module.scale_layer(weight) |
| 124 | |
| 125 | |
| 126 | def unscale_lora_layers(model, weight: float | None = None): |
no outgoing calls
no test coverage detected
searching dependent graphs…