> For the complete documentation index, see [llms.txt](https://boinc-ai.gitbook.io/diffusers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boinc-ai.gitbook.io/diffusers/using-diffusers/loading-and-hub/push-files-to-the-hub.md).

# Push files to the Hub

## Push files to the Hub

![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)![Open In Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)

🌍 Diffusers provides a [PushToHubMixin](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin) 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 [PushToHubMixin](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin):

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 [PushToHubMixin](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin) to upload your files to the Hub.

You’ll need to log in to your Hub account with your access [token](https://huggingface.co/settings/tokens) first:

Copied

```
from boincai_hub import notebook_login

notebook_login()
```

### Models

To push a model to the Hub, call [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) 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 [*variant*](https://huggingface.co/docs/diffusers/using-diffusers/loading#checkpoint-variants) of the weights to push to the Hub. For example, to push `fp16` weights:

Copied

```
controlnet.push_to_hub("my-controlnet-model", variant="fp16")
```

The [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) 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

```
model = ControlNetModel.from_pretrained("your-namespace/my-controlnet-model")
```

### Scheduler

To push a scheduler to the Hub, call [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) and specfiy the repository id of the scheduler to be stored on the Hub:

Copied

```
from diffusers import DDIMScheduler

scheduler = DDIMScheduler(
    beta_start=0.00085,
    beta_end=0.012,
    beta_schedule="scaled_linear",
    clip_sample=False,
    set_alpha_to_one=False,
)
scheduler.push_to_hub("my-controlnet-scheduler")
```

The [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) 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

```
scheduler = DDIMScheduler.from_pretrained("your-namepsace/my-controlnet-scheduler")
```

### Pipeline

You can also push an entire pipeline with all it’s components to the Hub. For example, initialize the components of a [StableDiffusionPipeline](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline) with the parameters you want:

Copied

```
from diffusers import (
    UNet2DConditionModel,
    AutoencoderKL,
    DDIMScheduler,
    StableDiffusionPipeline,
)
from transformers import CLIPTextModel, CLIPTextConfig, CLIPTokenizer

unet = UNet2DConditionModel(
    block_out_channels=(32, 64),
    layers_per_block=2,
    sample_size=32,
    in_channels=4,
    out_channels=4,
    down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
    up_block_types=("CrossAttnUpBlock2D", "UpBlock2D"),
    cross_attention_dim=32,
)

scheduler = DDIMScheduler(
    beta_start=0.00085,
    beta_end=0.012,
    beta_schedule="scaled_linear",
    clip_sample=False,
    set_alpha_to_one=False,
)

vae = AutoencoderKL(
    block_out_channels=[32, 64],
    in_channels=3,
    out_channels=3,
    down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"],
    up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"],
    latent_channels=4,
)

text_encoder_config = CLIPTextConfig(
    bos_token_id=0,
    eos_token_id=2,
    hidden_size=32,
    intermediate_size=37,
    layer_norm_eps=1e-05,
    num_attention_heads=4,
    num_hidden_layers=5,
    pad_token_id=1,
    vocab_size=1000,
)
text_encoder = CLIPTextModel(text_encoder_config)
tokenizer = CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip")
```

Pass all of the components to the [StableDiffusionPipeline](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline) and call [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) to push the pipeline to the Hub:

Copied

```
components = {
    "unet": unet,
    "scheduler": scheduler,
    "vae": vae,
    "text_encoder": text_encoder,
    "tokenizer": tokenizer,
    "safety_checker": None,
    "feature_extractor": None,
}

pipeline = StableDiffusionPipeline(**components)
pipeline.push_to_hub("my-pipeline")
```

The [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) function saves each component to a subfolder in the repository. Now you can reload the pipeline from your repository on the Hub:

Copied

```
pipeline = StableDiffusionPipeline.from_pretrained("your-namespace/my-pipeline")
```

### Privacy

Set `private=True` in the [push\_to\_hub()](https://huggingface.co/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.utils.PushToHubMixin.push_to_hub) function to keep your model, scheduler, or pipeline files private:

Copied

```
controlnet.push_to_hub("my-controlnet-model", private=True)
```

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

```
model = ControlNet.from_pretrained("your-namespace/my-controlnet-model", use_auth_token=True)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boinc-ai.gitbook.io/diffusers/using-diffusers/loading-and-hub/push-files-to-the-hub.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
