diff --git a/docs/source/index.rst b/docs/source/index.rst index af5576d..3d182dd 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -17,7 +17,6 @@ DiffSynth-Studio 文档 tutorial/DownloadModels.md tutorial/Models.md tutorial/Pipelines.md - tutorial/PromptProcessing.md tutorial/Extensions.md tutorial/Schedulers.md diff --git a/docs/source/tutorial/ASimpleExample.md b/docs/source/tutorial/ASimpleExample.md index 8d80852..3062e47 100644 --- a/docs/source/tutorial/ASimpleExample.md +++ b/docs/source/tutorial/ASimpleExample.md @@ -17,25 +17,19 @@ pip install -e . 通过运行以下代码,我们将会下载模型、加载模型、生成图像。 ```python -import torch -from diffsynth import ModelManager, FluxImagePipeline +from diffsynth import ModelManager, SDXLImagePipeline -model_manager = ModelManager( - torch_dtype=torch.bfloat16, - device="cuda", - model_id_list=["FLUX.1-dev"] -) -pipe = FluxImagePipeline.from_model_manager(model_manager) +model_manager = ModelManager(device="cuda", model_id_list=["StableDiffusionXL_v1"]) +pipe = SDXLImagePipeline.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, + prompt="Diffuse light particles in the universe", + height=576, width=1024, seed=0 ) image.save("image.jpg") ``` -![image](https://github.com/user-attachments/assets/15a52a2b-2f18-46fe-810c-cb3ad2853919) +![image](https://github.com/user-attachments/assets/2e60d18e-534c-43d6-b875-26db5b05442e) 从这个例子中,我们可以看到,DiffSynth 中有两个关键模块:`ModelManager` 和 `Pipeline`,接下来我们详细介绍。 @@ -44,30 +38,19 @@ image.save("image.jpg") `ModelManager` 负责下载和加载模型,通过以下代码可以直接一步完成。 ```python -import torch -from diffsynth import ModelManager +from diffsynth import ModelManager, SDXLImagePipeline -model_manager = ModelManager( - torch_dtype=torch.bfloat16, - device="cuda", - model_id_list=["FLUX.1-dev"] -) +model_manager = ModelManager(device="cuda", model_id_list=["StableDiffusionXL_v1"]) ``` 当然,我们也支持分步完成,以下代码和上述代码的行为是等价的。 ```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", - "models/FLUX/FLUX.1-dev/text_encoder_2", - "models/FLUX/FLUX.1-dev/ae.safetensors", - "models/FLUX/FLUX.1-dev/flux1-dev.safetensors" -]) +download_models(["StableDiffusionXL_v1"]) +model_manager = ModelManager(device="cuda") +model_manager.load_models(["models/stable_diffusion_xl/sd_xl_base_1.0.safetensors"]) ``` 下载模型时,我们支持从 [ModelScope](https://www.modelscope.cn/) 和 [HuggingFace](https://huggingface.co/) 下载模型,也支持下载非预置的模型,关于模型下载的更多信息请参考[模型下载](./DownloadModels.md)。 @@ -76,10 +59,10 @@ model_manager.load_models([ ## 构建 Pipeline -DiffSynth-Studio 提供了多个推理 `Pipeline`,这些 `Pipeline` 可以直接通过 `ModelManager` 获取所需的模型并初始化。例如,FLUX.1-dev 模型的文生图 `Pipeline` 可以这样构建: +DiffSynth-Studio 提供了多个推理 `Pipeline`,这些 `Pipeline` 可以直接通过 `ModelManager` 获取所需的模型并初始化。例如,Kolors(可图)模型的文生图 `Pipeline` 可以这样构建: ```python -pipe = FluxImagePipeline.from_model_manager(model_manager) +pipe = SDXLImagePipeline.from_model_manager(model_manager) ``` 更多用于图像生成和视频生成的 `Pipeline` 详见[推理流水线](./Pipelines.md)。 diff --git a/docs/source/tutorial/DownloadModels.md b/docs/source/tutorial/DownloadModels.md index 7ed9173..125a847 100644 --- a/docs/source/tutorial/DownloadModels.md +++ b/docs/source/tutorial/DownloadModels.md @@ -4,7 +4,7 @@ ## 下载预置模型 -你可以直接使用 `download_models` 函数下载预置的模型文件,其中模型 ID 可参考 [config file](/diffsynth/configs/model_config.py)。 +你可以直接使用 `download_models` 函数下载预置的模型文件,其中模型 ID 可参考 [config file](https://github.com/modelscope/DiffSynth-Studio/blob/main/diffsynth/configs/model_config.py)。 ```python from diffsynth import download_models diff --git a/docs/source/tutorial/Installation.md b/docs/source/tutorial/Installation.md index 3831cd2..b37f98f 100644 --- a/docs/source/tutorial/Installation.md +++ b/docs/source/tutorial/Installation.md @@ -19,7 +19,7 @@ ## 使用 PyPI 下载 -直接通过 PyPI 安装(功能更新存在延后): +直接通过 PyPI 安装(功能更新存在延后,不建议使用这种方式): ```bash pip install diffsynth diff --git a/docs/source/tutorial/PromptProcessing.md b/docs/source/tutorial/PromptProcessing.md deleted file mode 100644 index 7356ba3..0000000 --- a/docs/source/tutorial/PromptProcessing.md +++ /dev/null @@ -1,37 +0,0 @@ -# 提示词处理 - -DiffSynth 内置了提示词处理功能,分为: - -- **提示词润色器(`prompt_refiner_classes`)**:包括提示词润色、提示词中译英、提示词同时润色与中译英,可选参数如下: - - - **英文提示词润色**:'BeautifulPrompt',使用到的是[pai-bloom-1b1-text2prompt-sd](https://modelscope.cn/models/AI-ModelScope/pai-bloom-1b1-text2prompt-sd)。 - - - **提示词中译英**:'Translator',使用到的是[opus-mt-zh-e](https://modelscope.cn/models/moxying/opus-mt-zh-en)。 - - - **提示词中译英并润色**:'QwenPrompt',使用到的是[Qwen2-1.5B-Instruct](https://modelscope.cn/models/qwen/Qwen2-1.5B-Instruct)。 - -- **提示词扩展器(`prompt_extender_classes`)**:基于Omost的提示词分区控制扩写,可选参数如下: - - - **提示词分区扩写**:'OmostPromter'。 - - -## 使用说明 - -### 提示词润色器 - -在加载模型 Pipeline 时,可以通过参数 `prompt_refiner_classes` 指定所需的提示词润色器功能。有关示例代码,请参考 [sd_prompt_refining.py](examples/image_synthesis/sd_prompt_refining.py)。 - -可选的 `prompt_refiner_classes` 参数包括:Translator、BeautifulPrompt、QwenPrompt。 - -```python -pipe = SDXLImagePipeline.from_model_manager(model_manager, prompt_refiner_classes=[Translator, BeautifulPrompt]) -``` - -### 提示词扩展器 - -在加载模型 Pipeline 时,可以通过参数 `prompt_extender_classes` 指定所需的提示词扩展器。有关示例代码,请参考 [omost_flux_text_to_image.py](examples/image_synthesis/omost_flux_text_to_image.py)。 - -```python -pipe = FluxImagePipeline.from_model_manager(model_manager, prompt_extender_classes=[OmostPromter]) -``` -