"vscode:/vscode.git/clone" did not exist on "9920c333c69d372911a4549cde7cb7cc12cd4dc8"
Unverified Commit e1bdcc7a authored by Piyush Thakur's avatar Piyush Thakur Committed by GitHub
Browse files

[Model Card] standardize T2I Sdxl Lora model card (#6944)

* standardize model card template t2i-lora-sdxl

* type annotations
parent 84905ca7
...@@ -58,6 +58,7 @@ from diffusers.utils import ( ...@@ -58,6 +58,7 @@ from diffusers.utils import (
convert_unet_state_dict_to_peft, convert_unet_state_dict_to_peft,
is_wandb_available, is_wandb_available,
) )
from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card
from diffusers.utils.import_utils import is_xformers_available from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.torch_utils import is_compiled_module from diffusers.utils.torch_utils import is_compiled_module
...@@ -70,33 +71,20 @@ logger = get_logger(__name__) ...@@ -70,33 +71,20 @@ logger = get_logger(__name__)
def save_model_card( def save_model_card(
repo_id: str, repo_id: str,
images=None, images: list = None,
base_model=str, base_model: str = None,
dataset_name=str, dataset_name: str = None,
train_text_encoder=False, train_text_encoder: bool = False,
repo_folder=None, repo_folder: str = None,
vae_path=None, vae_path: str = None,
): ):
img_str = "" img_str = ""
if images is not None:
for i, image in enumerate(images): for i, image in enumerate(images):
image.save(os.path.join(repo_folder, f"image_{i}.png")) image.save(os.path.join(repo_folder, f"image_{i}.png"))
img_str += f"![img_{i}](./image_{i}.png)\n" img_str += f"![img_{i}](./image_{i}.png)\n"
yaml = f""" model_description = f"""
---
license: creativeml-openrail-m
base_model: {base_model}
dataset: {dataset_name}
tags:
- stable-diffusion-xl
- stable-diffusion-xl-diffusers
- text-to-image
- diffusers
- lora
inference: true
---
"""
model_card = f"""
# LoRA text2image fine-tuning - {repo_id} # LoRA text2image fine-tuning - {repo_id}
These are LoRA adaption weights for {base_model}. The weights were fine-tuned on the {dataset_name} dataset. You can find some example images in the following. \n These are LoRA adaption weights for {base_model}. The weights were fine-tuned on the {dataset_name} dataset. You can find some example images in the following. \n
...@@ -106,8 +94,19 @@ LoRA for the text encoder was enabled: {train_text_encoder}. ...@@ -106,8 +94,19 @@ LoRA for the text encoder was enabled: {train_text_encoder}.
Special VAE used for training: {vae_path}. Special VAE used for training: {vae_path}.
""" """
with open(os.path.join(repo_folder, "README.md"), "w") as f: model_card = load_or_create_model_card(
f.write(yaml + model_card) repo_id_or_path=repo_id,
from_training=True,
license="creativeml-openrail-m",
base_model=base_model,
model_description=model_description,
inference=True,
)
tags = ["stable-diffusion-xl", "stable-diffusion-xl-diffusers", "text-to-image", "diffusers", "lora"]
model_card = populate_model_card(model_card, tags=tags)
model_card.save(os.path.join(repo_folder, "README.md"))
def import_model_class_from_model_name_or_path( def import_model_class_from_model_name_or_path(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment