You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
LoRA is consuming extra GPU power that is not required in inference. This can cause a noticable amount of overhead especially with high resolutions. For higher LoRA ranks (64/128), this can be up to 30%-50% performance gain.
Describe the solution you'd like
A bake_lora_weights function on UNet models (or any model that supports attention processor).
Uses can decide whether they want to keep swapping LoRA weights available or to bake weights to reduce inference overhead.
Proof of Concept:
@torch.no_grad()defbake_lora_weights(self):
defexpansion(lora: LoRALinearLayer):
# in x in -> in x outeye=torch.eye(lora.down.weight.size(1))
eye=eye.to(lora.down.weight)
returnlora(eye).Tdeftraverse(name: str, module: Attention):
ifhasattr(module, "set_processor"):
assertisinstance(module.processor, (LoRAAttnProcessor, LoRAAttnProcessor2_0, LoRAXFormersAttnProcessor))
module.to_k.weight+=expansion(module.processor.to_k_lora)
module.to_v.weight+=expansion(module.processor.to_v_lora)
module.to_q.weight+=expansion(module.processor.to_q_lora)
module.to_out[0].weight+=expansion(module.processor.to_out_lora)
forsub_name, childinmodule.named_children():
traverse(f"{name}.{sub_name}", child)
forname, moduleinself.named_children():
traverse(name, module)
iftorch.__version__>='2.0':
self.unet.set_attn_processor(AttnProcessor2_0())
elifis_xformers_available():
self.unet.set_attn_processor(XFormersAttnProcessor())
else:
self.unet.set_attn_processor(AttnProcessor())
Activity
apolinario commentedon Aug 17, 2023
Check this PR out :-)
#4473
eliphatfs commentedon Aug 17, 2023
Sorry for duplication. I only searched for issues and did not search for PRs. Thanks for sharing that pointer.