Johetan commited on
Commit
90188c2
·
verified ·
1 Parent(s): 75aa281

Model card auto-generated by SimpleTuner

Browse files
Files changed (1) hide show
  1. README.md +181 -0
README.md ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ base_model: "stabilityai/stable-diffusion-3.5-large"
4
+ tags:
5
+ - sd3
6
+ - sd3-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 [stabilityai/stable-diffusion-3.5-large](https://huggingface.co/stabilityai/stable-diffusion-3.5-large).
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: `5.0`
41
+ - CFG Rescale: `0.0`
42
+ - Steps: `20`
43
+ - Sampler: `FlowMatchEulerDiscreteScheduler`
44
+ - Seed: `42`
45
+ - Resolution: `512x512`
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: 0
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'])
73
+ - Optimizer: adamw_bf16
74
+ - Trainable parameter precision: Pure BF16
75
+ - Caption dropout probability: 5.0%
76
+
77
+
78
+ ### LyCORIS Config:
79
+ ```json
80
+ {
81
+ "algo": "lokr",
82
+ "multiplier": 1.0,
83
+ "linear_dim": 10000,
84
+ "linear_alpha": 1,
85
+ "factor": 16,
86
+ "apply_preset": {
87
+ "target_module": [
88
+ "Attention",
89
+ "FeedForward"
90
+ ],
91
+ "module_algo_map": {
92
+ "Attention": {
93
+ "factor": 16
94
+ },
95
+ "FeedForward": {
96
+ "factor": 8
97
+ }
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## Datasets
104
+
105
+ ### my-dataset-512
106
+ - Repeats: 10
107
+ - Total number of images: 182
108
+ - Total number of aspect buckets: 1
109
+ - Resolution: 0.262144 megapixels
110
+ - Cropped: False
111
+ - Crop style: None
112
+ - Crop aspect: None
113
+ - Used for regularisation data: No
114
+ ### my-dataset-crop-512
115
+ - Repeats: 10
116
+ - Total number of images: 182
117
+ - Total number of aspect buckets: 1
118
+ - Resolution: 0.262144 megapixels
119
+ - Cropped: True
120
+ - Crop style: center
121
+ - Crop aspect: square
122
+ - Used for regularisation data: No
123
+
124
+
125
+ ## Inference
126
+
127
+
128
+ ```python
129
+ import torch
130
+ from diffusers import DiffusionPipeline
131
+ from lycoris import create_lycoris_from_weights
132
+
133
+
134
+ def download_adapter(repo_id: str):
135
+ import os
136
+ from huggingface_hub import hf_hub_download
137
+ adapter_filename = "pytorch_lora_weights.safetensors"
138
+ cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
139
+ cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
140
+ path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
141
+ path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
142
+ os.makedirs(path_to_adapter, exist_ok=True)
143
+ hf_hub_download(
144
+ repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
145
+ )
146
+
147
+ return path_to_adapter_file
148
+
149
+ model_id = 'stabilityai/stable-diffusion-3.5-large'
150
+ adapter_repo_id = 'Johetan/simpletuner-lora'
151
+ adapter_filename = 'pytorch_lora_weights.safetensors'
152
+ adapter_file_path = download_adapter(repo_id=adapter_repo_id)
153
+ pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
154
+ lora_scale = 1.0
155
+ wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
156
+ wrapper.merge_to()
157
+
158
+ prompt = "A photo-realistic image of a cat"
159
+ negative_prompt = 'blurry, cropped, ugly'
160
+
161
+ ## Optional: quantise the model to save on vram.
162
+ ## Note: The model was quantised during training, and so it is recommended to do the same during inference time.
163
+ from optimum.quanto import quantize, freeze, qint8
164
+ quantize(pipeline.transformer, weights=qint8)
165
+ freeze(pipeline.transformer)
166
+
167
+ 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
168
+ image = pipeline(
169
+ prompt=prompt,
170
+ negative_prompt=negative_prompt,
171
+ num_inference_steps=20,
172
+ generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
173
+ width=512,
174
+ height=512,
175
+ guidance_scale=5.0,
176
+ ).images[0]
177
+ image.save("output.png", format="PNG")
178
+ ```
179
+
180
+
181
+