Use torch.svd_lowrank for large matrices in resize_lora.py by woct0rdho · Pull Request #2240 · kohya-ss/sd-scripts (original) (raw)

This hugely reduces the time to prune a LoRA, without visible quality loss compared to the full SVD. The time is reduced from 3 hours (Wan) and 1 hour (Qwen-Image) to a few seconds on my laptop.

See https://docs.pytorch.org/docs/stable/generated/torch.svd_lowrank.html for details. Maybe we can increase niter for even better quality but I think the default niter=2 already gives good enough quality. Kijai's LoraExtractKJ node uses niter=7 by default, see https://github.com/kijai/ComfyUI-KJNodes/blob/bb205d809b467307b8ec3bb1a22680a4873187f8/nodes/lora_nodes.py#L30 (but they don't yet do adaptive rank after svd_lowrank)