-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fuse loras #4473
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
Merged
Merged
Fuse loras #4473
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
ad0ca34
Fuse loras
patrickvonplaten 697a6a7
initial implementation.
sayakpaul 957f36e
merge into main
sayakpaul 703e9aa
add slow test one.
sayakpaul f9a7737
styling
sayakpaul 15b7652
add: test for checking efficiency
sayakpaul b4a9a44
print
sayakpaul a6d6402
position
sayakpaul a167a74
place model offload correctly
sayakpaul 14aa423
style
sayakpaul 16311f7
style.
sayakpaul a355544
unfuse test.
sayakpaul d8050b5
final checks
sayakpaul 96ae69e
Merge branch 'main' into fuse_loras
patrickvonplaten fddc586
resolve conflicts.
sayakpaul a976466
remove warning test
sayakpaul b718922
remove warnings altogether
sayakpaul 886993e
Merge branch 'main' into fuse_loras
sayakpaul 782367d
debugging
sayakpaul 84f63e8
tighten up tests.
sayakpaul 4a2e6c4
debugging
sayakpaul 1b07e43
debugging
sayakpaul 0d69dde
debugging
sayakpaul caa79ed
debugging
sayakpaul 345057d
debugging
sayakpaul f26a62a
debugging
sayakpaul bc2282c
debugging
sayakpaul ced2a90
debugging
sayakpaul ff78a58
debugging
sayakpaul 036a9bc
denugging
sayakpaul 1c6970f
debugging
sayakpaul 9f7492f
debugging
sayakpaul 975adf7
debugging
sayakpaul 0abf6fe
debugging
sayakpaul de916c6
debugging
sayakpaul e87e5dd
debugging
sayakpaul e376b58
debugging
sayakpaul 21f17b0
debugging
sayakpaul 5537305
debugging
sayakpaul 73c07ee
debugging
sayakpaul dc30b9d
debugging
sayakpaul 96c70e8
debugging
sayakpaul c5f37b5
debugging
sayakpaul 854231b
debugging
sayakpaul b00899e
debuging
sayakpaul 788b610
debugging
sayakpaul aedcb70
debugging
sayakpaul 67b8aa6
debugging
sayakpaul 1c69333
suit up the generator initialization a bit.
sayakpaul 55f5958
remove print
sayakpaul 73bdcb1
update assertion.
sayakpaul 940ed1b
debugging
sayakpaul 8fcd42a
remove print.
sayakpaul 6e99561
fix: assertions.
sayakpaul c3adb8c
style
sayakpaul 2d6cd03
can generator be a problem?
sayakpaul 53f2e74
generator
sayakpaul b9ea1fc
correct tests.
sayakpaul 9cb8ec3
support text encoder lora fusion.
sayakpaul 50c611d
tighten up tests.
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the reason
unfuse
gives different results might be because we don't do the computation in full fp32 precision here. In the_fuse_lora
function we do the computation in full fp32 precision, but here we don't I think. Can we try to make sure that:is always computed in full fp32 precision and only then we lower it potentially to fp16 dtype?
Guess we could also easily check this by casting the whole model to fp32 before doing fuse and unfuse to check cc @apolinario
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good hypothesis but would this explain the behaviour of this happening in some LoRAs but not others, and keeping some residual style?
davizca87/vulcan
→ different image after unloadingostris/crayon_style_lora_sdxl
→ same image after unloadingdavizca87/sun-flower
→ different image after unloading (and also different than the image unlaoded in 1)TheLastBen/Papercut_SDXL
→ same image after unloadingUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed cases ❌
davizca87/sun-flower
seems to keep some of the sunflower vibe in the backgrounddavizca87/vulcan
seems to keep some of the vulcan style in the outlines of the robotSuccess cases ✅
ostris/crayon_style_lora_sdxl
seems to produce a perceptually identical image after unfusingTheLastBen/Papercut_SDXL
andnerijs/pixel-art-xl
also exhibit the same correct behaviorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally always worry about how numerical precision stems through a network and affect the end results. Have seen enough cases because of this to not sleep well at night. So, I will start with what @patrickvonplaten suggested.
FWIW, though, there's actually a fast test that ensures the following trip doesn't have side-effects:
load_lora_weights() -> fuse_lora() -> unload_lora_weights()
gives you the outputs you would expect after doingfuse_lora()
.Let me know if anything is unclear.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I guess an analogous test could be made to address what I reported for a future PR
Namely asserting that the two
generate with no LoRA
are matching:generate with no LoRA before unfusing
→load_lora_weights()
→fuse_lora()
→unfuse_lora()
→generate with no LoRA after unfusing
This is the workflow I've reported above, the unfused unet seemingly still contains somewhat of a residue of the lora
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in: #4833 . Was a tricky issue that was caused by the patched text encoder LoRA layers being fully removed when doing
unload_lora
and therefore loosing their ability to unfuse. Hope it was ok to help out a bit here @sayakpaulThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had started
fuse-lora-pt2
and mentioned in Slack that I am looking into it. But okay.