{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "24817911-0228-4434-bd3f-9ca50e9d8763", "metadata": {}, "outputs": [], "source": [ "pwd" ] }, { "cell_type": "code", "execution_count": null, "id": "9c703396-7a83-4bb8-8faf-6f51550c0b4e", "metadata": {}, "outputs": [], "source": [ "!(python scripts/convert_sd_to_diffusers.py \\\n", " --checkpoint_path logs/2023-10-22T14-53-45_pokemon/checkpoints/epoch=000202.ckpt \\\n", " --original_config_file configs/stable-diffusion/pokemon.yaml \\\n", " --dump_path tf_202 \\\n", " --use_ema \\\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "0f86f81a-21ce-4bac-8e9d-517bd0200b9c", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import notebook_login\n", "\n", "notebook_login()" ] }, { "cell_type": "code", "execution_count": null, "id": "1b2be122-0c7d-4c99-84f0-70955d356721", "metadata": {}, "outputs": [], "source": [ "# @title Upload a locally saved pipeline to the hub\n", "\n", "# Code to upload a pipeline saved locally to the hub\n", "from huggingface_hub import HfApi, ModelCard, create_repo, get_full_repo_name\n", "\n", "# Set up repo and upload files\n", "model_name = \"tradfusion-v2\" # @param What you want it called on the hub\n", "local_folder_name = \"tf_202\" # @param Created by the script or one you created via image_pipe.save_pretrained('save_name')\n", "description = \"Fine-tuned Stable Diffusion Model on Irish Traditional Tunes Spectrograms\" # @param\n", "checkpoint_path = \"logs/2023-10-22T14-53-45_pokemon/checkpoints\"\n", "hub_model_id = get_full_repo_name(model_name)\n", "create_repo(hub_model_id)\n", "api = HfApi()\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/feature_extractor\", path_in_repo=\"feature_extractor\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/safety_checker\", path_in_repo=\"safety_checker\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/scheduler\", path_in_repo=\"scheduler\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/text_encoder\", path_in_repo=\"text_encoder\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/tokenizer\", path_in_repo=\"tokenizer\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/unet\", path_in_repo=\"unet\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/vae\", path_in_repo=\"vae\", repo_id=hub_model_id\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{local_folder_name}/model_index.json\",\n", " path_in_repo=\"model_index.json\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000202.ckpt\",\n", " path_in_repo=\"checkpoint_epoch202.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "# Add a model card (optional but nice!)\n", "content = f\"\"\"\n", "---\n", "license: mit\n", "tags:\n", "- pytorch\n", "- diffusers\n", "- unconditional-image-generation\n", "- text-to-image\n", "- diffusion-models-class\n", "---\n", "\n", "# Example Fine-Tuned Model for Unit 2 of the [Diffusion Models Class 🧨](https://github.com/huggingface/diffusion-models-class)\n", "\n", "{description}\n", "\n", "## Usage\n", "\n", "```python\n", "from diffusers import StableDiffusionPipeline\n", "\n", "pipeline = StableDiffusionPipeline.from_pretrained('{hub_model_id}')\n", "image = pipeline().images[0]\n", "image\n", "```\n", "\"\"\"\n", "\n", "card = ModelCard(content)\n", "card.push_to_hub(hub_model_id)" ] }, { "cell_type": "code", "execution_count": null, "id": "d4efff90-7300-4017-b0af-3ffafdb1eb9e", "metadata": {}, "outputs": [], "source": [ "# @title Upload a locally saved pipeline to the hub\n", "\n", "# Code to upload a pipeline saved locally to the hub\n", "from huggingface_hub import HfApi, ModelCard, create_repo, get_full_repo_name\n", "\n", "# Set up repo and upload files\n", "model_name = \"tradfusion-v2-training-files\" # @param What you want it called on the hub\n", "local_folder_name = \"logs/2023-10-22T14-53-45_pokemon\" # @param Created by the script or one you created via image_pipe.save_pretrained('save_name')\n", "#description = \"Fine-tuned Stable Diffusion Model on Irish Traditional Tunes Spectrograms\" # @param\n", "checkpoint_path = \"logs/2023-10-22T14-53-45_pokemon/checkpoints\"\n", "hub_model_id = get_full_repo_name(model_name)\n", "#create_repo(hub_model_id)\n", "api = HfApi()\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/configs\", path_in_repo=\"configs\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/images\", path_in_repo=\"images\", repo_id=hub_model_id\n", ")\n", "api.upload_folder(\n", " folder_path=f\"{local_folder_name}/testtube/version_0/tf\", path_in_repo=\"tf\", repo_id=hub_model_id\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{local_folder_name}/testtube/version_0/metrics.csv\",\n", " path_in_repo=\"metrics.csv\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000169.ckpt\",\n", " path_in_repo=\"checkpoint_epoch169.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000183.ckpt\",\n", " path_in_repo=\"checkpoint_epoch183.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000189.ckpt\",\n", " path_in_repo=\"checkpoint_epoch189.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000193.ckpt\",\n", " path_in_repo=\"checkpoint_epoch193.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000196.ckpt\",\n", " path_in_repo=\"checkpoint_epoch196.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000199.ckpt\",\n", " path_in_repo=\"checkpoint_epoch199.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000202.ckpt\",\n", " path_in_repo=\"checkpoint_epoch202.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/last.ckpt\",\n", " path_in_repo=\"checkpoint_last.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "# Add a model card (optional but nice!)\n", "content = f\"\"\"\n", "---\n", "license: mit\n", "tags:\n", "- pytorch\n", "- diffusers\n", "- text-to-image\n", "---\n", "\n", "## Usage\n", "\n", "Files logged during training, tensorboard, images generated, metrics and varias checkpoints\n", "\"\"\"\n", "\n", "#card = ModelCard(content)\n", "#card.push_to_hub(hub_model_id)" ] }, { "cell_type": "code", "execution_count": null, "id": "66cafa2d-ba4b-4086-8694-fb52911e453c", "metadata": {}, "outputs": [], "source": [ "# @title Upload a locally saved pipeline to the hub\n", "\n", "# Code to upload a pipeline saved locally to the hub\n", "from huggingface_hub import HfApi, ModelCard, create_repo, get_full_repo_name\n", "\n", "# Set up repo and upload files\n", "model_name = \"tradfusion-v2-training-files\" # @param What you want it called on the hub\n", "local_folder_name = \"wo\" # @param Created by the script or one you created via image_pipe.save_pretrained('save_name')\n", "checkpoint_path = \"logs/2023-10-22T14-53-45_pokemon/checkpoints\"\n", "hub_model_id = get_full_repo_name(model_name)\n", "\n", "api = HfApi()\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/epoch=000202.ckpt\",\n", " path_in_repo=\"checkpoint_epoch202.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n", "api.upload_file(\n", " path_or_fileobj=f\"{checkpoint_path}/last.ckpt\",\n", " path_in_repo=\"checkpoint_last.ckpt\",\n", " repo_id=hub_model_id,\n", ")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }