Skip to content

Commit 8571903

Browse files
committed
feedback
1 parent 582fca3 commit 8571903

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

docs/source/en/using-diffusers/other-formats.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ specific language governing permissions and limitations under the License.
1414

1515
[[open-in-colab]]
1616

17-
Diffusion models are saved in various file types and organized in different layouts. Diffusers stores model weights as safetensors files in a multifolder layout and it also supports loading files (like safetensors and ckpt files) from a single file layout which is commonly used in the diffusion ecosystem.
17+
Diffusion models are saved in various file types and organized in different layouts. Diffusers stores model weights as safetensors files in *Diffusers-multifolder* layout and it also supports loading files (like safetensors and ckpt files) from a *single-file* layout which is commonly used in the diffusion ecosystem.
1818

1919
Each layout has its own benefits and use cases, and this guide will show you how to load the different files and layouts, and how to convert them.
2020

2121
## Files
2222

2323
PyTorch model weights are typically saved with Python's [pickle](https://docs.python.org/3/library/pickle.html) utility as ckpt or bin files. However, pickle is not secure and pickled files may contain malicious code that can be executed. This vulnerability is a serious concern given the popularity of model sharing. To address this security issue, the [Safetensors](https://hf.co/docs/safetensors) library was developed as a secure alternative to pickle, which saves models as safetensors files.
2424

25-
### Safetensors
25+
### safetensors
2626

