Commit
·
fc83593
1
Parent(s):
1daa60a
init
Browse files- .gitattributes +1 -0
- README.md +139 -0
- images/3d_merged1.png +3 -0
- images/3d_merged2.png +3 -0
- images/3d_merged3.png +3 -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,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: "a 3dicon, a joyful yellow emoji with smiling eyes, showing two hands in front as if reaching to give a hug"
|
13 |
+
output:
|
14 |
+
url: >-
|
15 |
+
images/3d_merged1.png
|
16 |
+
- text: "a 3dicon, a miniature galaxy in a glass dome, with swirling stars and nebulae in vibrant blues and purples, surrounded by a group of colorful icons on a black background"
|
17 |
+
output:
|
18 |
+
url: >-
|
19 |
+
images/3d_merged2.png
|
20 |
+
- text: "a 3dicon, an alien with green skin"
|
21 |
+
output:
|
22 |
+
url: >-
|
23 |
+
images/3d_merged3.png
|
24 |
+
instance_prompt: null
|
25 |
+
datasets:
|
26 |
+
- linoyts/3d_icon
|
27 |
+
---
|
28 |
+
# LoRA for FLUX.1-dev - 3D Icon Style
|
29 |
+
|
30 |
+
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 3D icons. This work is part of the blog post, "Fine-Tuning FLUX.1-dev on consumer hardware and in FP8".
|
31 |
+
|
32 |
+
<Gallery />
|
33 |
+
|
34 |
+
## Inference
|
35 |
+
|
36 |
+
There are two main ways to use this LoRA for inference: loading the adapter on the fly or merging it with the base model.
|
37 |
+
|
38 |
+
### Option 1: Loading LoRA Adapters
|
39 |
+
|
40 |
+
This approach offers flexibility, allowing you to easily switch between different LoRA styles.
|
41 |
+
|
42 |
+
```python
|
43 |
+
from diffusers import FluxPipeline
|
44 |
+
import torch
|
45 |
+
|
46 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
47 |
+
pipeline = FluxPipeline.from_pretrained(
|
48 |
+
ckpt_id, torch_dtype=torch.float16
|
49 |
+
)
|
50 |
+
pipeline.load_lora_weights("derekl35/3dicon_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
51 |
+
pipeline.enable_model_cpu_offload()
|
52 |
+
|
53 |
+
image = pipeline(
|
54 |
+
"a 3dicon, an alien with green skin",
|
55 |
+
num_inference_steps=28,
|
56 |
+
guidance_scale=3.5,
|
57 |
+
height=768,
|
58 |
+
width=768,
|
59 |
+
generator=torch.manual_seed(0)
|
60 |
+
).images[0]
|
61 |
+
image.save("3d_loaded.png")
|
62 |
+
```
|
63 |
+
|
64 |
+
### Option 2: Merging LoRA into Base Model
|
65 |
+
|
66 |
+
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.
|
67 |
+
|
68 |
+
```python
|
69 |
+
from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel
|
70 |
+
import torch
|
71 |
+
|
72 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
73 |
+
pipeline = FluxPipeline.from_pretrained(
|
74 |
+
ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
|
75 |
+
)
|
76 |
+
pipeline.load_lora_weights("derekl35/3dicon_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
77 |
+
pipeline.fuse_lora()
|
78 |
+
pipeline.unload_lora_weights()
|
79 |
+
|
80 |
+
# You can save the fused transformer for later use
|
81 |
+
# pipeline.transformer.save_pretrained("fused_transformer")
|
82 |
+
|
83 |
+
pipeline.enable_model_cpu_offload()
|
84 |
+
image = pipeline(
|
85 |
+
"a 3dicon, an alien with green skin",
|
86 |
+
num_inference_steps=28,
|
87 |
+
guidance_scale=3.5,
|
88 |
+
height=768,
|
89 |
+
width=768,
|
90 |
+
generator=torch.manual_seed(0)
|
91 |
+
).images[0]
|
92 |
+
image.save("3d_merged.png")
|
93 |
+
```
|
94 |
+
|
95 |
+
you can also requantize model:
|
96 |
+
|
97 |
+
```python
|
98 |
+
from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel, BitsAndBytesConfig
|
99 |
+
import torch
|
100 |
+
|
101 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
102 |
+
pipeline = FluxPipeline.from_pretrained(
|
103 |
+
ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
|
104 |
+
)
|
105 |
+
pipeline.load_lora_weights("derekl35/3dicon_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
|
106 |
+
pipeline.fuse_lora()
|
107 |
+
pipeline.unload_lora_weights()
|
108 |
+
|
109 |
+
pipeline.transformer.save_pretrained("fused_transformer")
|
110 |
+
|
111 |
+
ckpt_id = "black-forest-labs/FLUX.1-dev"
|
112 |
+
bnb_4bit_compute_dtype = torch.bfloat16
|
113 |
+
|
114 |
+
nf4_config = BitsAndBytesConfig(
|
115 |
+
load_in_4bit=True,
|
116 |
+
bnb_4bit_quant_type="nf4",
|
117 |
+
bnb_4bit_compute_dtype=bnb_4bit_compute_dtype,
|
118 |
+
)
|
119 |
+
transformer = FluxTransformer2DModel.from_pretrained(
|
120 |
+
"fused_transformer",
|
121 |
+
quantization_config=nf4_config,
|
122 |
+
torch_dtype=bnb_4bit_compute_dtype,
|
123 |
+
)
|
124 |
+
|
125 |
+
pipeline = AutoPipelineForText2Image.from_pretrained(
|
126 |
+
ckpt_id, transformer=transformer, torch_dtype=bnb_4bit_compute_dtype
|
127 |
+
)
|
128 |
+
pipeline.enable_model_cpu_offload()
|
129 |
+
|
130 |
+
image = pipeline(
|
131 |
+
"a 3dicon, an alien with green skin",
|
132 |
+
num_inference_steps=28,
|
133 |
+
guidance_scale=3.5,
|
134 |
+
height=768,
|
135 |
+
width=768,
|
136 |
+
generator=torch.manual_seed(0)
|
137 |
+
).images[0]
|
138 |
+
image.save("3d_merged.png")
|
139 |
+
```
|
images/3d_merged1.png
ADDED
![]() |
Git LFS Details
|
images/3d_merged2.png
ADDED
![]() |
Git LFS Details
|
images/3d_merged3.png
ADDED
![]() |
Git LFS Details
|
pytorch_lora_weights.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:860ce78f09bdb29b0ca3bc34e879c0d50f645c814b106c19ff3aadb4e3e265cc
|
3 |
+
size 18727592
|