-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support model cards #176
Merged
Merged
support model cards #176
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
000ac7d
introduce model cards and support passing FPS.
sayakpaul 0ec5eba
updates
sayakpaul e45719c
fix
sayakpaul 8ae55ba
fix
sayakpaul e6f74dc
updates
sayakpaul e8ebb2f
Merge branch 'main' into model-card
sayakpaul 133baee
revert changes
sayakpaul 9f0dad4
revert args.py changes
sayakpaul 82dc3f5
fix
sayakpaul 2bc2b81
fix
sayakpaul ce00a68
Merge branch 'main' into model-card
sayakpaul 9f1c5d9
Merge branch 'main' into model-card
sayakpaul 800a47f
fix filename
sayakpaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
from typing import List, Union | ||
|
||
import numpy as np | ||
import wandb | ||
from diffusers.utils import export_to_video | ||
from diffusers.utils.hub_utils import load_or_create_model_card, populate_model_card | ||
from PIL import Image | ||
|
||
|
||
def save_model_card( | ||
args, | ||
repo_id: str, | ||
videos: Union[List[str], Union[List[Image.Image], List[np.ndarray]]], | ||
validation_prompts: List[str], | ||
fps: int = 30, | ||
) -> None: | ||
widget_dict = [] | ||
output_dir = str(args.output_dir) | ||
if videos is not None and len(videos) > 0: | ||
for i, (video, validation_prompt) in enumerate(zip(videos, validation_prompts)): | ||
if not isinstance(video, str): | ||
export_to_video(video, os.path.join(output_dir, f"final_video_{i}.mp4"), fps=fps) | ||
widget_dict.append( | ||
{ | ||
"text": validation_prompt if validation_prompt else " ", | ||
"output": {"url": video if isinstance(video, str) else f"final_video_{i}.mp4"}, | ||
} | ||
) | ||
|
||
model_description = f""" | ||
# LoRA Finetune | ||
|
||
<Gallery /> | ||
|
||
## Model description | ||
|
||
This is a lora finetune of model: `{args.pretrained_model_name_or_path}`. | ||
|
||
The model was trained using [`finetrainers`](https://github.com/a-r-r-o-w/finetrainers). | ||
|
||
## Download model | ||
|
||
[Download LoRA]({repo_id}/tree/main) in the Files & Versions tab. | ||
|
||
## Usage | ||
|
||
Requires the [🧨 Diffusers library](https://github.com/huggingface/diffusers) installed. | ||
|
||
```py | ||
TODO | ||
``` | ||
|
||
For more details, including weighting, merging and fusing LoRAs, check the [documentation](https://huggingface.co/docs/diffusers/main/en/using-diffusers/loading_adapters) on loading LoRAs in diffusers. | ||
""" | ||
if wandb.run.url: | ||
model_description += f""" | ||
Find out the wandb run URL and training configurations [here]({wandb.run.url}). | ||
""" | ||
|
||
model_card = load_or_create_model_card( | ||
repo_id_or_path=repo_id, | ||
from_training=True, | ||
base_model=args.pretrained_model_name_or_path, | ||
model_description=model_description, | ||
widget=widget_dict, | ||
) | ||
tags = [ | ||
"text-to-video", | ||
"diffusers-training", | ||
"diffusers", | ||
"lora", | ||
"template:sd-lora", | ||
] | ||
|
||
model_card = populate_model_card(model_card, tags=tags) | ||
model_card.save(os.path.join(args.output_dir, "README.md")) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to keep it minimal yet sufficient for now.