installation.md 5.36 KB
Newer Older
Aryan's avatar
Aryan committed
1
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
Nathan Lambert's avatar
Nathan Lambert committed
2
3
4
5
6
7
8
9
10
11
12

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

13
# Installation
Patrick von Platen's avatar
Patrick von Platen committed
14

Steven Liu's avatar
Steven Liu committed
15
Diffusers is tested on Python 3.8+, PyTorch 1.4+, and Flax 0.4.1+. Follow the installation instructions for the deep learning library you're using, [PyTorch](https://pytorch.org/get-started/locally/) or [Flax](https://flax.readthedocs.io/en/latest/).
Patrick von Platen's avatar
Patrick von Platen committed
16

Steven Liu's avatar
Steven Liu committed
17
Create a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) for easier management of separate projects and to avoid compatibility issues between dependencies. Use [uv](https://docs.astral.sh/uv/), a Rust-based Python package and project manager, to create a virtual environment and install Diffusers.
18
19

```bash
Steven Liu's avatar
Steven Liu committed
20
21
uv venv my-env
source my-env/bin/activate
22
23
```

Steven Liu's avatar
Steven Liu committed
24
Install Diffusers with one of the following methods.
25

Steven Liu's avatar
Steven Liu committed
26
27
<hfoptions id="install">
<hfoption id="pip">
Steven Liu's avatar
Steven Liu committed
28

Steven Liu's avatar
Steven Liu committed
29
PyTorch only supports Python 3.8 - 3.11 on Windows.
Steven Liu's avatar
Steven Liu committed
30

31
```bash
Steven Liu's avatar
Steven Liu committed
32
uv pip install diffusers["torch"] transformers
33
```
Steven Liu's avatar
Steven Liu committed
34

Steven Liu's avatar
Steven Liu committed
35
Use the command below for Flax.
Steven Liu's avatar
Steven Liu committed
36
37
38
39
40

```bash
uv pip install diffusers["flax"] transformers
```

Steven Liu's avatar
Steven Liu committed
41
42
</hfoption>
<hfoption id="conda">
43
44
45
46
47

```bash
conda install -c conda-forge diffusers
```

Steven Liu's avatar
Steven Liu committed
48
49
</hfoption>
<hfoption id="source">
50

Steven Liu's avatar
Steven Liu committed
51
A source install installs the `main` version instead of the latest `stable` version. The `main` version is useful for staying updated with the latest changes but it may not always be stable. If you run into a problem, open an [Issue](https://github.com/huggingface/diffusers/issues/new/choose) and we will try to resolve it as soon as possible.
52

Steven Liu's avatar
Steven Liu committed
53
Make sure [Accelerate](https://huggingface.co/docs/accelerate/index) is installed.
54
55

```bash
Steven Liu's avatar
Steven Liu committed
56
uv pip install accelerate
57
58
```

Steven Liu's avatar
Steven Liu committed
59
Install Diffusers from source with the command below.
60
61

```bash
Steven Liu's avatar
Steven Liu committed
62
uv pip install git+https://github.com/huggingface/diffusers
63
64
```

Steven Liu's avatar
Steven Liu committed
65
66
</hfoption>
</hfoptions>
67
68
69

## Editable install

Steven Liu's avatar
Steven Liu committed
70
An editable install is recommended for development workflows or if you're using the `main` version of the source code. A special link is created between the cloned repository and the Python library paths. This avoids reinstalling a package after every change.
71

Steven Liu's avatar
Steven Liu committed
72
Clone the repository and install Diffusers with the following commands.
73

Steven Liu's avatar
Steven Liu committed
74
75
<hfoptions id="editable">
<hfoption id="PyTorch">
76
77
78

```bash
git clone https://github.com/huggingface/diffusers.git
Partho's avatar
Partho committed
79
cd diffusers
Steven Liu's avatar
Steven Liu committed
80
uv pip install -e ".[torch]"
81
82
```

Steven Liu's avatar
Steven Liu committed
83
84
85
</hfoption>
<hfoption id="Flax">

86
```bash
Steven Liu's avatar
Steven Liu committed
87
88
89
git clone https://github.com/huggingface/diffusers.git
cd diffusers
uv pip install -e ".[flax]"
90
```
Patrick von Platen's avatar
Patrick von Platen committed
91

Steven Liu's avatar
Steven Liu committed
92
93
</hfoption>
</hfoptions>
Patrick von Platen's avatar
Patrick von Platen committed
94

Steven Liu's avatar
Steven Liu committed
95
96
> [!WARNING]
> You must keep the `diffusers` folder if you want to keep using the library with the editable install.
Patrick von Platen's avatar
Patrick von Platen committed
97

Steven Liu's avatar
Steven Liu committed
98
Update your cloned repository to the latest version of Diffusers with the command below.
99
100
101
102
103

```bash
cd ~/diffusers/
git pull
```
Patrick von Platen's avatar
Patrick von Platen committed
104

Steven Liu's avatar
Steven Liu committed
105
106
## Cache

Steven Liu's avatar
Steven Liu committed
107
Model weights and files are downloaded from the Hub to a cache, which is usually your home directory. Change the cache location with the [HF_HOME](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhome) or [HF_HUB_CACHE](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhubcache) environment variables or configuring the `cache_dir` parameter in methods like [`~DiffusionPipeline.from_pretrained`].
Steven Liu's avatar
Steven Liu committed
108

Steven Liu's avatar
Steven Liu committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<hfoptions id="cache">
<hfoption id="env variable">

```bash
export HF_HOME="/path/to/your/cache"
export HF_HUB_CACHE="/path/to/your/hub/cache"
```

</hfoption>
<hfoption id="from_pretrained">

```py
from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    cache_dir="/path/to/your/cache"
)
```

</hfoption>
</hfoptions>

Cached files allow you to use Diffusers offline. Set the [HF_HUB_OFFLINE](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhuboffline) environment variable to `1` to prevent Diffusers from connecting to the internet.
Steven Liu's avatar
Steven Liu committed
133
134

```shell
135
export HF_HUB_OFFLINE=1
Steven Liu's avatar
Steven Liu committed
136
137
```

Steven Liu's avatar
Steven Liu committed
138
For more details about managing and cleaning the cache, take a look at the [Understand caching](https://huggingface.co/docs/huggingface_hub/guides/manage-cache) guide.
Steven Liu's avatar
Steven Liu committed
139
140

## Telemetry logging
141

Steven Liu's avatar
Steven Liu committed
142
143
144
145
Diffusers gathers telemetry information during [`~DiffusionPipeline.from_pretrained`] requests.
The data gathered includes the Diffusers and PyTorch/Flax version, the requested model or pipeline class,
and the path to a pretrained checkpoint if it is hosted on the Hub.

146
This usage data helps us debug issues and prioritize new features.
Steven Liu's avatar
Steven Liu committed
147
148
Telemetry is only sent when loading models and pipelines from the Hub,
and it is not collected if you're loading local files.
149

Steven Liu's avatar
Steven Liu committed
150
Opt-out and disable telemetry collection with the [HF_HUB_DISABLE_TELEMETRY](https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhubdisabletelemetry) environment variable.
151

Steven Liu's avatar
Steven Liu committed
152
153
<hfoptions id="telemetry">
<hfoption id="Linux/macOS">
154

155
```bash
156
export HF_HUB_DISABLE_TELEMETRY=1
157
158
```

Steven Liu's avatar
Steven Liu committed
159
160
</hfoption>
<hfoption id="Windows">
161

162
```bash
163
set HF_HUB_DISABLE_TELEMETRY=1
164
```
Steven Liu's avatar
Steven Liu committed
165
166
167

</hfoption>
</hfoptions>