Skip to content
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

FLUX LoRA Support #6847

Merged
merged 49 commits into from
Sep 18, 2024
Merged

FLUX LoRA Support #6847

merged 49 commits into from
Sep 18, 2024

Conversation

RyanJDick
Copy link
Collaborator

@RyanJDick RyanJDick commented Sep 12, 2024

Summary

This PR adds support for FLUX LoRA models on both quantized and non-quantized base models.

Supported formats:

  • diffusers
  • kohya

Full changelist:

  • Consolidated LoRA handling code in invokeai/backend/lora
  • Add support for FLUX kohya and FLUX diffusers LoRA model loading
  • Add ability to either patch LoRAs or run as a sidecar model (the latter enables LoRAs to be applied to a wide range of quantized models).

QA Instructions

Note to reviewers: I tested everything in this checklist. Feel free to re-verify any of this, but also test any LoRAs that you have. There are many small LoRA format variations, and there's a risk of breaking one of them with this change.

FLUX LoRA

Regression Tests

  • SD1.5 LoRA (check output, speed and memory)
  • SDXL LoRA (check output, speed and memory)
  • USE_MODULAR_DENOISE=1 smoke test with LoRA

Test for output regression with the following LoRA formats:

  • LoRA
  • LoHA
  • LoKr
  • IA3

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)

@github-actions github-actions bot added python PRs that change python files invocations PRs that change invocations backend PRs that change backend files python-tests PRs that change python tests labels Sep 12, 2024
@RyanJDick RyanJDick force-pushed the ryan/flux-lora-quantized branch 2 times, most recently from 9c2f173 to c3aa092 Compare September 13, 2024 15:25
@RyanJDick RyanJDick marked this pull request as ready for review September 13, 2024 18:35
@RyanJDick
Copy link
Collaborator Author

Note to reviewers: Please test any LoRAs that you have (SD or FLUX). There are many small LoRA format variations, and there's a risk of breaking one of them with this change.

@bghira
Copy link

bghira commented Sep 14, 2024

i don't see how alpha=8 would work for any peft loras that aren't also rank=8

@bghira
Copy link

bghira commented Sep 15, 2024

if you're going for lycoris support note that the support for this in peft is very lacking currently, with an open issue for community help request on updating the various modules

it's very easy to wrap the upstream lycoris library modules though, as @KohakuBlueleaf has added a functional API for this use case. it just wraps the Diffusers model and has .apply_to() and .merge_to() for sidecar or fused running

there's built in methods for extracting models and playing with them in other ways. i'd highly recommend switching from peft for lycoris stuff.

@KohakuBlueleaf
Copy link

it's very easy to wrap the upstream lycoris library modules though, as @KohakuBlueleaf has added a functional API for this use case. it just wraps the Diffusers model and has .apply_to() and .merge_to() for sidecar or fused running

.apply_to() is module API. Functional API is something designed for library to implement their own low-level wrapper.
(For example, lokr_output = layer(x) + lokr_bypass_forward(x, w1, w2a, w2b ...))

@RyanJDick
Copy link
Collaborator Author

if you're going for lycoris support note that the support for this in peft is very lacking currently, with an open issue for community help request on updating the various modules

it's very easy to wrap the upstream lycoris library modules though, as @KohakuBlueleaf has added a functional API for this use case. it just wraps the Diffusers model and has .apply_to() and .merge_to() for sidecar or fused running

there's built in methods for extracting models and playing with them in other ways. i'd highly recommend switching from peft for lycoris stuff.

Thanks for this context. We explored using PEFT at one point, but decided against using it because it didn't meet our requirements for high patching/unpatching speeds.

I'll leave the integration of the upstream lycoris lib for future work. For now, we have our own implementation of the lycoris layers for fused execution, and partial support for sidecar execution (and easy to extend).

@bghira
Copy link

bghira commented Sep 16, 2024

i agree that the patching speed of diffusers could be improved. if you have any observations/suggestions please open an issue report

@RyanJDick RyanJDick merged commit d6da2aa into main Sep 18, 2024
14 checks passed
@RyanJDick RyanJDick deleted the ryan/flux-lora-quantized branch September 18, 2024 17:49
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 invocations PRs that change invocations python PRs that change python files python-tests PRs that change python tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants