MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / unscale_lora_layers

Function unscale_lora_layers

diffusers/src/diffusers/utils/peft_utils.py:123–147  ·  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: Optional[float] = None)

Source from the content-addressed store, hash-verified

121
122
123def unscale_lora_layers(model, weight: Optional[float] = None):
124 """
125 Removes the previously passed weight given to the LoRA layers of the model.
126
127 Args:
128 model (`torch.nn.Module`):
129 The model to scale.
130 weight (`float`, *optional*):
131 The weight to be given to the LoRA layers. If no scale is passed the scale of the lora layer will be
132 re-initialized to the correct value. If 0.0 is passed, we will re-initialize the scale with the correct
133 value.
134 """
135 from peft.tuners.tuners_utils import BaseTunerLayer
136
137 if weight == 1.0:
138 return
139
140 for module in model.modules():
141 if isinstance(module, BaseTunerLayer):
142 if weight is not None and weight != 0:
143 module.unscale_layer(weight)
144 elif weight is not None and weight == 0:
145 for adapter_name in module.active_adapters:
146 # if weight == 0 unscale should re-set the scale to the original value.
147 module.set_scale(adapter_name, 1.0)
148
149
150def get_peft_kwargs(rank_dict, network_alpha_dict, peft_state_dict, is_unet=True):

Callers 15

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
encode_promptMethod · 0.90
encode_promptMethod · 0.90
encode_promptMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected