Commit
·
8f20832
1
Parent(s):
8d03357
init
Browse files- .gitattributes +1 -0
- README.md +141 -0
- pytorch_lora_weights.safetensors +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: black-forest-labs/FLUX.1-dev
|
3 |
+
library_name: diffusers
|
4 |
+
tags:
|
5 |
+
- text-to-image
|
6 |
+
- diffusers-training
|
7 |
+
- diffusers
|
8 |
+
- lora
|
9 |
+
- flux
|
10 |
+
- flux-diffusers
|
11 |
+
widget:
|
12 |
+
- text: "Serene raven-haired woman, moonlit lilies, swirling botanicals, alphonse mucha style"
|
13 |
+
output:
|
14 |
+
url: >-
|
15 |
+
images/alphonse_mucha_merged1.png
|
16 |
+
- text: "a puppy in a pond, alphonse mucha style"
|
17 |
+
output:
|
18 |
+
url: >-
|
19 |
+
images/alphonse_mucha_merged2.png
|
20 |
+
- text: "Ornate fox with a collar of autumn leaves and berries, amidst a tapestry of forest foliage, alphonse mucha style"
|
21 |
+
output:
|
22 |
+
url: >-
|
23 |
+
images/alphonse_mucha_merged3.png
|
24 |
+
instance_prompt: null
|
25 |
+
---
|
26 |
+
# LoRA for FLUX.1-dev - Alphonse Mucha Style
|
27 |
+
|
28 |
+
This repository contains a LoRA (Low-Rank Adaptation) fine-tuned on `black-forest-labs/FLUX.1-dev` to generate images in the artistic style of Alphonse Mucha. This work is part of the blog post, "Fine-Tuning FLUX.1-dev on consumer hardware and in FP8".
|
29 |
+
|
30 |
+
<Gallery />
|
31 |
+
|
32 |
+
## Model Description
|
33 |
+
|
34 |
+
This LoRA was trained on [derekl35/alphonse-mucha-style](https://huggingface.co/datasets/derekl35/alphonse-mucha-style) dataset.
|
35 |
+
|
36 |
+
## Inference
|
37 |
+
|
38 |
+
There are two main ways to use this LoRA for inference: loading the adapter on the fly or merging it with the base model.
|
39 |
+
|
40 |
+
### Option 1: Loading LoRA Adapters
|
41 |
+
|
42 |
+
This approach offers flexibility, allowing you to easily switch between different LoRA styles.
|
43 |
+
|
44 |
+
```python
|
45 |
+
from diffusers import FluxPipeline
|
46 |
+
import torch
|
47 |
+
|
48 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
49 |
+
pipeline = FluxPipeline.from_pretrained(
|
50 |
+
ckpt_id, torch_dtype=torch.float16
|
51 |
+
)
|
52 |
+
pipeline.load_lora_weights("derekl35/alphonse_mucha_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
53 |
+
pipeline.enable_model_cpu_offload()
|
54 |
+
|
55 |
+
image = pipeline(
|
56 |
+
"a puppy in a pond, alphonse mucha style",
|
57 |
+
num_inference_steps=28,
|
58 |
+
guidance_scale=3.5,
|
59 |
+
height=768,
|
60 |
+
width=512,
|
61 |
+
generator=torch.manual_seed(0)
|
62 |
+
).images[0]
|
63 |
+
image.save("alphonse_mucha_loaded.png")
|
64 |
+
```
|
65 |
+
|
66 |
+
### Option 2: Merging LoRA into Base Model
|
67 |
+
|
68 |
+
Merging the LoRA into the base model can lead to slightly faster inference and is useful when you want to use a single style consistently.
|
69 |
+
|
70 |
+
```python
|
71 |
+
from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel
|
72 |
+
import torch
|
73 |
+
|
74 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
75 |
+
pipeline = FluxPipeline.from_pretrained(
|
76 |
+
ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
|
77 |
+
)
|
78 |
+
pipeline.load_lora_weights("derekl35/alphonse_mucha_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
79 |
+
pipeline.fuse_lora()
|
80 |
+
pipeline.unload_lora_weights()
|
81 |
+
|
82 |
+
# You can save the fused transformer for later use
|
83 |
+
# pipeline.transformer.save_pretrained("fused_transformer")
|
84 |
+
|
85 |
+
pipeline.enable_model_cpu_offload()
|
86 |
+
image = pipeline(
|
87 |
+
"a puppy in a pond, alphonse mucha style",
|
88 |
+
num_inference_steps=28,
|
89 |
+
guidance_scale=3.5,
|
90 |
+
height=768,
|
91 |
+
width=512,
|
92 |
+
generator=torch.manual_seed(0)
|
93 |
+
).images[0]
|
94 |
+
image.save("alphonse_mucha_merged.png")
|
95 |
+
```
|
96 |
+
|
97 |
+
you can also requantize model:
|
98 |
+
|
99 |
+
```python
|
100 |
+
from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel, BitsAndBytesConfig
|
101 |
+
import torch
|
102 |
+
|
103 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
104 |
+
pipeline = FluxPipeline.from_pretrained(
|
105 |
+
ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
|
106 |
+
)
|
107 |
+
pipeline.load_lora_weights("derekl35/alphonse_mucha_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
108 |
+
pipeline.fuse_lora()
|
109 |
+
pipeline.unload_lora_weights()
|
110 |
+
|
111 |
+
pipeline.transformer.save_pretrained("fused_transformer")
|
112 |
+
|
113 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
114 |
+
bnb_4bit_compute_dtype = torch.bfloat16
|
115 |
+
|
116 |
+
nf4_config = BitsAndBytesConfig(
|
117 |
+
load_in_4bit=True,
|
118 |
+
bnb_4bit_quant_type="nf4",
|
119 |
+
bnb_4bit_compute_dtype=bnb_4bit_compute_dtype,
|
120 |
+
)
|
121 |
+
transformer = FluxTransformer2DModel.from_pretrained(
|
122 |
+
"fused_transformer",
|
123 |
+
quantization_config=nf4_config,
|
124 |
+
torch_dtype=bnb_4bit_compute_dtype,
|
125 |
+
)
|
126 |
+
|
127 |
+
pipeline = AutoPipelineForText2Image.from_pretrained(
|
128 |
+
ckpt_id, transformer=transformer, torch_dtype=bnb_4bit_compute_dtype
|
129 |
+
)
|
130 |
+
pipeline.enable_model_cpu_offload()
|
131 |
+
|
132 |
+
image = pipeline(
|
133 |
+
"a puppy in a pond, alphonse mucha style",
|
134 |
+
num_inference_steps=28,
|
135 |
+
guidance_scale=3.5,
|
136 |
+
height=768,
|
137 |
+
width=512,
|
138 |
+
generator=torch.manual_seed(0)
|
139 |
+
).images[0]
|
140 |
+
image.save("alphonse_mucha_merged.png")
|
141 |
+
```
|
pytorch_lora_weights.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d6775f99c7c63eccede37bf17e822f24d7f957bbcf8cf61e6a2e628271e5c7da
|
3 |
+
size 18727592
|