Skip to content

Commit dd8cb2b

Browse files
committed
draft
1 parent 3b079ec commit dd8cb2b

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

docs/source/en/using-diffusers/other-formats.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,44 @@ pipeline = StableDiffusionPipeline.from_single_file(
7070
</hfoption>
7171
</hfoptions>
7272

73-
#### LoRA files
73+
#### LoRAs
7474

75-
[LoRA](https://hf.co/docs/peft/conceptual_guides/adapter#low-rank-adaptation-lora) is a lightweight adapter that is fast and easy to train, making them especially popular for generating images in a certain way or style. These adapters are commonly stored in a safetensors file, and are widely popular on model sharing platforms like [civitai](https://civitai.com/).
76-
77-
LoRAs are loaded into a base model with the [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] method.
75+
[LoRAs](../tutorials/using_peft_for_inference) are lightweight checkpoints fine-tuned to generate images or video in a specific style. If you are using a checkpoint trained with a Diffusers training script, the LoRA configuration is automatically saved as metadata in a safetensors file. When the safetensors file is loaded, the metadata is parsed to correctly configure the LoRA and avoids missing or incorrect LoRA configurations.
7876

7977
```py
80-
from diffusers import StableDiffusionXLPipeline
8178
import torch
79+
from diffusers import FluxPipeline
8280

83-
# base model
84-
pipeline = StableDiffusionXLPipeline.from_pretrained(
85-
"Lykon/dreamshaper-xl-1-0", torch_dtype=torch.float16, variant="fp16"
81+
pipeline = FluxPipeline.from_pretrained(
82+
"black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
8683
).to("cuda")
84+
pipeline.load_lora_weights("linoyts/yarn_art_Flux_LoRA")
8785

88-
# download LoRA weights
89-
!wget https://civitai.com/api/download/models/168776 -O blueprintify.safetensors
90-
91-
# load LoRA weights
92-
pipeline.load_lora_weights(".", weight_name="blueprintify.safetensors")
93-
prompt = "bl3uprint, a highly detailed blueprint of the empire state building, explaining how to build all parts, many txt, blueprint grid backdrop"
94-
negative_prompt = "lowres, cropped, worst quality, low quality, normal quality, artifacts, signature, watermark, username, blurry, more than one bridge, bad architecture"
86+
network_alphas, metadata = FluxPipeline.lora_state_dict(
87+
"linoyts/yarn_art_Flux_LoRA",
88+
return_lora_metadata=True
89+
)
9590

96-
image = pipeline(
97-
prompt=prompt,
98-
negative_prompt=negative_prompt,
99-
generator=torch.manual_seed(0),
100-
).images[0]
101-
image
91+
print("LoRA metadata:")
92+
for key, value in metadata.items():
93+
print(f" {key}: {value}")
10294
```
10395

104-
<div class="flex justify-center">
105-
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/blueprint-lora.png"/>
106-
</div>
96+
For LoRAs that aren't trained with Diffusers, you can still inject the metadata as long as it is a safetensors file.
97+
98+
```py
99+
import torch
100+
from diffusers import FluxPipeline
101+
102+
pipeline = FluxPipeline.from_pretrained(
103+
"black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
104+
).to("cuda")
105+
pipeline.load_lora_weights("linoyts/yarn_art_Flux_LoRA")
106+
pipeline.save_lora_weights(
107+
transformer_lora_adapter_metadata={"r": 16, "lora_alpha": 16},
108+
text_encoder_lora_adapter_metadata={"r": 8, "lora_alpha": 8}
109+
)
110+
```
107111

108112
### ckpt
109113

0 commit comments

Comments
 (0)