update docs

This commit is contained in:
Artiprocher
2024-10-08 21:18:35 +08:00
parent 677ecbf1d2
commit 55f1a10255
7 changed files with 185 additions and 47 deletions

View File

@@ -12,26 +12,55 @@ cd DiffSynth-Studio
pip install -e .
```
## 下载模型
## 一键运行!
我们在 DiffSynth-Studio 中预置了一些主流 Diffusion 模型的下载链接,你可以直接使用 `download_models` 函数下载预置的模型文件
通过运行以下代码,我们将会下载模型、加载模型、生成图像
```python
from diffsynth import download_models
import torch
from diffsynth import ModelManager, FluxImagePipeline
download_models(["FLUX.1-dev"])
model_manager = ModelManager(
torch_dtype=torch.bfloat16,
device="cuda",
model_id_list=["FLUX.1-dev"]
)
pipe = FluxImagePipeline.from_model_manager(model_manager)
torch.manual_seed(0)
image = pipe(
prompt="In a forest, a wooden plank sign reading DiffSynth",
height=576, width=1024,
)
image.save("image.jpg")
```
我们支持从 [ModelScope](https://www.modelscope.cn/) 和 [HuggingFace](https://huggingface.co/) 下载模型,也支持下载非预置的模型,请参考[模型下载](./DownloadModels.md)
![image](https://github.com/user-attachments/assets/15a52a2b-2f18-46fe-810c-cb3ad2853919)
## 加载模型
从这个例子中我们可以看到DiffSynth 中有两个关键模块:`ModelManager``Pipeline`,接下来我们详细介绍。
在 DiffSynth-Studio 中,模型由统一的 `ModelManager` 维护。以 FLUX.1-dev 模型为例,模型包括两个文本编码器、一个 DiT、一个 VAE使用方式如下所示
## 下载和加载模型
`ModelManager` 负责下载和加载模型,通过以下代码可以直接一步完成。
```python
import torch
from diffsynth import ModelManager
model_manager = ModelManager(
torch_dtype=torch.bfloat16,
device="cuda",
model_id_list=["FLUX.1-dev"]
)
```
当然,我们也支持分步完成,以下代码和上述代码的行为是等价的。
```python
import torch
from diffsynth import download_models, ModelManager
download_models(["FLUX.1-dev"])
model_manager = ModelManager(torch_dtype=torch.bfloat16, device="cuda")
model_manager.load_models([
"models/FLUX/FLUX.1-dev/text_encoder/model.safetensors",
@@ -41,7 +70,9 @@ model_manager.load_models([
])
```
你可以把所有想要加载的模型路径放入其中。对于 `.safetensors` 等格式的模型权重文件,`ModelManager` 在加载后会自动判断模型类型;对于文件夹格式的模型,`ModelManager` 会尝试解析其中的 `config.json` 文件并尝试调用 `transformers` 等第三方库中的对应模块。关于 DiffSynth-Studio 支持的模型,请参考[支持的模型](./Models.md)。
下载模型时,我们支持从 [ModelScope](https://www.modelscope.cn/) 和 [HuggingFace](https://huggingface.co/) 下载模型,也支持下载非预置的模型,关于模型下载的更多信息请参考[模型下载](./DownloadModels.md)。
加载模型时,你可以把所有想要加载的模型路径放入其中。对于 `.safetensors` 等格式的模型权重文件,`ModelManager` 在加载后会自动判断模型类型;对于文件夹格式的模型,`ModelManager` 会尝试解析其中的 `config.json` 文件并尝试调用 `transformers` 等第三方库中的对应模块。关于 DiffSynth-Studio 支持的模型,请参考[支持的模型](./Models.md)。
## 构建 Pipeline
@@ -52,30 +83,3 @@ pipe = FluxImagePipeline.from_model_manager(model_manager)
```
更多用于图像生成和视频生成的 `Pipeline` 详见[推理流水线](./Pipelines.md)。
## 生成!
写好你的提示词,交给 DiffSynth-Studio启动生成任务吧
```python
import torch
from diffsynth import ModelManager, FluxImagePipeline
model_manager = ModelManager(torch_dtype=torch.bfloat16, device="cuda")
model_manager.load_models([
"models/FLUX/FLUX.1-dev/text_encoder/model.safetensors",
"models/FLUX/FLUX.1-dev/text_encoder_2",
"models/FLUX/FLUX.1-dev/ae.safetensors",
"models/FLUX/FLUX.1-dev/flux1-dev.safetensors"
])
pipe = FluxImagePipeline.from_model_manager(model_manager)
torch.manual_seed(0)
image = pipe(
prompt="In a forest, a wooden plank sign reading DiffSynth",
height=576, width=1024
)
image.save("image.jpg")
```
![image](https://github.com/user-attachments/assets/15a52a2b-2f18-46fe-810c-cb3ad2853919)