From 0e03797fd1794b76cdcb5d40b3f3739999d42a0e Mon Sep 17 00:00:00 2001 From: Artiprocher Date: Thu, 4 Dec 2025 14:43:04 +0800 Subject: [PATCH] update docs --- README.md | 7 +++++++ README_zh.md | 7 +++++++ diffsynth/core/loader/config.py | 20 +++++++++---------- .../Pipeline_Usage/Environment_Variables.md | 2 +- docs/en/Pipeline_Usage/Model_Inference.md | 4 ++-- .../Pipeline_Usage/Environment_Variables.md | 2 +- docs/zh/Pipeline_Usage/Model_Inference.md | 4 ++-- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d7f1575..294e952 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,13 @@ If you meet problems during installation, they might be caused by upstream depen DiffSynth-Studio redesigns the inference and training pipelines for mainstream Diffusion models (including FLUX, Wan, etc.), enabling efficient memory management and flexible model training. +> Before using model inference or training, you can configure the model download source via [environment variables](/docs/en/Pipeline_Usage/Environment_Variables.md). By default, this project downloads models from ModelScope. Users outside China can switch the download source to Hugging Face: +> +> ```python +> import os +> os.environ["DIFFSYNTH_DOWNLOAD_SOURCE"] = "huggingface" +> ``` + ### Image Synthesis ![Image](https://github.com/user-attachments/assets/c01258e2-f251-441a-aa1e-ebb22f02594d) diff --git a/README_zh.md b/README_zh.md index 724bd15..0ddf959 100644 --- a/README_zh.md +++ b/README_zh.md @@ -209,6 +209,13 @@ pip install diffsynth DiffSynth-Studio 为主流 Diffusion 模型(包括 FLUX、Wan 等)重新设计了推理和训练流水线,能够实现高效的显存管理、灵活的模型训练。 +> 在进行模型推理和训练前,可通过[环境变量](/docs/zh/Pipeline_Usage/Environment_Variables.md)配置模型下载源,本项目默认从魔搭社区下载模型,非中国用户可将模型下载源修改为 Huggingface: +> +> ```python +> import os +> os.environ["DIFFSYNTH_DOWNLOAD_SOURCE"] = "huggingface" +> ``` + ### 图像生成模型 ![Image](https://github.com/user-attachments/assets/c01258e2-f251-441a-aa1e-ebb22f02594d) diff --git a/diffsynth/core/loader/config.py b/diffsynth/core/loader/config.py index 673ff07..562675f 100644 --- a/diffsynth/core/loader/config.py +++ b/diffsynth/core/loader/config.py @@ -11,7 +11,7 @@ class ModelConfig: path: Union[str, list[str]] = None model_id: str = None origin_file_pattern: Union[str, list[str]] = None - download_resource: str = None + download_source: str = None local_model_path: str = None skip_download: bool = None offload_device: Optional[Union[str, torch.device]] = None @@ -36,14 +36,14 @@ class ModelConfig: else: return self.origin_file_pattern - def parse_download_resource(self): - if self.download_resource is None: - if os.environ.get('DIFFSYNTH_DOWNLOAD_RESOURCE') is not None: - return os.environ.get('DIFFSYNTH_DOWNLOAD_RESOURCE') + def parse_download_source(self): + if self.download_source is None: + if os.environ.get('DIFFSYNTH_DOWNLOAD_SOURCE') is not None: + return os.environ.get('DIFFSYNTH_DOWNLOAD_SOURCE') else: return "modelscope" else: - return self.download_resource + return self.download_source def parse_skip_download(self): if self.skip_download is None: @@ -60,8 +60,8 @@ class ModelConfig: def download(self): origin_file_pattern = self.parse_original_file_pattern() downloaded_files = glob.glob(origin_file_pattern, root_dir=os.path.join(self.local_model_path, self.model_id)) - download_resource = self.parse_download_resource() - if download_resource.lower() == "modelscope": + download_source = self.parse_download_source() + if download_source.lower() == "modelscope": snapshot_download( self.model_id, local_dir=os.path.join(self.local_model_path, self.model_id), @@ -69,7 +69,7 @@ class ModelConfig: ignore_file_pattern=downloaded_files, local_files_only=False ) - elif download_resource.lower() == "huggingface": + elif download_source.lower() == "huggingface": hf_snapshot_download( self.model_id, local_dir=os.path.join(self.local_model_path, self.model_id), @@ -78,7 +78,7 @@ class ModelConfig: local_files_only=False ) else: - raise ValueError("`download_resource` should be `modelscope` or `huggingface`.") + raise ValueError("`download_source` should be `modelscope` or `huggingface`.") def require_downloading(self): if self.path is not None: diff --git a/docs/en/Pipeline_Usage/Environment_Variables.md b/docs/en/Pipeline_Usage/Environment_Variables.md index 308bf16..91d016f 100644 --- a/docs/en/Pipeline_Usage/Environment_Variables.md +++ b/docs/en/Pipeline_Usage/Environment_Variables.md @@ -34,6 +34,6 @@ Attention mechanism implementation method. Can be set to `flash_attention_3`, `f Buffer size in disk mapping. Default is 1B (1000000000). Larger values occupy more memory but result in faster speeds. -## `DIFFSYNTH_DOWNLOAD_RESOURCE` +## `DIFFSYNTH_DOWNLOAD_SOURCE` Remote model download source. Can be set to `modelscope` or `huggingface` to control the source of model downloads. Default value is `modelscope`. \ No newline at end of file diff --git a/docs/en/Pipeline_Usage/Model_Inference.md b/docs/en/Pipeline_Usage/Model_Inference.md index 8901ee6..e5a85a0 100644 --- a/docs/en/Pipeline_Usage/Model_Inference.md +++ b/docs/en/Pipeline_Usage/Model_Inference.md @@ -69,11 +69,11 @@ os.environ["DIFFSYNTH_SKIP_DOWNLOAD"] = "True" import diffsynth ``` -To download models from [HuggingFace](https://huggingface.co/), set [environment variable DIFFSYNTH_DOWNLOAD_RESOURCE](/docs/en/Pipeline_Usage/Environment_Variables.md#diffsynth_download_resource) to `huggingface`. +To download models from [HuggingFace](https://huggingface.co/), set [environment variable DIFFSYNTH_DOWNLOAD_SOURCE](/docs/en/Pipeline_Usage/Environment_Variables.md#diffsynth_download_source) to `huggingface`. ```shell import os -os.environ["DIFFSYNTH_DOWNLOAD_RESOURCE"] = "huggingface" +os.environ["DIFFSYNTH_DOWNLOAD_SOURCE"] = "huggingface" import diffsynth ``` diff --git a/docs/zh/Pipeline_Usage/Environment_Variables.md b/docs/zh/Pipeline_Usage/Environment_Variables.md index 4e35e86..9c96fcc 100644 --- a/docs/zh/Pipeline_Usage/Environment_Variables.md +++ b/docs/zh/Pipeline_Usage/Environment_Variables.md @@ -34,6 +34,6 @@ DIFFSYNTH_MODEL_BASE_PATH="./path_to_my_models" python xxx.py 硬盘直连中的 Buffer 大小,默认是 1B(1000000000),数值越大,占用内存越大,速度越快。 -## `DIFFSYNTH_DOWNLOAD_RESOURCE` +## `DIFFSYNTH_DOWNLOAD_SOURCE` 远程模型下载源,可设置为 `modelscope` 或 `huggingface`,控制模型下载的来源,默认值为 `modelscope`。 diff --git a/docs/zh/Pipeline_Usage/Model_Inference.md b/docs/zh/Pipeline_Usage/Model_Inference.md index 3e658ba..75a1ed8 100644 --- a/docs/zh/Pipeline_Usage/Model_Inference.md +++ b/docs/zh/Pipeline_Usage/Model_Inference.md @@ -69,11 +69,11 @@ os.environ["DIFFSYNTH_SKIP_DOWNLOAD"] = "True" import diffsynth ``` -如需从 [HuggingFace](https://huggingface.co/) 下载模型,请将[环境变量 DIFFSYNTH_DOWNLOAD_RESOURCE](/docs/zh/Pipeline_Usage/Environment_Variables.md#diffsynth_download_resource) 设置为 `huggingface`。 +如需从 [HuggingFace](https://huggingface.co/) 下载模型,请将[环境变量 DIFFSYNTH_DOWNLOAD_SOURCE](/docs/zh/Pipeline_Usage/Environment_Variables.md#diffsynth_download_source) 设置为 `huggingface`。 ```shell import os -os.environ["DIFFSYNTH_DOWNLOAD_RESOURCE"] = "huggingface" +os.environ["DIFFSYNTH_DOWNLOAD_SOURCE"] = "huggingface" import diffsynth ```