ENH: Improve speed of function expanding LoRA scales by BenjaminBossan · Pull Request #11834 · huggingface/diffusers (original) (raw)

What does this PR do?

Resolves #11816

The following call proved to be a bottleneck when setting a lot of LoRA adapters in diffusers:

weights = scale_expansion_fn(self, weights)

This is because we would repeatedly call unet.state_dict(), even though in the standard case, it is not necessary:

This PR fixes this by deferring this call, so that it is only run when it's necessary, not earlier.

Note: This PR doesn't change the fact that set_adapters becomes slower the more adapters are already loaded, but since it speeds up the whole process by a factor of approximately 10x, set_adapters is much less of a bottleneck.

Before submitting