Skip to content

Load LoRA with uneven Rank #7954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mutatedducks97
Copy link

@mutatedducks97 mutatedducks97 commented Apr 24, 2025

Summary

Internally invoke makes use of CustomLinear module to inject LoRA into but does not support fused weights from uneven rank from up and down matrices. In this PR we create a fused matrix to address this issue. Since huggingface diffusers implements FLUX using a fused kqv The rank of the LoRA generated from a diffuser FLUX model will be different.

Before this PR the following issues would occur. This resolves it.

  1. For QKV attention layers (img_attn and txt_atn):
    • CustomLinear(in_features=3072, out_features=9216)
    • LoRA matrices: down=[12, 3072], up=[9216, 4]
    • The error shows: cannot multiply (9216x4) with (12x3072)
    • We need it to output a matrix with shape (9216, 3072)
  • New shape:torch.Size([9216, 3072])
  1. For linear1 layers:
    • CustomLinear(in_features=3072, out_features=21504)
    • LoRA matrices: down=[16, 3072], up=[21504, 4]
    • The error shows: cannot multiply (21504x4) with (16x3072)
    • We need it to output a matrix with shape (21504, 3072)

Default Flux

image

50 steps training

image

350 steps training Flux

image

Related Issues / Discussions

QA Instructions

Merge Plan

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added python PRs that change python files backend PRs that change backend files labels Apr 24, 2025
@mutatedducks97 mutatedducks97 marked this pull request as draft April 24, 2025 22:11
@mutatedducks97 mutatedducks97 marked this pull request as ready for review April 25, 2025 11:46
@mutatedducks97 mutatedducks97 changed the title Sam/model load Load LoRA with uneven Rank Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend PRs that change backend files python PRs that change python files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant