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)
| 101 | |
| 102 | |
| 103 | def scale_lora_layers(model, weight): |
| 104 | """ |
| 105 | Adjust the weightage given to the LoRA layers of the model. |
| 106 | |
| 107 | Args: |
| 108 | model (`torch.nn.Module`): |
| 109 | The model to scale. |
| 110 | weight (`float`): |
| 111 | The weight to be given to the LoRA layers. |
| 112 | """ |
| 113 | from peft.tuners.tuners_utils import BaseTunerLayer |
| 114 | |
| 115 | if weight == 1.0: |
| 116 | return |
| 117 | |
| 118 | for module in model.modules(): |
| 119 | if isinstance(module, BaseTunerLayer): |
| 120 | module.scale_layer(weight) |
| 121 | |
| 122 | |
| 123 | def unscale_lora_layers(model, weight: Optional[float] = None): |
no outgoing calls
no test coverage detected