Skip to content

Commit 330c5f6

Browse files
committed
use InputParam/OutputParam templates and fix ruff
1 parent e439012 commit 330c5f6

6 files changed

Lines changed: 130 additions & 129 deletions

File tree

src/diffusers/modular_pipelines/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
HeliosPyramidDistilledModularPipeline,
125125
HeliosPyramidModularPipeline,
126126
)
127+
from .hunyuan_video1_5 import (
128+
HunyuanVideo15Blocks,
129+
HunyuanVideo15Image2VideoBlocks,
130+
HunyuanVideo15ModularPipeline,
131+
)
127132
from .modular_pipeline import (
128133
AutoPipelineBlocks,
129134
BlockState,
@@ -145,7 +150,6 @@
145150
QwenImageLayeredModularPipeline,
146151
QwenImageModularPipeline,
147152
)
148-
from .hunyuan_video1_5 import HunyuanVideo15Blocks, HunyuanVideo15Image2VideoBlocks, HunyuanVideo15ModularPipeline
149153
from .stable_diffusion_xl import StableDiffusionXLAutoBlocks, StableDiffusionXLModularPipeline
150154
from .wan import (
151155
Wan22Blocks,

src/diffusers/modular_pipelines/hunyuan_video1_5/before_denoise.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def expected_components(self) -> list[ComponentSpec]:
7676
@property
7777
def inputs(self) -> list[InputParam]:
7878
return [
79-
InputParam("num_videos_per_prompt", default=1),
80-
InputParam("prompt_embeds", required=True, type_hint=torch.Tensor),
81-
InputParam("batch_size", type_hint=int),
79+
InputParam.template("num_images_per_prompt", name="num_videos_per_prompt"),
80+
InputParam.template("prompt_embeds"),
81+
InputParam.template("batch_size", default=None),
8282
]
8383

8484
@property
@@ -111,8 +111,8 @@ def description(self) -> str:
111111
@property
112112
def inputs(self) -> list[InputParam]:
113113
return [
114-
InputParam("num_inference_steps", default=50),
115-
InputParam("sigmas"),
114+
InputParam.template("num_inference_steps"),
115+
InputParam.template("sigmas"),
116116
]
117117

118118
@property
@@ -150,20 +150,20 @@ def description(self) -> str:
150150
@property
151151
def inputs(self) -> list[InputParam]:
152152
return [
153-
InputParam("height", type_hint=int),
154-
InputParam("width", type_hint=int),
153+
InputParam.template("height"),
154+
InputParam.template("width"),
155155
InputParam("num_frames", type_hint=int, default=121),
156-
InputParam("latents", type_hint=torch.Tensor | None),
157-
InputParam("num_videos_per_prompt", type_hint=int, default=1),
158-
InputParam("generator"),
159-
InputParam("batch_size", required=True, type_hint=int),
160-
InputParam("dtype", type_hint=torch.dtype),
156+
InputParam.template("latents"),
157+
InputParam.template("num_images_per_prompt", name="num_videos_per_prompt"),
158+
InputParam.template("generator"),
159+
InputParam.template("batch_size", required=True, default=None),
160+
InputParam.template("dtype", default=None),
161161
]
162162

163163
@property
164164
def intermediate_outputs(self) -> list[OutputParam]:
165165
return [
166-
OutputParam("latents", type_hint=torch.Tensor),
166+
OutputParam.template("latents"),
167167
OutputParam("cond_latents_concat", type_hint=torch.Tensor),
168168
OutputParam("mask_concat", type_hint=torch.Tensor),
169169
OutputParam("image_embeds", type_hint=torch.Tensor),
@@ -265,19 +265,19 @@ def expected_components(self) -> list[ComponentSpec]:
265265
@property
266266
def inputs(self) -> list[InputParam]:
267267
return [
268-
InputParam("image", required=True),
268+
InputParam.template("image"),
269269
InputParam("num_frames", type_hint=int, default=121),
270-
InputParam("latents", type_hint=torch.Tensor | None),
271-
InputParam("num_videos_per_prompt", type_hint=int, default=1),
272-
InputParam("generator"),
273-
InputParam("batch_size", required=True, type_hint=int),
274-
InputParam("dtype", type_hint=torch.dtype),
270+
InputParam.template("latents"),
271+
InputParam.template("num_images_per_prompt", name="num_videos_per_prompt"),
272+
InputParam.template("generator"),
273+
InputParam.template("batch_size", required=True, default=None),
274+
InputParam.template("dtype", default=None),
275275
]
276276

277277
@property
278278
def intermediate_outputs(self) -> list[OutputParam]:
279279
return [
280-
OutputParam("latents", type_hint=torch.Tensor),
280+
OutputParam.template("latents"),
281281
OutputParam("cond_latents_concat", type_hint=torch.Tensor),
282282
OutputParam("mask_concat", type_hint=torch.Tensor),
283283
OutputParam("image_embeds", type_hint=torch.Tensor),

src/diffusers/modular_pipelines/hunyuan_video1_5/decoders.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any
1615

17-
import numpy as np
18-
import PIL
1916
import torch
2017

2118
from ...configuration_utils import FrozenDict
@@ -49,20 +46,16 @@ def description(self) -> str:
4946
return "Step that decodes the denoised latents into videos"
5047

5148
@property
52-
def inputs(self) -> list[tuple[str, Any]]:
49+
def inputs(self) -> list[InputParam]:
5350
return [
54-
InputParam("latents", required=True, type_hint=torch.Tensor),
55-
InputParam("output_type", default="np", type_hint=str),
51+
InputParam.template("latents", required=True),
52+
InputParam.template("output_type", default="np"),
5653
]
5754

5855
@property
5956
def intermediate_outputs(self) -> list[OutputParam]:
6057
return [
61-
OutputParam(
62-
"videos",
63-
type_hint=list[list[PIL.Image.Image]] | list[torch.Tensor] | list[np.ndarray],
64-
description="The generated videos",
65-
)
58+
OutputParam.template("videos"),
6659
]
6760

6861
# Copied from pipeline_hunyuan_video1_5.py lines 823-829

src/diffusers/modular_pipelines/hunyuan_video1_5/denoise.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def description(self) -> str:
4343
@property
4444
def inputs(self) -> list[InputParam]:
4545
return [
46-
InputParam("latents", required=True, type_hint=torch.Tensor),
46+
InputParam.template("latents", required=True),
4747
InputParam("cond_latents_concat", required=True, type_hint=torch.Tensor),
4848
InputParam("mask_concat", required=True, type_hint=torch.Tensor),
4949
]
@@ -92,8 +92,8 @@ def description(self) -> str:
9292
@property
9393
def inputs(self) -> list[InputParam]:
9494
inputs = [
95-
InputParam("attention_kwargs"),
96-
InputParam("num_inference_steps", required=True, type_hint=int),
95+
InputParam.template("attention_kwargs"),
96+
InputParam.template("num_inference_steps", required=True, default=None),
9797
InputParam("image_embeds", type_hint=torch.Tensor),
9898
]
9999
for value in self._guider_input_fields.values():
@@ -194,8 +194,8 @@ def loop_expected_components(self) -> list[ComponentSpec]:
194194
@property
195195
def loop_inputs(self) -> list[InputParam]:
196196
return [
197-
InputParam("timesteps", required=True, type_hint=torch.Tensor),
198-
InputParam("num_inference_steps", required=True, type_hint=int),
197+
InputParam.template("timesteps", required=True),
198+
InputParam.template("num_inference_steps", required=True, default=None),
199199
]
200200

201201
@torch.no_grad()
@@ -273,10 +273,10 @@ def description(self) -> str:
273273
@property
274274
def inputs(self) -> list[InputParam]:
275275
inputs = [
276-
InputParam("attention_kwargs"),
277-
InputParam("num_inference_steps", required=True, type_hint=int),
276+
InputParam.template("attention_kwargs"),
277+
InputParam.template("num_inference_steps", required=True, default=None),
278278
InputParam("image_embeds", type_hint=torch.Tensor),
279-
InputParam("timesteps", required=True, type_hint=torch.Tensor),
279+
InputParam.template("timesteps", required=True),
280280
]
281281
for value in self._guider_input_fields.values():
282282
if isinstance(value, tuple):

src/diffusers/modular_pipelines/hunyuan_video1_5/encoders.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,26 @@ def expected_components(self) -> list[ComponentSpec]:
158158
@property
159159
def inputs(self) -> list[InputParam]:
160160
return [
161-
InputParam("prompt"),
162-
InputParam("negative_prompt"),
163-
InputParam("prompt_embeds", type_hint=torch.Tensor),
164-
InputParam("prompt_embeds_mask", type_hint=torch.Tensor),
165-
InputParam("negative_prompt_embeds", type_hint=torch.Tensor),
166-
InputParam("negative_prompt_embeds_mask", type_hint=torch.Tensor),
161+
InputParam.template("prompt", required=False),
162+
InputParam.template("negative_prompt"),
163+
InputParam.template("prompt_embeds", required=False),
164+
InputParam.template("prompt_embeds_mask", required=False),
165+
InputParam.template("negative_prompt_embeds"),
166+
InputParam.template("negative_prompt_embeds_mask"),
167167
InputParam("prompt_embeds_2", type_hint=torch.Tensor),
168168
InputParam("prompt_embeds_mask_2", type_hint=torch.Tensor),
169169
InputParam("negative_prompt_embeds_2", type_hint=torch.Tensor),
170170
InputParam("negative_prompt_embeds_mask_2", type_hint=torch.Tensor),
171-
InputParam("num_videos_per_prompt", type_hint=int, default=1),
171+
InputParam.template("num_images_per_prompt", name="num_videos_per_prompt"),
172172
]
173173

174174
@property
175175
def intermediate_outputs(self) -> list[OutputParam]:
176176
return [
177-
OutputParam("prompt_embeds", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
178-
OutputParam("prompt_embeds_mask", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
179-
OutputParam("negative_prompt_embeds", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
180-
OutputParam("negative_prompt_embeds_mask", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
177+
OutputParam.template("prompt_embeds"),
178+
OutputParam.template("prompt_embeds_mask"),
179+
OutputParam.template("negative_prompt_embeds"),
180+
OutputParam.template("negative_prompt_embeds_mask"),
181181
OutputParam("prompt_embeds_2", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
182182
OutputParam("prompt_embeds_mask_2", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),
183183
OutputParam("negative_prompt_embeds_2", type_hint=torch.Tensor, kwargs_type="denoiser_input_fields"),

0 commit comments

Comments
 (0)