Skip to content

Commit 4e09363

Browse files
authored
Feature/no default lora (#137)
* update qwen image doc * fix tutorial_zh resolutions * support no default lora key * ruff format * fix typo
1 parent 7a6d86d commit 4e09363

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

diffsynth_engine/pipelines/qwen_image.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,32 @@ def _from_diffsynth(self, lora_state_dict: Dict[str, torch.Tensor]) -> Dict[str,
4141
dit_dict = {}
4242
for key, param in lora_state_dict.items():
4343
origin_key = key
44-
if "lora_A.default.weight" not in key:
44+
lora_a_suffix = None
45+
if "lora_A.default.weight" in key:
46+
lora_a_suffix = "lora_A.default.weight"
47+
elif "lora_A.weight" in key:
48+
lora_a_suffix = "lora_A.weight"
49+
50+
if lora_a_suffix is None:
4551
continue
52+
4653
lora_args = {}
4754
lora_args["down"] = param
48-
lora_args["up"] = lora_state_dict[origin_key.replace("lora_A.default.weight", "lora_B.default.weight")]
55+
56+
lora_b_suffix = lora_a_suffix.replace("lora_A", "lora_B")
57+
lora_args["up"] = lora_state_dict[origin_key.replace(lora_a_suffix, lora_b_suffix)]
58+
4959
lora_args["rank"] = lora_args["up"].shape[1]
50-
alpha_key = origin_key.replace("lora_A.default.weight", "alpha").replace("lora_up.default.weight", "alpha")
60+
alpha_key = origin_key.replace("lora_up", "lora_A").replace(lora_a_suffix, "alpha")
61+
5162
if alpha_key in lora_state_dict:
5263
alpha = lora_state_dict[alpha_key]
5364
else:
5465
alpha = lora_args["rank"]
5566
lora_args["alpha"] = alpha
56-
key = key.replace(".lora_A.default.weight", "")
67+
68+
key = key.replace(f".{lora_a_suffix}", "")
69+
5770
if key.startswith("transformer") and "attn.to_out.0" in key:
5871
key = key.replace("attn.to_out.0", "attn.to_out")
5972
dit_dict[key] = lora_args

docs/tutorial.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ We will continuously update DiffSynth-Engine to support more models. (Wan2.2 LoR
8888

8989
After the model is downloaded, load the model with the corresponding pipeline and perform inference.
9090

91-
9291
### Image Generation(Qwen-Image)
9392

9493
The following code calls `QwenImagePipeline` to load the [Qwen-Image](https://www.modelscope.cn/models/Qwen/Qwen-Image) model and generate an image. Recommended resolutions are 928×1664, 1104×1472, 1328×1328, 1472×1104, and 1664×928, with a suggested cfg_scale of 4. If no negative_prompt is provided, it defaults to a single space character (not an empty string). For multi-GPU parallelism, currently only cfg parallelism is supported (parallelism=2), with other optimization efforts underway.
@@ -122,7 +121,7 @@ image.save("image.png")
122121

123122
Please note that if some necessary modules, like text encoders, are missing from a model repository, the pipeline will automatically download the required files.
124123

125-
#### Detailed Parameters(Qwen-Image)
124+
### Detailed Parameters(Qwen-Image)
126125

127126
In the image generation pipeline `pipe`, we can use the following parameters for fine-grained control:
128127

docs/tutorial_zh.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## 安装
44

5-
在使用 DiffSynth-Engine 前,请先确保您的硬件设备满足以下要求
5+
在使用 DiffSynth-Engine 前,请先确保您的硬件设备满足以下要求:
66

77
* NVIDIA GPU CUDA 计算能力 8.6+(例如 RTX 50 Series、RTX 40 Series、RTX 30 Series 等,详见 [NVidia 文档](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#compute-capabilities))或 Apple Silicon M 系列芯片
88

9-
以及 Python 环境需求Python 3.10+。
9+
以及 Python 环境需求: Python 3.10+。
1010

11-
使用 `pip3` 工具从 PyPI 安装 DiffSynth-Engine
11+
使用 `pip3` 工具从 PyPI 安装 DiffSynth-Engine:
1212

1313
```shell
1414
pip3 install diffsynth-engine
@@ -64,7 +64,7 @@ model_path = fetch_model("Wan-AI/Wan2.1-T2V-14B", path="diffusion_pytorch_model*
6464

6565
## 模型类型
6666

67-
Diffusion 模型包含多种多样的模型结构,每种模型由对应的流水线进行加载和推理,目前我们支持的模型类型包括
67+
Diffusion 模型包含多种多样的模型结构,每种模型由对应的流水线进行加载和推理,目前我们支持的模型类型包括:
6868

6969
| 模型结构 | 样例 | 流水线 |
7070
| --------------- | ------------------------------------------------------------ | ------------------- |
@@ -123,16 +123,17 @@ image.save("image.png")
123123

124124
#### 详细参数(Qwen-Image)
125125

126-
在图像生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制
126+
在图像生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制:
127127

128128
* `prompt`: 提示词,用于描述生成图像的内容,支持多种语言(中文/英文/日文等),例如“一只猫”/"a cat"/"庭を走る猫"。
129129
* `negative_prompt`: 负面提示词,用于描述不希望图像中出现的内容,例如“ugly”,默认为一个空格而不是空字符串, " "。
130-
* `cfg_scale`: [Classifier-free guidance](https://arxiv.org/abs/2207.12598) 的引导系数,通常更大的引导系数可以达到更强的文图相关性,但会降低生成内容的多样性,推荐值为4。
130+
* `cfg_scale`:[Classifier-free guidance](https://arxiv.org/abs/2207.12598) 的引导系数,通常更大的引导系数可以达到更强的文图相关性,但会降低生成内容的多样性,推荐值为4。
131131
* `height`: 图像高度。
132132
* `width`: 图像宽度。
133133
* `num_inference_steps`: 推理步数,通常推理步数越多,计算时间越长,图像质量越高。
134134
* `seed`: 随机种子,固定的随机种子可以使生成的内容固定。
135135

136+
136137
### 图像生成
137138

138139
以下代码可以调用 `FluxImagePipeline` 加载[麦橘超然](https://www.modelscope.cn/models/MAILAND/majicflus_v1/summary?version=v1.0)模型生成一张图。如果要加载其他结构的模型,请将代码中的 `FluxImagePipeline``FluxPipelineConfig` 替换成对应的流水线模块及配置。
@@ -152,7 +153,7 @@ image.save("image.png")
152153

153154
#### 详细参数
154155

155-
在图像生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制
156+
在图像生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制:
156157

157158
* `prompt`: 提示词,用于描述生成图像的内容,例如“a cat”。
158159
* `negative_prompt`: 负面提示词,用于描述不希望图像中出现的内容,例如“ugly”。
@@ -217,7 +218,7 @@ save_video(video, "video.mp4")
217218

218219
#### 详细参数
219220

220-
在视频生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制
221+
在视频生成流水线 `pipe` 中,我们可以通过以下参数进行精细的控制:
221222

222223
* `prompt`: 提示词,用于描述生成图像的内容,例如“a cat”。
223224
* `negative_prompt`: 负面提示词,用于描述不希望图像中出现的内容,例如“ugly”。

0 commit comments

Comments
 (0)