abby101 commited on
Commit
86116e3
1 Parent(s): dcaeb47

run and generate model card

Browse files
README.md CHANGED
@@ -1,3 +1,92 @@
1
  ---
2
  license: openrail++
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: openrail++
3
+ library_name: diffusers
4
+ tags:
5
+ - text-to-image
6
+ - stable-diffusion-xl
7
+ - stable-diffusion-xl-diffusers
8
+ - text-to-image
9
+ - diffusers
10
+ - lora
11
+ - template:sd-lora
12
+ base_model: runwayml/stable-diffusion-v1-5
13
+ instance_prompt: A mushroom in [V] style
14
+ widget:
15
+ - text: ' '
16
+ output:
17
+ url: image_0.png
18
+ - text: ' '
19
+ output:
20
+ url: image_1.png
21
+ - text: ' '
22
+ output:
23
+ url: image_2.png
24
  ---
25
+
26
+ <!-- This model card has been generated automatically according to the information the training script had access to. You
27
+ should probably proofread and complete it, then remove this comment. -->
28
+
29
+
30
+ # SDXL LoRA DreamBooth - abby101/test
31
+
32
+ <Gallery />
33
+
34
+ ## Model description
35
+
36
+ ### These are abby101/test LoRA adaption weights for runwayml/stable-diffusion-v1-5.
37
+
38
+ ## Download model
39
+
40
+ ### Use it with UIs such as AUTOMATIC1111, Comfy UI, SD.Next, Invoke
41
+
42
+ - **LoRA**: download **[`..safetensors` here 💾](/abby101/test/blob/main/..safetensors)**.
43
+ - Place it on your `models/Lora` folder.
44
+ - On AUTOMATIC1111, load the LoRA by adding `<lora:.:1>` to your prompt. On ComfyUI just [load it as a regular LoRA](https://comfyanonymous.github.io/ComfyUI_examples/lora/).
45
+
46
+
47
+ ## Use it with the [🧨 diffusers library](https://github.com/huggingface/diffusers)
48
+
49
+ ```py
50
+ from diffusers import AutoPipelineForText2Image
51
+ import torch
52
+
53
+ pipeline = AutoPipelineForText2Image.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16).to('cuda')
54
+ pipeline.load_lora_weights('abby101/test', weight_name='pytorch_lora_weights.safetensors')
55
+
56
+ image = pipeline('A mushroom in [V] style').images[0]
57
+ ```
58
+
59
+ For more details, including weighting, merging and fusing LoRAs, check the [documentation on loading LoRAs in diffusers](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters)
60
+
61
+ ## Trigger words
62
+
63
+ You should use A mushroom in [V] style to trigger the image generation.
64
+
65
+ ## Details
66
+ All [Files & versions](/abby101/test/tree/main).
67
+
68
+ The weights were trained using [🧨 diffusers Advanced Dreambooth Training Script](https://github.com/huggingface/diffusers/blob/main/examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py).
69
+
70
+ LoRA for the text encoder was enabled. False.
71
+
72
+ Pivotal tuning was enabled: False.
73
+
74
+ Special VAE used for training: None.
75
+
76
+
77
+
78
+ ## Intended uses & limitations
79
+
80
+ #### How to use
81
+
82
+ ```python
83
+ # TODO: add an example code snippet for running this diffusion pipeline
84
+ ```
85
+
86
+ #### Limitations and bias
87
+
88
+ [TODO: provide examples of latent issues and potential remediations]
89
+
90
+ ## Training details
91
+
92
+ [TODO: describe the data used to train the model]
image_0.png ADDED
image_1.png ADDED
image_2.png ADDED
test-model-card-template-dreambooth-sdxl-lora-adv.ipynb ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "!pip install git+https://github.com/chiral-carbon/diffusers@advdiff_sdxl -q"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "import os, re\n",
19
+ "\n",
20
+ "from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card\n",
21
+ "\n",
22
+ "def save_model_card(\n",
23
+ " repo_id: str,\n",
24
+ " use_dora: bool,\n",
25
+ " images: list = None,\n",
26
+ " base_model: str = None,\n",
27
+ " train_text_encoder: bool = False,\n",
28
+ " train_text_encoder_ti: bool = False,\n",
29
+ " token_abstraction_dict=None,\n",
30
+ " instance_prompt: str = None,\n",
31
+ " validation_prompt:str = None,\n",
32
+ " repo_folder=None,\n",
33
+ " vae_path=None,\n",
34
+ "):\n",
35
+ " widget_dict = []\n",
36
+ " if images is not None:\n",
37
+ " for i, image in enumerate(images):\n",
38
+ " image.save(os.path.join(repo_folder, f\"image_{i}.png\"))\n",
39
+ " widget_dict.append(\n",
40
+ " {\"text\": validation_prompt if validation_prompt else \" \", \"output\": {\"url\": f\"image_{i}.png\"}}\n",
41
+ " )\n",
42
+ " else:\n",
43
+ " widget_dict.append(\n",
44
+ " {\"text\": instance_prompt}\n",
45
+ " )\n",
46
+ " embeddings_filename = f\"{repo_folder}_emb\"\n",
47
+ " instance_prompt_webui = re.sub(r\"<s\\d+>\", \"\", re.sub(r\"<s\\d+>\", embeddings_filename, instance_prompt, count=1))\n",
48
+ " ti_keys = \", \".join(f'\"{match}\"' for match in re.findall(r\"<s\\d+>\", instance_prompt))\n",
49
+ " if instance_prompt_webui != embeddings_filename:\n",
50
+ " instance_prompt_sentence = f\"For example, `{instance_prompt_webui}`\"\n",
51
+ " else:\n",
52
+ " instance_prompt_sentence = \"\"\n",
53
+ " trigger_str = f\"You should use {instance_prompt} to trigger the image generation.\"\n",
54
+ " diffusers_imports_pivotal = \"\"\n",
55
+ " diffusers_example_pivotal = \"\"\n",
56
+ " webui_example_pivotal = \"\"\n",
57
+ " if train_text_encoder_ti:\n",
58
+ " trigger_str = (\n",
59
+ " \"To trigger image generation of trained concept(or concepts) replace each concept identifier \"\n",
60
+ " \"in you prompt with the new inserted tokens:\\n\"\n",
61
+ " )\n",
62
+ " diffusers_imports_pivotal = \"\"\"from huggingface_hub import hf_hub_download\n",
63
+ "from safetensors.torch import load_file\n",
64
+ " \"\"\"\n",
65
+ " diffusers_example_pivotal = f\"\"\"embedding_path = hf_hub_download(repo_id='{repo_id}', filename='{embeddings_filename}.safetensors', repo_type=\"model\")\n",
66
+ "state_dict = load_file(embedding_path)\n",
67
+ "pipeline.load_textual_inversion(state_dict[\"clip_l\"], token=[{ti_keys}], text_encoder=pipeline.text_encoder, tokenizer=pipeline.tokenizer)\n",
68
+ "pipeline.load_textual_inversion(state_dict[\"clip_g\"], token=[{ti_keys}], text_encoder=pipeline.text_encoder_2, tokenizer=pipeline.tokenizer_2)\n",
69
+ " \"\"\"\n",
70
+ " webui_example_pivotal = f\"\"\"- *Embeddings*: download **[`{embeddings_filename}.safetensors` here 💾](/{repo_id}/blob/main/{embeddings_filename}.safetensors)**.\n",
71
+ " - Place it on it on your `embeddings` folder\n",
72
+ " - Use it by adding `{embeddings_filename}` to your prompt. {instance_prompt_sentence}\n",
73
+ " (you need both the LoRA and the embeddings as they were trained together for this LoRA)\n",
74
+ " \"\"\"\n",
75
+ " if token_abstraction_dict:\n",
76
+ " for key, value in token_abstraction_dict.items():\n",
77
+ " tokens = \"\".join(value)\n",
78
+ " trigger_str += f\"\"\"\n",
79
+ "to trigger concept `{key}` → use `{tokens}` in your prompt \\n\n",
80
+ "\"\"\"\n",
81
+ "\n",
82
+ " model_description = f\"\"\"\n",
83
+ "# SDXL LoRA DreamBooth - {repo_id}\n",
84
+ "\n",
85
+ "<Gallery />\n",
86
+ "\n",
87
+ "## Model description\n",
88
+ "\n",
89
+ "### These are {repo_id} LoRA adaption weights for {base_model}.\n",
90
+ "\n",
91
+ "## Download model\n",
92
+ "\n",
93
+ "### Use it with UIs such as AUTOMATIC1111, Comfy UI, SD.Next, Invoke\n",
94
+ "\n",
95
+ "- **LoRA**: download **[`{repo_folder}.safetensors` here 💾](/{repo_id}/blob/main/{repo_folder}.safetensors)**.\n",
96
+ " - Place it on your `models/Lora` folder.\n",
97
+ " - On AUTOMATIC1111, load the LoRA by adding `<lora:{repo_folder}:1>` to your prompt. On ComfyUI just [load it as a regular LoRA](https://comfyanonymous.github.io/ComfyUI_examples/lora/).\n",
98
+ "{webui_example_pivotal}\n",
99
+ "\n",
100
+ "## Use it with the [🧨 diffusers library](https://github.com/huggingface/diffusers)\n",
101
+ "\n",
102
+ "```py\n",
103
+ "from diffusers import AutoPipelineForText2Image\n",
104
+ "import torch\n",
105
+ "{diffusers_imports_pivotal}\n",
106
+ "pipeline = AutoPipelineForText2Image.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16).to('cuda')\n",
107
+ "pipeline.load_lora_weights('{repo_id}', weight_name='pytorch_lora_weights.safetensors')\n",
108
+ "{diffusers_example_pivotal}\n",
109
+ "image = pipeline('{validation_prompt if validation_prompt else instance_prompt}').images[0]\n",
110
+ "```\n",
111
+ "\n",
112
+ "For more details, including weighting, merging and fusing LoRAs, check the [documentation on loading LoRAs in diffusers](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters)\n",
113
+ "\n",
114
+ "## Trigger words\n",
115
+ "\n",
116
+ "{trigger_str}\n",
117
+ "\n",
118
+ "## Details\n",
119
+ "All [Files & versions](/{repo_id}/tree/main).\n",
120
+ "\n",
121
+ "The weights were trained using [🧨 diffusers Advanced Dreambooth Training Script](https://github.com/huggingface/diffusers/blob/main/examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py).\n",
122
+ "\n",
123
+ "LoRA for the text encoder was enabled. {train_text_encoder}.\n",
124
+ "\n",
125
+ "Pivotal tuning was enabled: {train_text_encoder_ti}.\n",
126
+ "\n",
127
+ "Special VAE used for training: {vae_path}.\n",
128
+ "\n",
129
+ "\"\"\"\n",
130
+ " model_card = load_or_create_model_card(\n",
131
+ " repo_id_or_path=repo_id,\n",
132
+ " from_training=True,\n",
133
+ " license=\"openrail++\",\n",
134
+ " base_model=base_model,\n",
135
+ " prompt=instance_prompt,\n",
136
+ " model_description=model_description,\n",
137
+ " widget=widget_dict,\n",
138
+ " )\n",
139
+ " tags = [\n",
140
+ " \"text-to-image\",\n",
141
+ " \"stable-diffusion-xl\",\n",
142
+ " \"stable-diffusion-xl-diffusers\",\n",
143
+ " \"text-to-image\",\n",
144
+ " \"diffusers\",\n",
145
+ " \"lora\",\n",
146
+ " \"template:sd-lora\",\n",
147
+ " ]\n",
148
+ " model_card = populate_model_card(model_card, tags=tags)\n",
149
+ " "
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": 3,
155
+ "metadata": {},
156
+ "outputs": [],
157
+ "source": [
158
+ "from diffusers.utils import load_image\n",
159
+ "\n",
160
+ "images = [\n",
161
+ " load_image(\"https://huggingface.co/datasets/diffusers/docs-images/resolve/main/amused/A%20mushroom%20in%20%5BV%5D%20style.png\")\n",
162
+ " for _ in range(3)\n",
163
+ "]\n",
164
+ "\n",
165
+ "save_model_card(\n",
166
+ " use_dora=False,\n",
167
+ " repo_id=\"abby101/test\",\n",
168
+ " images=images,\n",
169
+ " base_model=\"runwayml/stable-diffusion-v1-5\",\n",
170
+ " repo_folder=\".\",\n",
171
+ " instance_prompt=\"A mushroom in [V] style\",\n",
172
+ ")"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 4,
178
+ "metadata": {},
179
+ "outputs": [
180
+ {
181
+ "name": "stdout",
182
+ "output_type": "stream",
183
+ "text": [
184
+ "---\n",
185
+ "license: openrail++\n",
186
+ "library_name: diffusers\n",
187
+ "tags:\n",
188
+ "- text-to-image\n",
189
+ "- stable-diffusion-xl\n",
190
+ "- stable-diffusion-xl-diffusers\n",
191
+ "- text-to-image\n",
192
+ "- diffusers\n",
193
+ "- lora\n",
194
+ "- template:sd-lora\n",
195
+ "base_model: runwayml/stable-diffusion-v1-5\n",
196
+ "instance_prompt: A mushroom in [V] style\n",
197
+ "widget:\n",
198
+ "- text: ' '\n",
199
+ " output:\n",
200
+ " url: image_0.png\n",
201
+ "- text: ' '\n",
202
+ " output:\n",
203
+ " url: image_1.png\n",
204
+ "- text: ' '\n",
205
+ " output:\n",
206
+ " url: image_2.png\n",
207
+ "---\n",
208
+ "\n",
209
+ "<!-- This model card has been generated automatically according to the information the training script had access to. You\n",
210
+ "should probably proofread and complete it, then remove this comment. -->\n",
211
+ "\n",
212
+ "\n",
213
+ "# SDXL LoRA DreamBooth - abby101/test\n",
214
+ "\n",
215
+ "<Gallery />\n",
216
+ "\n",
217
+ "## Model description\n",
218
+ "\n",
219
+ "### These are abby101/test LoRA adaption weights for runwayml/stable-diffusion-v1-5.\n",
220
+ "\n",
221
+ "## Download model\n",
222
+ "\n",
223
+ "### Use it with UIs such as AUTOMATIC1111, Comfy UI, SD.Next, Invoke\n",
224
+ "\n",
225
+ "- **LoRA**: download **[`..safetensors` here 💾](/abby101/test/blob/main/..safetensors)**.\n",
226
+ " - Place it on your `models/Lora` folder.\n",
227
+ " - On AUTOMATIC1111, load the LoRA by adding `<lora:.:1>` to your prompt. On ComfyUI just [load it as a regular LoRA](https://comfyanonymous.github.io/ComfyUI_examples/lora/).\n",
228
+ "\n",
229
+ "\n",
230
+ "## Use it with the [🧨 diffusers library](https://github.com/huggingface/diffusers)\n",
231
+ "\n",
232
+ "```py\n",
233
+ "from diffusers import AutoPipelineForText2Image\n",
234
+ "import torch\n",
235
+ "\n",
236
+ "pipeline = AutoPipelineForText2Image.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0', torch_dtype=torch.float16).to('cuda')\n",
237
+ "pipeline.load_lora_weights('abby101/test', weight_name='pytorch_lora_weights.safetensors')\n",
238
+ "\n",
239
+ "image = pipeline('A mushroom in [V] style').images[0]\n",
240
+ "```\n",
241
+ "\n",
242
+ "For more details, including weighting, merging and fusing LoRAs, check the [documentation on loading LoRAs in diffusers](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters)\n",
243
+ "\n",
244
+ "## Trigger words\n",
245
+ "\n",
246
+ "You should use A mushroom in [V] style to trigger the image generation.\n",
247
+ "\n",
248
+ "## Details\n",
249
+ "All [Files & versions](/abby101/test/tree/main).\n",
250
+ "\n",
251
+ "The weights were trained using [🧨 diffusers Advanced Dreambooth Training Script](https://github.com/huggingface/diffusers/blob/main/examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py).\n",
252
+ "\n",
253
+ "LoRA for the text encoder was enabled. False.\n",
254
+ "\n",
255
+ "Pivotal tuning was enabled: False.\n",
256
+ "\n",
257
+ "Special VAE used for training: None.\n",
258
+ "\n",
259
+ "\n",
260
+ "\n",
261
+ "## Intended uses & limitations\n",
262
+ "\n",
263
+ "#### How to use\n",
264
+ "\n",
265
+ "```python\n",
266
+ "# TODO: add an example code snippet for running this diffusion pipeline\n",
267
+ "```\n",
268
+ "\n",
269
+ "#### Limitations and bias\n",
270
+ "\n",
271
+ "[TODO: provide examples of latent issues and potential remediations]\n",
272
+ "\n",
273
+ "## Training details\n",
274
+ "\n",
275
+ "[TODO: describe the data used to train the model]"
276
+ ]
277
+ }
278
+ ],
279
+ "source": [
280
+ "!cat README.md"
281
+ ]
282
+ }
283
+ ],
284
+ "metadata": {
285
+ "kernelspec": {
286
+ "display_name": "pydl",
287
+ "language": "python",
288
+ "name": "python3"
289
+ },
290
+ "language_info": {
291
+ "codemirror_mode": {
292
+ "name": "ipython",
293
+ "version": 3
294
+ },
295
+ "file_extension": ".py",
296
+ "mimetype": "text/x-python",
297
+ "name": "python",
298
+ "nbconvert_exporter": "python",
299
+ "pygments_lexer": "ipython3",
300
+ "version": "3.10.9"
301
+ }
302
+ },
303
+ "nbformat": 4,
304
+ "nbformat_minor": 2
305
+ }