Skip to content

Commit dc84cc8

Browse files
committed
Lift LTXVaeEncoderStep out of I2V core denoise into its own auto block
1 parent d8e14c4 commit dc84cc8

1 file changed

Lines changed: 65 additions & 22 deletions

File tree

src/diffusers/modular_pipelines/ltx/modular_blocks_ltx.py

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from ...utils import logging
16-
from ..modular_pipeline import SequentialPipelineBlocks
16+
from ..modular_pipeline import AutoPipelineBlocks, SequentialPipelineBlocks
1717
from ..modular_pipeline_utils import OutputParam
1818
from .before_denoise import (
1919
LTXImage2VideoPrepareLatentsStep,
@@ -99,8 +99,8 @@ class LTXImage2VideoCoreDenoiseStep(SequentialPipelineBlocks):
9999
Denoise block for image-to-video that takes encoded conditions and an image, and runs the denoising process.
100100
101101
Components:
102-
transformer (`LTXVideoTransformer3DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`) vae
103-
(`AutoencoderKLLTXVideo`) video_processor (`VideoProcessor`) guider (`ClassifierFreeGuidance`)
102+
transformer (`LTXVideoTransformer3DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`) guider
103+
(`ClassifierFreeGuidance`)
104104
105105
Inputs:
106106
num_videos_per_prompt (`int`, *optional*, defaults to 1):
@@ -127,12 +127,12 @@ class LTXImage2VideoCoreDenoiseStep(SequentialPipelineBlocks):
127127
TODO: Add description.
128128
frame_rate (`int`, *optional*, defaults to 25):
129129
TODO: Add description.
130-
image (`Image | list`):
131-
Reference image(s) for denoising. Can be a single image or list of images.
132-
generator (`Generator`, *optional*):
133-
Torch generator for deterministic generation.
130+
image_latents (`Tensor`):
131+
TODO: Add description.
134132
latents (`Tensor`, *optional*):
135133
Pre-generated noisy latents for image generation.
134+
generator (`Generator`, *optional*):
135+
Torch generator for deterministic generation.
136136
attention_kwargs (`dict`, *optional*):
137137
Additional kwargs for attention processors.
138138
@@ -145,15 +145,14 @@ class LTXImage2VideoCoreDenoiseStep(SequentialPipelineBlocks):
145145
block_classes = [
146146
LTXTextInputStep,
147147
LTXSetTimestepsStep,
148-
LTXVaeEncoderStep,
149148
LTXImage2VideoPrepareLatentsStep,
150149
LTXImage2VideoDenoiseStep,
151150
]
152-
block_names = ["input", "set_timesteps", "vae_encoder", "prepare_latents", "denoise"]
151+
block_names = ["input", "set_timesteps", "prepare_latents", "denoise"]
153152

154153
@property
155154
def description(self):
156-
return "Denoise block for image-to-video that takes encoded conditions and an image, and runs the denoising process."
155+
return "Denoise block for image-to-video that takes encoded conditions and image latents, and runs the denoising process."
157156

158157
@property
159158
def outputs(self):
@@ -228,15 +227,56 @@ def outputs(self):
228227
return [OutputParam.template("videos")]
229228

230229

230+
# auto_docstring
231+
class LTXAutoVaeEncoderStep(AutoPipelineBlocks):
232+
"""
233+
VAE encoder step that encodes the image input into its latent representation.
234+
This is an auto pipeline block that works for image-to-video tasks.
235+
- `LTXVaeEncoderStep` is used when `image` is provided.
236+
- If `image` is not provided, step will be skipped.
237+
238+
Components:
239+
vae (`AutoencoderKLLTXVideo`) video_processor (`VideoProcessor`)
240+
241+
Inputs:
242+
image (`Image | list`, *optional*):
243+
Reference image(s) for denoising. Can be a single image or list of images.
244+
height (`int`, *optional*, defaults to 512):
245+
The height in pixels of the generated image.
246+
width (`int`, *optional*, defaults to 704):
247+
The width in pixels of the generated image.
248+
generator (`Generator`, *optional*):
249+
Torch generator for deterministic generation.
250+
251+
Outputs:
252+
image_latents (`Tensor`):
253+
Encoded image latents from the VAE encoder
254+
"""
255+
256+
model_name = "ltx"
257+
block_classes = [LTXVaeEncoderStep]
258+
block_names = ["vae_encoder"]
259+
block_trigger_inputs = ["image"]
260+
261+
@property
262+
def description(self):
263+
return (
264+
"VAE encoder step that encodes the image input into its latent representation.\n"
265+
"This is an auto pipeline block that works for image-to-video tasks.\n"
266+
" - `LTXVaeEncoderStep` is used when `image` is provided.\n"
267+
" - If `image` is not provided, step will be skipped."
268+
)
269+
270+
231271
# auto_docstring
232272
class LTXImage2VideoBlocks(SequentialPipelineBlocks):
233273
"""
234274
Modular pipeline blocks for LTX Video image-to-video.
235275
236276
Components:
237-
text_encoder (`T5EncoderModel`) tokenizer (`T5TokenizerFast`) guider (`ClassifierFreeGuidance`) transformer
238-
(`LTXVideoTransformer3DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`) vae (`AutoencoderKLLTXVideo`)
239-
video_processor (`VideoProcessor`)
277+
text_encoder (`T5EncoderModel`) tokenizer (`T5TokenizerFast`) guider (`ClassifierFreeGuidance`) vae
278+
(`AutoencoderKLLTXVideo`) video_processor (`VideoProcessor`) transformer (`LTXVideoTransformer3DModel`)
279+
scheduler (`FlowMatchEulerDiscreteScheduler`)
240280
241281
Inputs:
242282
prompt (`str`):
@@ -245,6 +285,14 @@ class LTXImage2VideoBlocks(SequentialPipelineBlocks):
245285
The prompt or prompts not to guide the image generation.
246286
max_sequence_length (`int`, *optional*, defaults to 128):
247287
Maximum sequence length for prompt encoding.
288+
image (`Image | list`, *optional*):
289+
Reference image(s) for denoising. Can be a single image or list of images.
290+
height (`int`, *optional*, defaults to 512):
291+
The height in pixels of the generated image.
292+
width (`int`, *optional*, defaults to 704):
293+
The width in pixels of the generated image.
294+
generator (`Generator`, *optional*):
295+
Torch generator for deterministic generation.
248296
num_videos_per_prompt (`int`, *optional*, defaults to 1):
249297
The number of images to generate per prompt.
250298
num_inference_steps (`int`, *optional*, defaults to 50):
@@ -253,18 +301,12 @@ class LTXImage2VideoBlocks(SequentialPipelineBlocks):
253301
Timesteps for the denoising process.
254302
sigmas (`list`, *optional*):
255303
Custom sigmas for the denoising process.
256-
height (`int`, *optional*, defaults to 512):
257-
The height in pixels of the generated image.
258-
width (`int`, *optional*, defaults to 704):
259-
The width in pixels of the generated image.
260304
num_frames (`int`, *optional*, defaults to 161):
261305
TODO: Add description.
262306
frame_rate (`int`, *optional*, defaults to 25):
263307
TODO: Add description.
264-
image (`Image | list`):
265-
Reference image(s) for denoising. Can be a single image or list of images.
266-
generator (`Generator`, *optional*):
267-
Torch generator for deterministic generation.
308+
image_latents (`Tensor`):
309+
TODO: Add description.
268310
latents (`Tensor`, *optional*):
269311
Pre-generated noisy latents for image generation.
270312
attention_kwargs (`dict`, *optional*):
@@ -284,10 +326,11 @@ class LTXImage2VideoBlocks(SequentialPipelineBlocks):
284326
model_name = "ltx"
285327
block_classes = [
286328
LTXTextEncoderStep,
329+
LTXAutoVaeEncoderStep,
287330
LTXImage2VideoCoreDenoiseStep,
288331
LTXVaeDecoderStep,
289332
]
290-
block_names = ["text_encoder", "denoise", "decode"]
333+
block_names = ["text_encoder", "vae_encoder", "denoise", "decode"]
291334

292335
@property
293336
def description(self):

0 commit comments

Comments
 (0)