2727
> [!TIP]
28-
> Learn more about the design decisions and why Safetensors is the preferred file format for saving and loading model weights in the [Safetensors audited as really safe and becoming the default](https://blog.eleuther.ai/safetensors-security-audit/) blog post.
28+
> Learn more about the design decisions and why safetensor files are preferred for saving and loading model weights in the [Safetensors audited as really safe and becoming the default](https://blog.eleuther.ai/safetensors-security-audit/) blog post.
2929
3030
[Safetensors](https://hf.co/docs/safetensors) is a safe and fast file format for securely storing and loading tensors. Safetensors restricts the header size to limit certain types of attacks, supports lazy loading (useful for distributed setups), and has generally faster loading speeds.
3131

@@ -35,10 +35,10 @@ Make sure you have the [Safetensors](https://hf.co/docs/safetensors) library ins
3535
!pip install safetensors
3636
```
3737

38-
Safetensor stores weights in a safetensors file. Diffusers loads safetensors files by default if they're available and the Safetensors library is installed. There are two ways safetensors files can be organized:
38+
Safetensors stores weights in a safetensors file. Diffusers loads safetensors files by default if they're available and the Safetensors library is installed. There are two ways safetensors files can be organized:
3939

40-
1. all the model weights may be saved in a single file (check out the [WarriorMama777/OrangeMixs](https://hf.co/WarriorMama777/OrangeMixs/tree/main/Models/AbyssOrangeMix) repository as an example)
41-
2. there may be several separate safetensors files, one for each pipeline component (text encoder, UNet, VAE), organized in subfolders (check out the [runwayml/stable-diffusion-v1-5](https://hf.co/runwayml/stable-diffusion-v1-5/tree/main) repository as an example)
40+
1. Diffusers-multifolder layout: there may be several separate safetensors files, one for each pipeline component (text encoder, UNet, VAE), organized in subfolders (check out the [runwayml/stable-diffusion-v1-5](https://hf.co/runwayml/stable-diffusion-v1-5/tree/main) repository as an example)
41+
2. single-file layout: all the model weights may be saved in a single file (check out the [WarriorMama777/OrangeMixs](https://hf.co/WarriorMama777/OrangeMixs/tree/main/Models/AbyssOrangeMix) repository as an example)
4242

4343
<hfoptions id="safetensors">
4444
<hfoption id="multifolder">
@@ -124,11 +124,11 @@ pipeline = StableDiffusionPipeline.from_single_file(
124124

125125
## Storage layout
126126

127-
There are two ways model files are organized, either in a multifolder layout or in a single file layout. Diffusers uses the multifolder layout by default where each component file (text encoder, UNet, VAE) is stored in a separate subfolder. Diffusers also supports loading models from a single file layout where all the components are bundled together.
127+
There are two ways model files are organized, either in a Diffusers-multifolder layout or in a single-file layout. The Diffusers-multifolder layout is the default, and each component file (text encoder, UNet, VAE) is stored in a separate subfolder. Diffusers also supports loading models from a single-file layout where all the components are bundled together.
128128

129-
### Multifolder
129+
### Diffusers-multifolder
130130

131-
The multifolder layout is the default storage layout for Diffusers. Each component's (text encoder, UNet, VAE) weights are stored in a separate subfolder. The weights can be stored as safetensors or ckpt files.
131+
The Diffusers-multifolder layout is the default storage layout for Diffusers. Each component's (text encoder, UNet, VAE) weights are stored in a separate subfolder. The weights can be stored as safetensors or ckpt files.
132132

133133
<div class="flex flex-row gap-4">
134134
<div class="flex-1">
@@ -141,7 +141,7 @@ The multifolder layout is the default storage layout for Diffusers. Each compone
141141
</div>
142142
</div>
143143

144-
To load from a multifolder layout, use the [`~DiffusionPipeline.from_pretrained`] method.
144+
To load from Diffusers-multifolder layout, use the [`~DiffusionPipeline.from_pretrained`] method.
145145

146146
```py
147147
from diffusers import DiffusionPipeline
@@ -154,7 +154,7 @@ pipeline = DiffusionPipeline.from_pretrained(
154154
).to("cuda")
155155
```
156156

157-
Benefits of using the multifolder layout include:
157+
Benefits of using the Diffusers-multifolder layout include:
158158

159159
1. Faster to load each component file individually or in parallel.
160160
2. Reduced memory usage because you only load the components you need. For example, models like [SDXL Turbo](https://hf.co/stabilityai/sdxl-turbo), [SDXL Lightning](https://hf.co/ByteDance/SDXL-Lightning), and [Hyper-SD](https://hf.co/ByteDance/Hyper-SD) have the same components except for the UNet. You can reuse their shared components with the [`~DiffusionPipeline.from_pipe`] method without consuming any additional memory (take a look at the [Reuse a pipeline](./loading#reuse-a-pipeline) guide) and only load the UNet. This way, you don't need to download redundant components and unnecessarily use more memory.
@@ -213,15 +213,15 @@ Benefits of using the multifolder layout include:
213213

214214
5. More visibility and information about a model's components, which are stored in a [config.json](https://hf.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/unet/config.json) file in each component subfolder.
215215

216-
### Single file
216+
### Single-file
217217

218-
The single file layout stores all the model weights in a single file. All the model components (text encoder, UNet, VAE) weights are kept together instead of separately in subfolders. This can be a safetensors or ckpt file.
218+
The single-file layout stores all the model weights in a single file. All the model components (text encoder, UNet, VAE) weights are kept together instead of separately in subfolders. This can be a safetensors or ckpt file.
219219

220220
<div class="flex justify-center">
221221
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/single-file-layout.png"/>
222222
</div>
223223

224-
To load from a single file layout, use the [`~loaders.FromSingleFileMixin.from_single_file`] method.
224+
To load from a single-file layout, use the [`~loaders.FromSingleFileMixin.from_single_file`] method.
225225

226226
```py
227227
import torch
@@ -235,9 +235,9 @@ pipeline = StableDiffusionXLPipeline.from_single_file(
235235
).to("cuda")
236236
```
237237

238-
Benefits of using a single file layout include:
238+
Benefits of using a single-file layout include:
239239

240-
1. Easy compatibility with diffusion interfaces such as [ComfyUI](https://github.com/comfyanonymous/ComfyUI) or [Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) which commonly use a single file layout.
240+
1. Easy compatibility with diffusion interfaces such as [ComfyUI](https://github.com/comfyanonymous/ComfyUI) or [Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) which commonly use a single-file layout.
241241
2. Easier to manage (download and share) a single file.
242242

243243
## Convert layout and files
@@ -247,15 +247,15 @@ Diffusers provides many scripts and methods to convert storage layouts and file
247247
Take a look at the [diffusers/scripts](https://github.com/huggingface/diffusers/tree/main/scripts) collection to find a script that fits your conversion needs.
248248

249249
> [!TIP]
250-
> Scripts that have "`to_diffusers`" appended at the end mean they convert a model to the multifolder format used by Diffusers. Each script has their own specific set of arguments for configuring the conversion, so make sure you check what arguments are available!
250+
> Scripts that have "`to_diffusers`" appended at the end mean they convert a model to the Diffusers-multifolder layout. Each script has their own specific set of arguments for configuring the conversion, so make sure you check what arguments are available!
251251
252-
For example, to convert a Stable Diffusion XL model stored in Diffusers multifolder format to a single file type, run the [convert_diffusers_to_original_sdxl.py](https://github.com/huggingface/diffusers/blob/main/scripts/convert_diffusers_to_original_sdxl.py) script. Provide the path to the model to convert, and the path to save the converted model to. You can optionally specify whether you want to save the model as a safetensors file and whether to save the model in half-precision.
252+
For example, to convert a Stable Diffusion XL model stored in Diffusers-multifolder layout to a single-file layout, run the [convert_diffusers_to_original_sdxl.py](https://github.com/huggingface/diffusers/blob/main/scripts/convert_diffusers_to_original_sdxl.py) script. Provide the path to the model to convert, and the path to save the converted model to. You can optionally specify whether you want to save the model as a safetensors file and whether to save the model in half-precision.
253253

254254
```bash
255255
python convert_diffusers_to_original_sdxl.py --model_path path/to/model/to/convert --checkpoint_path path/to/save/model/to --use_safetensors
256256
```
257257

258-
You can also save a model to the multifolder format with the [`~DiffusionPipeline.save_pretrained`] method. This creates a directory for you if it doesn't already exist, and it also saves the files as a safetensors file by default.
258+
You can also save a model to Diffusers-multifolder layout with the [`~DiffusionPipeline.save_pretrained`] method. This creates a directory for you if it doesn't already exist, and it also saves the files as a safetensors file by default.
259259

260260
```py
261261
from diffusers import StableDiffusionXLPipeline
@@ -266,4 +266,4 @@ pipeline = StableDiffusionXLPipeline.from_single_file(
266266
pipeline.save_pretrained()
267267
```
268268

269-
Lastly, there are also Spaces, such as [SD To Diffusers](https://hf.co/spaces/diffusers/sd-to-diffusers) and [SD-XL To Diffusers](https://hf.co/spaces/diffusers/sdxl-to-diffusers), that provide a more user-friendly interface for converting models to the multifolder format. This is the easiest and most convenient option for converting layouts, and it'll open a PR on your model repository with the converted files. However, this option is not as reliable as running a script, and the Space may fail for more complicated models.
269+
Lastly, there are also Spaces, such as [SD To Diffusers](https://hf.co/spaces/diffusers/sd-to-diffusers) and [SD-XL To Diffusers](https://hf.co/spaces/diffusers/sdxl-to-diffusers), that provide a more user-friendly interface for converting models to Diffusers-multifolder layout. This is the easiest and most convenient option for converting layouts, and it'll open a PR on your model repository with the converted files. However, this option is not as reliable as running a script, and the Space may fail for more complicated models.

0 commit comments

Comments
 (0)