Push files to the Hub

Push files to the Hub

Open In ColabOpen In Studio Lab

🌍 Diffusers provides a PushToHubMixinarrow-up-right for uploading your model, scheduler, or pipeline to the Hub. It is an easy way to store your files on the Hub, and also allows you to share your work with others. Under the hood, the PushToHubMixinarrow-up-right:

  1. creates a repository on the Hub

  2. saves your model, scheduler, or pipeline files so they can be reloaded later

  3. uploads folder containing these files to the Hub

This guide will show you how to use the PushToHubMixinarrow-up-right to upload your files to the Hub.

You’ll need to log in to your Hub account with your access tokenarrow-up-right first:

Copied

from boincai_hub import notebook_login

notebook_login()

Models

To push a model to the Hub, call push_to_hub()arrow-up-right and specfiy the repository id of the model to be stored on the Hub:

Copied

from diffusers import ControlNetModel

controlnet = ControlNetModel(
    block_out_channels=(32, 64),
    layers_per_block=2,
    in_channels=4,
    down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
    cross_attention_dim=32,
    conditioning_embedding_out_channels=(16, 32),
)
controlnet.push_to_hub("my-controlnet-model")

For model’s, you can also specify the variantarrow-up-right of the weights to push to the Hub. For example, to push fp16 weights:

Copied

The push_to_hub()arrow-up-right function saves the model’s config.json file and the weights are automatically saved in the safetensors format.

Now you can reload the model from your repository on the Hub:

Copied

Scheduler

To push a scheduler to the Hub, call push_to_hub()arrow-up-right and specfiy the repository id of the scheduler to be stored on the Hub:

Copied

The push_to_hub()arrow-up-right function saves the scheduler’s scheduler_config.json file to the specified repository.

Now you can reload the scheduler from your repository on the Hub:

Copied

Pipeline

You can also push an entire pipeline with all it’s components to the Hub. For example, initialize the components of a StableDiffusionPipelinearrow-up-right with the parameters you want:

Copied

Pass all of the components to the StableDiffusionPipelinearrow-up-right and call push_to_hub()arrow-up-right to push the pipeline to the Hub:

Copied

The push_to_hub()arrow-up-right function saves each component to a subfolder in the repository. Now you can reload the pipeline from your repository on the Hub:

Copied

Privacy

Set private=True in the push_to_hub()arrow-up-right function to keep your model, scheduler, or pipeline files private:

Copied

Private repositories are only visible to you, and other users won’t be able to clone the repository and your repository won’t appear in search results. Even if a user has the URL to your private repository, they’ll receive a 404 - Repo not found error.

To load a model, scheduler, or pipeline from a private or gated repositories, set use_auth_token=True:

Copied

Last updated