-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[docs] Load A1111 LoRA #3629
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
[docs] Load A1111 LoRA #3629
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,4 +123,69 @@ pipeline.to("cuda") | |
placeholder_token = "<my-funny-cat-token>" | ||
prompt = f"two {placeholder_token} getting married, photorealistic, high quality" | ||
image = pipeline(prompt, num_inference_steps=50).images[0] | ||
``` | ||
``` | ||
|
||
## A1111 LoRA files | ||
|
||
[Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) (A1111) is a popular web UI for Stable Diffusion that supports model sharing platforms like [Civitai](https://civitai.com/). Models trained with the Low-Rank Adaptation (LoRA) technique are especially popular because they're fast to train and have a much smaller file size than a fully finetuned model. 🤗 Diffusers supports loading A1111 LoRA checkpoints with [`~LoraLoaderMixin.load_lora_weights`]: | ||
|
||
```py | ||
from diffusers import DiffusionPipeline, UniPCMultistepScheduler | ||
import torch | ||
|
||
pipeline = DiffusionPipeline.from_pretrained( | ||
"andite/anything-v4.0", torch_dtype=torch.float16, safety_checker=None | ||
).to("cuda") | ||
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config) | ||
``` | ||
|
||
Download a LoRA checkpoint from Civitai; this example uses the [Howls Moving Castle,Interior/Scenery LoRA (Ghibli Stlye)](https://civitai.com/models/14605?modelVersionId=19998) checkpoint, but feel free to try out any LoRA checkpoint! | ||
|
||
```bash | ||
!wget https://civitai.com/api/download/models/19998 -O howls_moving_castle.safetensors | ||
``` | ||
|
||
Load the LoRA checkpoint into the pipeline with the [`~LoraLoaderMixin.load_lora_weights`] method: | ||
|
||
```py | ||
pipeline.load_lora_weights(".", weight_name="howls_moving_castle.safetensors") | ||
``` | ||
|
||
Now you can use the pipeline to generate images: | ||
|
||
```py | ||
prompt = "masterpiece, illustration, ultra-detailed, cityscape, san francisco, golden gate bridge, california, bay area, in the snow, beautiful detailed starry sky" | ||
negative_prompt = "lowres, cropped, worst quality, low quality, normal quality, artifacts, signature, watermark, username, blurry, more than one bridge, bad architecture" | ||
|
||
images = pipeline( | ||
prompt=prompt, | ||
negative_prompt=negative_prompt, | ||
width=512, | ||
height=512, | ||
num_inference_steps=25, | ||
num_images_per_prompt=4, | ||
generator=torch.manual_seed(0), | ||
).images | ||
``` | ||
|
||
Finally, create a helper function to display the images: | ||
|
||
```py | ||
from PIL import Image | ||
|
||
|
||
def image_grid(imgs, rows=2, cols=2): | ||
w, h = imgs[0].size | ||
grid = Image.new("RGB", size=(cols * w, rows * h)) | ||
|
||
for i, img in enumerate(imgs): | ||
grid.paste(img, box=(i % cols * w, i // cols * h)) | ||
return grid | ||
|
||
|
||
image_grid(images) | ||
``` | ||
|
||
<div class="flex justify-center"> | ||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/a1111-lora-sf.png"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The picture is amazing 💘 I also included a with and with LoRA comparison here. |
||
</div> |
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.
Also, possible directly load like:
C.f.: https://huggingface.co/docs/diffusers/main/en/training/lora#supporting-a1111-themed-lora-checkpoints-from-diffusers