DerekLiu35 commited on
Commit
2db39b2
·
1 Parent(s): 24cd2fd
.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,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, yarn art style"
13
+ output:
14
+ url: >-
15
+ images/yarn_merged1.png
16
+ - text: "a puppy in a pond, yarn art style"
17
+ output:
18
+ url: >-
19
+ images/yarn_merged2.png
20
+ - text: "Ornate fox with a collar of autumn leaves and berries, amidst a tapestry of forest foliage, yarn art style"
21
+ output:
22
+ url: >-
23
+ images/yarn_merged3.png
24
+ instance_prompt: null
25
+ ---
26
+ # LoRA for FLUX.1-dev - Yarn Art 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 Yarn Art. This work is part of the blog post, "Fine-Tuning FLUX.1-dev on consumer hardware and in FP8".
29
+
30
+ <Gallery />
31
+
32
+ ## Inference
33
+
34
+ There are two main ways to use this LoRA for inference: loading the adapter on the fly or merging it with the base model.
35
+
36
+ ### Option 1: Loading LoRA Adapters
37
+
38
+ This approach offers flexibility, allowing you to easily switch between different LoRA styles.
39
+
40
+ ```python
41
+ from diffusers import FluxPipeline
42
+ import torch
43
+
44
+ ckpt_id = "black-forest-labs/FLUX.1-dev"
45
+ pipeline = FluxPipeline.from_pretrained(
46
+ ckpt_id, torch_dtype=torch.float16
47
+ )
48
+ pipeline.load_lora_weights("derekl35/yarn_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
49
+ pipeline.enable_model_cpu_offload()
50
+
51
+ image = pipeline(
52
+ "a puppy in a pond, yarn art style",
53
+ num_inference_steps=28,
54
+ guidance_scale=3.5,
55
+ height=768,
56
+ generator=torch.manual_seed(0)
57
+ ).images[0]
58
+ image.save("yarn_loaded.png")
59
+ ```
60
+
61
+ ### Option 2: Merging LoRA into Base Model
62
+
63
+ 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.
64
+
65
+ ```python
66
+ from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel
67
+ import torch
68
+
69
+ ckpt_id = "black-forest-labs/FLUX.1-dev"
70
+ pipeline = FluxPipeline.from_pretrained(
71
+ ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
72
+ )
73
+ pipeline.load_lora_weights("derekl35/yarn_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
74
+ pipeline.fuse_lora()
75
+ pipeline.unload_lora_weights()
76
+
77
+ # You can save the fused transformer for later use
78
+ # pipeline.transformer.save_pretrained("fused_transformer")
79
+
80
+ pipeline.enable_model_cpu_offload()
81
+ image = pipeline(
82
+ "a puppy in a pond, yarn art style",
83
+ num_inference_steps=28,
84
+ guidance_scale=3.5,
85
+ height=768,
86
+ width=512,
87
+ generator=torch.manual_seed(0)
88
+ ).images[0]
89
+ image.save("yarn_merged.png")
90
+ ```
91
+
92
+ you can also requantize model:
93
+
94
+ ```python
95
+ from diffusers import FluxPipeline, AutoPipelineForText2Image, FluxTransformer2DModel, BitsAndBytesConfig
96
+ import torch
97
+
98
+ ckpt_id = "black-forest-labs/FLUX.1-dev"
99
+ pipeline = FluxPipeline.from_pretrained(
100
+ ckpt_id, text_encoder=None, text_encoder_2=None, torch_dtype=torch.float16
101
+ )
102
+ pipeline.load_lora_weights("derekl35/yarn_qlora_flux", weight_name="pytorch_lora_weights.safetensors")
103
+ pipeline.fuse_lora()
104
+ pipeline.unload_lora_weights()
105
+
106
+ pipeline.transformer.save_pretrained("fused_transformer")
107
+
108
+ ckpt_id = "black-forest-labs/FLUX.1-dev"
109
+ bnb_4bit_compute_dtype = torch.bfloat16
110
+
111
+ nf4_config = BitsAndBytesConfig(
112
+ load_in_4bit=True,
113
+ bnb_4bit_quant_type="nf4",
114
+ bnb_4bit_compute_dtype=bnb_4bit_compute_dtype,
115
+ )
116
+ transformer = FluxTransformer2DModel.from_pretrained(
117
+ "fused_transformer",
118
+ quantization_config=nf4_config,
119
+ torch_dtype=bnb_4bit_compute_dtype,
120
+ )
121
+
122
+ pipeline = AutoPipelineForText2Image.from_pretrained(
123
+ ckpt_id, transformer=transformer, torch_dtype=bnb_4bit_compute_dtype
124
+ )
125
+ pipeline.enable_model_cpu_offload()
126
+
127
+ image = pipeline(
128
+ "a puppy in a pond, yarn art style",
129
+ num_inference_steps=28,
130
+ guidance_scale=3.5,
131
+ height=768,
132
+ width=512,
133
+ generator=torch.manual_seed(0)
134
+ ).images[0]
135
+ image.save("yarn_merged.png")
136
+ ```
images/yarn_merged1.png ADDED

Git LFS Details

  • SHA256: 7edac874a3cace381b522a6a9513310c529a35105894c7dbf21e1a1a85c24452
  • Pointer size: 132 Bytes
  • Size of remote file: 1.36 MB
images/yarn_merged2.png ADDED

Git LFS Details

  • SHA256: fdede1e76cd87504bf280e958a971143709e9d6af7a3338f3a34049f44112187
  • Pointer size: 132 Bytes
  • Size of remote file: 1.06 MB
images/yarn_merged3.png ADDED

Git LFS Details

  • SHA256: 4282eeae9199e5d4b9c94b82d23d1dba6f95df791c6db294d116d528d4fb9285
  • Pointer size: 132 Bytes
  • Size of remote file: 1.31 MB
pytorch_lora_weights.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a47c8786c9efc379b033b94dbc05b99061ddbaa22911bbd5361957d585451756
3
+ size 18727592