# How to convert ckpt to diffusers format

**URL:** <https://discuss.huggingface.co/t/how-to-convert-ckpt-to-diffusers-format/35635>\
**Category:** 🧨 Diffusers\
**Created:** [April 5, 2023, 10:32am UTC](https://discuss.huggingface.co/t/how-to-convert-ckpt-to-diffusers-format/35635 "2023-04-05T10:32:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrickvonplaten](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/patrickvonplaten/32/2171_2.png) [@patrickvonplaten](https://discuss.huggingface.co/u/patrickvonplaten)\
**Post date:** [April 5, 2023, 10:32am UTC](https://discuss.huggingface.co/t/how-to-convert-ckpt-to-diffusers-format/35635/1 "2023-04-05T10:32:21Z")

</div>

The community is heavily using both the `.ckpt` and the diffusers format. We are working on having better support for interoperability between the formats, but the recommended approach is always to just upload checkpoints in both formats.

Let’s dive a bit into the best approach to convert .ckpt into diffusers format.

# Option 1.)

The easiest and most convenient approach is to just use a space to convert the checkpoint.  
You can just try it here: [SD To Diffusers - a Hugging Face Space by diffusers](https://huggingface.co/spaces/diffusers/sd-to-diffusers)

As soon as the model is a bit more customized this might however not work. In this case the space tends to open an empty PR or just fails. This means that the conversion didn’t work.

# Option 2.)

Option two is the more error-proof option and should always work.

1. Git clone the repo that has a `.ckpt` and where you want to convert the checkpoint from. E.g.:

```auto
git lfs install
git clone https://huggingface.co/CiaraRowles/TemporalNet

```

1. Open a pull request and follow the instructions

```auto
cd TemporalNet && git fetch origin refs/pr/13:pr/13

```

and

```auto
git checkout pr/14

```

1. Now convert the checkpoint. For this you need to have a local clone [diffusers](https://github.com/huggingface/diffusers) . Then we recommend to always use the [`https://github.com/huggingface/diffusers/blob/main/scripts/convert_original_stable_diffusion_to_diffusers.py`](https://github.com/huggingface/diffusers/blob/main/scripts/convert_original_stable_diffusion_to_diffusers.py) script.

You need to make sure to configure your input arguments correctly. We recommend to always pass the following parameters:

```auto
--original_config_file
--checkpoint_path
--dump_path

```

Let’s explain them a bit more in-detail:

`--dump_path` is just the path where the diffusers checkpoint will be save  
`--checkpoint_path` is the path to the `.ckpt` file to be converted. If multiple `.ckpt` files are present, we recommend to always use the _largest_ one  
`--original_config_file` - the original config file. This should be a file that ends with a `yaml` suffix. In case no file is present you should try to find the corresponding file in the github repo the `.ckpt` model originated from. Some examples:

- [stable-diffusion/configs/stable-diffusion at main · CompVis/stable-diffusion · GitHub](https://github.com/CompVis/stable-diffusion/tree/main/configs/stable-diffusion)
- [stablediffusion/configs/stable-diffusion at main · Stability-AI/stablediffusion · GitHub](https://github.com/Stability-AI/stablediffusion/tree/main/configs/stable-diffusion)
- [ControlNet/models at main · lllyasviel/ControlNet · GitHub](https://github.com/lllyasviel/ControlNet/tree/main/models)

We recommend to then convert the checkpoint directly into the cloned local repo. For our example above we used the following command. We took the `cldm_v15.yaml` config from [ControlNet/models at main · lllyasviel/ControlNet · GitHub](https://github.com/lllyasviel/ControlNet/tree/main/models) since we know that the model is a sd15 model and a controlnet model and because no config was present in the original repo

```auto
python ../diffusers/scripts/convert_original_stable_diffusion_to_diffusers.py --checkpoint_path temporalnetv3.ckpt --original_config_file cldm_v15.yaml --dump_path ./ --controlnet

```

1. Now we recommend that you test the converted checkpoint and then upload your changes to the PR:

```auto
git push origin pr/13:refs/pr/13

```

Done!

The resulting PR is here: [CiaraRowles/TemporalNet · Add diffusers weights](https://huggingface.co/CiaraRowles/TemporalNet/discussions/13)

---

<div class="post-metadata">

**Author:** ![vinesmsuic](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/vinesmsuic/32/17428_2.png) [@vinesmsuic](https://discuss.huggingface.co/u/vinesmsuic)\
**Post date:** [July 7, 2023, 10:28pm UTC](https://discuss.huggingface.co/t/how-to-convert-ckpt-to-diffusers-format/35635/2 "2023-07-07T22:28:02Z")

</div>

The link in Option1 gives a Runtime error

```auto
## Memory limit exceeded (16Gi)

```
