Skip to content

Use torch.svd_lowrank for large matrices in resize_lora.py#2240

Merged
kohya-ss merged 1 commit intokohya-ss:sd3from
woct0rdho:svd-lowrank
Mar 29, 2026
Merged

Use torch.svd_lowrank for large matrices in resize_lora.py#2240
kohya-ss merged 1 commit intokohya-ss:sd3from
woct0rdho:svd-lowrank

Conversation

@woct0rdho
Copy link
Copy Markdown
Contributor

@woct0rdho woct0rdho commented Nov 17, 2025

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)

@kohya-ss
Copy link
Copy Markdown
Owner

Thank you, this is really nice! I'd like to merge this sooner. I'm a little busy so please wait a moment.

@kohya-ss kohya-ss changed the base branch from main to sd3 March 29, 2026 10:54
@kohya-ss kohya-ss merged commit 2723a75 into kohya-ss:sd3 Mar 29, 2026
1 check passed
@kohya-ss
Copy link
Copy Markdown
Owner

Thank you for this!

@woct0rdho woct0rdho deleted the svd-lowrank branch March 29, 2026 10:57
kohya-ss added a commit that referenced this pull request Mar 29, 2026
Allow users to control the number of iterations for torch.svd_lowrank
on large matrices. Default is 2 (matching PR #2240 behavior). Set to 0
to disable svd_lowrank and use full SVD instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kohya-ss
Copy link
Copy Markdown
Owner

I've added an option --svd_lowrank_niter to control niter param and disable svd_lowrank at #2296.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants