Entiluke commited on
Commit
4e7da96
·
verified ·
1 Parent(s): 30fc2e5

Model card auto-generated by SimpleTuner

Browse files
Files changed (1) hide show
  1. README.md +168 -0
README.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ base_model: "black-forest-labs/FLUX.1-dev"
4
+ tags:
5
+ - flux
6
+ - flux-diffusers
7
+ - text-to-image
8
+ - diffusers
9
+ - simpletuner
10
+ - not-for-all-audiences
11
+ - lora
12
+ - template:sd-lora
13
+ - lycoris
14
+ inference: true
15
+ widget:
16
+ - text: 'unconditional (blank prompt)'
17
+ parameters:
18
+ negative_prompt: 'blurry, cropped, ugly'
19
+ output:
20
+ url: ./assets/image_0_0.png
21
+ - text: 'A photo-realistic image of a cat'
22
+ parameters:
23
+ negative_prompt: 'blurry, cropped, ugly'
24
+ output:
25
+ url: ./assets/image_1_0.png
26
+ ---
27
+
28
+ # simpletuner-lora
29
+
30
+ This is a LyCORIS adapter derived from [black-forest-labs/FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev).
31
+
32
+
33
+ The main validation prompt used during training was:
34
+ ```
35
+ A photo-realistic image of a cat
36
+ ```
37
+
38
+
39
+ ## Validation settings
40
+ - CFG: `3.0`
41
+ - CFG Rescale: `0.0`
42
+ - Steps: `20`
43
+ - Sampler: `FlowMatchEulerDiscreteScheduler`
44
+ - Seed: `42`
45
+ - Resolution: `1024x1024`
46
+ - Skip-layer guidance:
47
+
48
+ Note: The validation settings are not necessarily the same as the [training settings](#training-settings).
49
+
50
+ You can find some example images in the following gallery:
51
+
52
+
53
+ <Gallery />
54
+
55
+ The text encoder **was not** trained.
56
+ You may reuse the base model text encoder for inference.
57
+
58
+
59
+ ## Training settings
60
+
61
+ - Training epochs: 5
62
+ - Training steps: 500
63
+ - Learning rate: 0.0001
64
+ - Learning rate schedule: polynomial
65
+ - Warmup steps: 100
66
+ - Max grad norm: 2.0
67
+ - Effective batch size: 1
68
+ - Micro-batch size: 1
69
+ - Gradient accumulation steps: 1
70
+ - Number of GPUs: 1
71
+ - Gradient checkpointing: True
72
+ - Prediction type: flow-matching (extra parameters=['shift=3', 'flux_guidance_mode=constant', 'flux_guidance_value=1.0', 'flow_matching_loss=compatible'])
73
+ - Optimizer: adamw_bf16
74
+ - Trainable parameter precision: Pure BF16
75
+ - Caption dropout probability: 0.0%
76
+
77
+ ### LyCORIS Config:
78
+ ```json
79
+ {
80
+ "algo": "lokr",
81
+ "multiplier": 1.0,
82
+ "linear_dim": 5000,
83
+ "linear_alpha": 1,
84
+ "factor": 16,
85
+ "apply_preset": {
86
+ "target_module": [
87
+ "Attention",
88
+ "FeedForward"
89
+ ],
90
+ "module_algo_map": {
91
+ "Attention": {
92
+ "factor": 16
93
+ },
94
+ "FeedForward": {
95
+ "factor": 8
96
+ }
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ ## Datasets
103
+
104
+ ### my-dataset-1024
105
+ - Repeats: 10
106
+ - Total number of images: 8
107
+ - Total number of aspect buckets: 1
108
+ - Resolution: 1.048576 megapixels
109
+ - Cropped: False
110
+ - Crop style: None
111
+ - Crop aspect: None
112
+ - Used for regularisation data: No
113
+
114
+
115
+ ## Inference
116
+
117
+
118
+ ```python
119
+ import torch
120
+ from diffusers import DiffusionPipeline
121
+ from lycoris import create_lycoris_from_weights
122
+
123
+
124
+ def download_adapter(repo_id: str):
125
+ import os
126
+ from huggingface_hub import hf_hub_download
127
+ adapter_filename = "pytorch_lora_weights.safetensors"
128
+ cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
129
+ cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
130
+ path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
131
+ path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
132
+ os.makedirs(path_to_adapter, exist_ok=True)
133
+ hf_hub_download(
134
+ repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
135
+ )
136
+
137
+ return path_to_adapter_file
138
+
139
+ model_id = 'black-forest-labs/FLUX.1-dev'
140
+ adapter_repo_id = 'Entiluke/simpletuner-lora'
141
+ adapter_filename = 'pytorch_lora_weights.safetensors'
142
+ adapter_file_path = download_adapter(repo_id=adapter_repo_id)
143
+ pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
144
+ lora_scale = 1.0
145
+ wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
146
+ wrapper.merge_to()
147
+
148
+ prompt = "A photo-realistic image of a cat"
149
+
150
+
151
+ ## Optional: quantise the model to save on vram.
152
+ ## Note: The model was quantised during training, and so it is recommended to do the same during inference time.
153
+ from optimum.quanto import quantize, freeze, qint8
154
+ quantize(pipeline.transformer, weights=qint8)
155
+ freeze(pipeline.transformer)
156
+
157
+ pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu') # the pipeline is already in its target precision level
158
+ image = pipeline(
159
+ prompt=prompt,
160
+ num_inference_steps=20,
161
+ generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
162
+ width=1024,
163
+ height=1024,
164
+ guidance_scale=3.0,
165
+ ).images[0]
166
+ image.save("output.png", format="PNG")
167
+ ```
168
+