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

Parse LoRA from prompt #198

Merged
merged 12 commits into from
Dec 10, 2023
Merged

Parse LoRA from prompt #198

merged 12 commits into from
Dec 10, 2023

Conversation

Danamir
Copy link
Contributor

@Danamir Danamir commented Dec 8, 2023

This adds the capacity to parse LoRA directly from the prompt, using the Auto1111 webui syntax : <lora:name:strength>.

The lora name is searched in all the available lora models in the ComfyUI installation, by case insensitive filename only. No path, no extension, to keep the prompt light.

The strength is optional, replaced by 1.0 if absent.

Once applied the whole <lora*> is removed from the prompt before applying the conditioning.

For example the prompt photography of a bird <lora:add-detail-xl:1.0> auto loads the matching LoRA LoRA\5. SDXL\Style\Add-detail-XL.safetensors found on my installation :

image

If the LoRA is not found in the available models, an error is returned :

image

Same concept if an invalid strength is given :

image

I find it more responsive to display the error directly in the krita interface, but it could be replaced by a log line only in client.log

@Danamir
Copy link
Contributor Author

Danamir commented Dec 8, 2023

The lint check outputs :
image

But I'm not sure what lines needs to be reformatted. I tried to apply an auto format in IntelliJ IDEA, but many lines are impacted, some not concerned by this PR.

Any idea ?

[edit] : I read the lint output too quickly, it suggests the modifications to be done.

Copy link
Owner

@Acly Acly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice to have functionality wise, I like the error handling too.

Question: since comfy uses embedding:file syntax for embeddings, does it make sense to support lora:file? It's a bit leaner, but doesn't work for filenames that contain spaces I guess.

Requests:

  • Since prompt weight/strength can now be changed with Ctrl+Up/Down, it would be nice to have this for LoRA. From a user perspective I would kind of expect it to work. Maybe it's enough to add support for <> back in, or the extra colon needs to be handled.
  • Please write a test for parse_lora (you may want to take a lora list as argument rather than Client)

ai_diffusion/workflow.py Outdated Show resolved Hide resolved
ai_diffusion/workflow.py Outdated Show resolved Hide resolved
ai_diffusion/workflow.py Outdated Show resolved Hide resolved
ai_diffusion/workflow.py Outdated Show resolved Hide resolved
@Danamir
Copy link
Contributor Author

Danamir commented Dec 10, 2023

Question: since comfy uses embedding:file syntax for embeddings, does it make sense to support lora:file? It's a bit leaner, but doesn't work for filenames that contain spaces I guess.

There is the problem with LoRA names allowing spaces, and the attention edit on Ctrl+up/down which relies entirely on delimiters. (cf. below).

Since prompt weight/strength can now be changed with Ctrl+Up/Down, it would be nice to have this for LoRA. From a user perspective I would kind of expect it to work. Maybe it's enough to add support for <> back in, or the extra colon needs to be handled.

Done. I set the lower bound to -2.0 to allow negative LoRA strengths, and patched the parser to allow strength 1.0 to be displayed for <> delimiters.

Please write a test for parse_lora (you may want to take a lora list as argument rather than Client)

Done.

@Acly
Copy link
Owner

Acly commented Dec 10, 2023

Thanks! works very smoothly now

@Acly Acly merged commit 4bcea66 into Acly:main Dec 10, 2023
2 checks passed
@peterpernhofer
Copy link

peterpernhofer commented Mar 3, 2024

Sorry to say. But in Krita-Plugin version 1.14.1 it seems. that this (very very useful) feature is missing again.
Loras are not parsed from prompt. I have to add them manually in the connection dialog settings every time, I want to use a lora

@Danamir
Copy link
Contributor Author

Danamir commented Mar 3, 2024

It's still working for me : tested with a prompt "a bird on a branch lora:add-detail-xl:1.0" and the option to dump the workflow I checked that the LoRA is correctly affecting the output :

image

Can you see if the dumped workflow is working (it can be found in %APPDATA%\krita\ai_diffusion\logs) ? Also check the logs to see if there is a name resolution error ?

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.

3 participants