MCPcopy Index your code
hub / github.com/huggingface/diffusers / unscale_lora_layers

Function unscale_lora_layers

src/diffusers/utils/peft_utils.py:126–150  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

124
125
126def 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
153def get_peft_kwargs(

Callers 15

encode_promptMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90
_encode_promptMethod · 0.90
forwardMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…