"vscode:/vscode.git/clone" did not exist on "162f3ccb01d9b31d21f1a1ae3d6cabbfe4079838"
installation.md 6.13 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.7.0+, and Flax. Follow the installation instructions below for the deep learning library you are using:
Patrick von Platen's avatar
Patrick von Platen committed
16

Steven Liu's avatar
Steven Liu committed
17
18
- [PyTorch](https://pytorch.org/get-started/locally/) installation instructions
- [Flax](https://flax.readthedocs.io/en/latest/) installation instructions
Patrick von Platen's avatar
Patrick von Platen committed
19

20
## Install with pip
Patrick von Platen's avatar
Patrick von Platen committed
21

22
23
You should install 🤗 Diffusers in a [virtual environment](https://docs.python.org/3/library/venv.html).
If you're unfamiliar with Python virtual environments, take a look at this [guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/).
24
A virtual environment makes it easier to manage different projects and avoid compatibility issues between dependencies.
25

Steven Liu's avatar
Steven Liu committed
26
27
28
29
Create a virtual environment with Python or [uv](https://docs.astral.sh/uv/) (refer to [Installation](https://docs.astral.sh/uv/getting-started/installation/) for installation instructions), a fast Rust-based Python package and project manager.

<hfoptions id="install">
<hfoption id="uv">
30
31

```bash
Steven Liu's avatar
Steven Liu committed
32
33
uv venv my-env
source my-env/bin/activate
34
35
```

Steven Liu's avatar
Steven Liu committed
36
37
</hfoption>
<hfoption id="Python">
38
39

```bash
Steven Liu's avatar
Steven Liu committed
40
41
python -m venv my-env
source my-env/bin/activate
Patrick von Platen's avatar
Patrick von Platen committed
42
```
43

Steven Liu's avatar
Steven Liu committed
44
45
46
47
</hfoption>
</hfoptions>

You should also install 🤗 Transformers because 🤗 Diffusers relies on its models.
48

49

50
51
<frameworkcontent>
<pt>
Steven Liu's avatar
Steven Liu committed
52
53
54
55
56
57
58
59
60

PyTorch only supports Python 3.8 - 3.11 on Windows. Install Diffusers with uv.

```bash
uv install diffusers["torch"] transformers
```

You can also install Diffusers with pip.

61
```bash
62
pip install diffusers["torch"] transformers
63
```
Steven Liu's avatar
Steven Liu committed
64

65
66
</pt>
<jax>
Steven Liu's avatar
Steven Liu committed
67
68
69
70
71
72
73
74
75

Install Diffusers with uv.

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

You can also install Diffusers with pip.

76
```bash
77
pip install diffusers["flax"] transformers
Patrick von Platen's avatar
Patrick von Platen committed
78
```
Steven Liu's avatar
Steven Liu committed
79

80
81
</jax>
</frameworkcontent>
Patrick von Platen's avatar
Patrick von Platen committed
82

83
84
85
86
87
88
89
90
## Install with conda

After activating your virtual environment, with `conda` (maintained by the community):

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

91
92
## Install from source

Steven Liu's avatar
Steven Liu committed
93
Before installing 🤗 Diffusers from source, make sure you have PyTorch and 🤗 Accelerate installed.
94

95
To install 🤗 Accelerate:
96
97
98
99
100

```bash
pip install accelerate
```

Steven Liu's avatar
Steven Liu committed
101
Then install 🤗 Diffusers from source:
102
103
104
105
106
107
108
109
110
111

```bash
pip install git+https://github.com/huggingface/diffusers
```

This command installs the bleeding edge `main` version rather than the latest `stable` version.
The `main` version is useful for staying up-to-date with the latest developments.
For instance, if a bug has been fixed since the last official release but a new release hasn't been rolled out yet.
However, this means the `main` version may not always be stable.
We strive to keep the `main` version operational, and most issues are usually resolved within a few hours or a day.
Steven Liu's avatar
Steven Liu committed
112
If you run into a problem, please open an [Issue](https://github.com/huggingface/diffusers/issues/new/choose) so we can fix it even sooner!
113
114
115
116
117
118
119
120
121
122
123
124

## Editable install

You will need an editable install if you'd like to:

* Use the `main` version of the source code.
* Contribute to 🤗 Diffusers and need to test changes in the code.

Clone the repository and install 🤗 Diffusers with the following commands:

```bash
git clone https://github.com/huggingface/diffusers.git
Partho's avatar
Partho committed
125
cd diffusers
126
127
```

128
129
130
<frameworkcontent>
<pt>
```bash
131
132
pip install -e ".[torch]"
```
133
134
135
</pt>
<jax>
```bash
136
pip install -e ".[flax]"
137
```
138
139
</jax>
</frameworkcontent>
140
141
142

These commands will link the folder you cloned the repository to and your Python library paths.
Python will now look inside the folder you cloned to in addition to the normal library paths.
143
For example, if your Python packages are typically installed in `~/anaconda3/envs/main/lib/python3.10/site-packages/`, Python will also search the `~/diffusers/` folder you cloned to.
Patrick von Platen's avatar
Patrick von Platen committed
144

145
<Tip warning={true}>
Patrick von Platen's avatar
Patrick von Platen committed
146

147
You must keep the `diffusers` folder if you want to keep using the library.
Patrick von Platen's avatar
Patrick von Platen committed
148

149
</Tip>
Patrick von Platen's avatar
Patrick von Platen committed
150

151
152
153
154
155
156
Now you can easily update your clone to the latest version of 🤗 Diffusers with the following command:

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

158
Your Python environment will find the `main` version of 🤗 Diffusers on the next run.
159

Steven Liu's avatar
Steven Liu committed
160
161
162
163
## Cache

Model weights and files are downloaded from the Hub to a cache which is usually your home directory. You can change the cache location by specifying the `HF_HOME` or `HUGGINFACE_HUB_CACHE` environment variables or configuring the `cache_dir` parameter in methods like [`~DiffusionPipeline.from_pretrained`].

164
Cached files allow you to run 🤗 Diffusers offline. To prevent 🤗 Diffusers from connecting to the internet, set the `HF_HUB_OFFLINE` environment variable to `1` and 🤗 Diffusers will only load previously downloaded files in the cache.
Steven Liu's avatar
Steven Liu committed
165
166

```shell
167
export HF_HUB_OFFLINE=1
Steven Liu's avatar
Steven Liu committed
168
169
170
171
172
```

For more details about managing and cleaning the cache, take a look at the [caching](https://huggingface.co/docs/huggingface_hub/guides/manage-cache) guide.

## Telemetry logging
173

Steven Liu's avatar
Steven Liu committed
174
175
176
Our library gathers telemetry information during [`~DiffusionPipeline.from_pretrained`] requests.
The data gathered includes the version of 🤗 Diffusers and PyTorch/Flax, the requested model or pipeline class,
and the path to a pretrained checkpoint if it is hosted on the Hugging Face Hub.
177
This usage data helps us debug issues and prioritize new features.
Steven Liu's avatar
Steven Liu committed
178
179
Telemetry is only sent when loading models and pipelines from the Hub,
and it is not collected if you're loading local files.
180

Steven Liu's avatar
Steven Liu committed
181
We understand that not everyone wants to share additional information,and we respect your privacy.
182
You can disable telemetry collection by setting the `HF_HUB_DISABLE_TELEMETRY` environment variable from your terminal:
183
184

On Linux/MacOS:
185

186
```bash
187
export HF_HUB_DISABLE_TELEMETRY=1
188
189
190
```

On Windows:
191

192
```bash
193
set HF_HUB_DISABLE_TELEMETRY=1
194
```