mirror of
https://github.com/huggingface/diffusers.git
synced 2026-10-26 08:59:24 +03:00
182 lines
6.4 KiB
Markdown
182 lines
6.4 KiB
Markdown
<!--Copyright 2025 The HuggingFace Team. All rights reserved.
|
|
|
|
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.
|
|
-->
|
|
|
|
# Installation
|
|
|
|
Diffusers requires Python 3.10+ and is tested with PyTorch 2.6+. Install [PyTorch](https://pytorch.org/get-started/locally/) according to your system and setup.
|
|
|
|
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.
|
|
|
|
```bash
|
|
uv venv my-env
|
|
source my-env/bin/activate
|
|
```
|
|
|
|
Install Diffusers with one of the following methods.
|
|
|
|
<hfoptions id="install">
|
|
<hfoption id="pip">
|
|
|
|
```bash
|
|
uv pip install diffusers["torch"] transformers
|
|
```
|
|
|
|
</hfoption>
|
|
<hfoption id="NVIDIA Spark (ARM64)">
|
|
|
|
To install Diffusers with PyTorch on NVIDIA Spark devices (such as an RTX Spark laptop) running ARM64, install PyTorch from the NVIDIA PyPI index. These devices require NVIDIA's ARM64 builds of PyTorch, which are not available on the default PyPI index or the standard PyTorch wheel index.
|
|
|
|
Run the command below to check if your system detects an NVIDIA GPU.
|
|
|
|
```bash
|
|
nvidia-smi
|
|
```
|
|
|
|
Install PyTorch from the NVIDIA PyPI index, then install Diffusers.
|
|
|
|
```bash
|
|
uv pip install torch --index-url https://pypi.nvidia.com
|
|
uv pip install diffusers
|
|
```
|
|
|
|
</hfoption>
|
|
<hfoption id="conda">
|
|
|
|
```bash
|
|
conda install -c conda-forge diffusers
|
|
```
|
|
|
|
</hfoption>
|
|
<hfoption id="source">
|
|
|
|
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.
|
|
|
|
Make sure [Accelerate](https://huggingface.co/docs/accelerate/index) is installed.
|
|
|
|
```bash
|
|
uv pip install accelerate
|
|
```
|
|
|
|
Install Diffusers from source with the command below.
|
|
|
|
```bash
|
|
uv pip install git+https://github.com/huggingface/diffusers
|
|
```
|
|
|
|
</hfoption>
|
|
</hfoptions>
|
|
|
|
Install with extras when you need them. `diffusers["torch"]` pulls PyTorch and Accelerate. Other extras cover quantization backends, training, and docs. See [`setup.py`](https://github.com/huggingface/diffusers/blob/main/setup.py) for the full list.
|
|
|
|
## Devices
|
|
|
|
Diffusers runs on any accelerator supported by PyTorch. The examples throughout the docs use `"cuda"` because it is the most common setup, but nothing is CUDA-specific. Swap in the device string for your hardware, such as `"xpu"` for Intel GPUs, `"mps"` for Apple silicon, or `"cpu"`.
|
|
|
|
```py
|
|
device = "cuda" # or "mps", "xpu", "cpu"
|
|
pipeline.to(device)
|
|
```
|
|
|
|
To pick the device at runtime instead of hardcoding it, use [torch.accelerator](https://docs.pytorch.org/docs/stable/accelerator.html).
|
|
|
|
```py
|
|
import torch
|
|
|
|
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
|
|
```
|
|
|
|
## Editable install
|
|
|
|
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.
|
|
|
|
Clone the repository and install Diffusers with the following commands.
|
|
|
|
```bash
|
|
git clone https://github.com/huggingface/diffusers.git
|
|
cd diffusers
|
|
uv pip install -e ".[torch]"
|
|
```
|
|
|
|
> [!WARNING]
|
|
> You must keep the `diffusers` folder if you want to keep using the library with the editable install.
|
|
|
|
Update your cloned repository to the latest version of Diffusers with the command below.
|
|
|
|
```bash
|
|
cd ~/diffusers/
|
|
git pull
|
|
```
|
|
|
|
## Cache
|
|
|
|
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`].
|
|
|
|
<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.
|
|
|
|
```shell
|
|
export HF_HUB_OFFLINE=1
|
|
```
|
|
|
|
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.
|
|
|
|
## Telemetry logging
|
|
|
|
Diffusers gathers telemetry information during [`~DiffusionPipeline.from_pretrained`] requests.
|
|
The data gathered includes the Diffusers and PyTorch version, the requested model or pipeline class,
|
|
and the path to a pretrained checkpoint if it is hosted on the Hub.
|
|
|
|
This usage data helps us debug issues and prioritize new features.
|
|
Telemetry is only sent when loading models and pipelines from the Hub,
|
|
and it is not collected if you're loading local files.
|
|
|
|
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.
|
|
|
|
<hfoptions id="telemetry">
|
|
<hfoption id="Linux/macOS">
|
|
|
|
```bash
|
|
export HF_HUB_DISABLE_TELEMETRY=1
|
|
```
|
|
|
|
</hfoption>
|
|
<hfoption id="Windows">
|
|
|
|
```bash
|
|
set HF_HUB_DISABLE_TELEMETRY=1
|
|
```
|
|
|
|
</hfoption>
|
|
</hfoptions>
|