image_encoding
¶
Image and video encoding stages for diffusion pipelines.
This module contains implementations of encoding stages for diffusion pipelines: - ImageEncodingStage: Encodes images using image encoders (e.g., CLIP) - RefImageEncodingStage: Encodes reference image for Wan2.1 control pipeline - ImageVAEEncodingStage: Encodes images to latent space using VAE for I2V generation - VideoVAEEncodingStage: Encodes videos to latent space using VAE for V2V and control tasks
Classes¶
fastvideo.pipelines.stages.image_encoding.HYWorldImageEncodingStage
¶
Bases: ImageEncodingStage
Stage for encoding image prompts into embeddings for HYWorld models.
Uses SigLIP (or other vision encoder) to encode reference images for I2V tasks. Also encodes reference image with VAE for conditional latent.
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.HYWorldImageEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into image encoder hidden states and VAE latents.
For I2V
- encodes the reference image using SigLIP → image_embeds
- encodes the reference image using VAE → image_latent (expanded to full temporal dim)
For T2V: creates zero embeddings
The image_latent is expanded to match the full temporal dimension of the video latent, following the original HunyuanVideo-1.5 implementation where: - First frame contains the encoded reference image - All other frames are zeros - Mask channel is 1 for first frame, 0 for rest
Source code in fastvideo/pipelines/stages/image_encoding.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
fastvideo.pipelines.stages.image_encoding.HYWorldImageEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
fastvideo.pipelines.stages.image_encoding.Hy15ImageEncodingStage
¶
Bases: ImageEncodingStage
Stage for encoding image prompts into embeddings for HunyuanVideo1.5 models.
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.Hy15ImageEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into image encoder hidden states.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.Hy15ImageEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
fastvideo.pipelines.stages.image_encoding.ImageEncodingStage
¶
Bases: PipelineStage
Stage for encoding image prompts into embeddings for diffusion models.
This stage handles the encoding of image prompts into the embedding space expected by the diffusion model.
Initialize the prompt encoding stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_logging
|
Whether to enable logging for this stage. |
required | |
is_secondary
|
Whether this is a secondary image encoder. |
required |
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.ImageEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into image encoder hidden states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
ForwardBatch
|
The current batch information. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments. |
required |
Returns:
| Type | Description |
|---|---|
ForwardBatch
|
The batch with encoded prompt embeddings. |
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.ImageEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify image encoding stage inputs.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.ImageEncodingStage.verify_output
¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify image encoding stage outputs.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.ImageVAEEncodingStage
¶
Bases: PipelineStage
Stage for encoding image pixel representations into latent space.
This stage handles the encoding of image pixel representations into the final input format (e.g., latents) for image-to-video generation.
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.ImageVAEEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode pixel representations into latent space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
ForwardBatch
|
The current batch information. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments. |
required |
Returns:
| Type | Description |
|---|---|
ForwardBatch
|
The batch with encoded outputs. |
Source code in fastvideo/pipelines/stages/image_encoding.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
fastvideo.pipelines.stages.image_encoding.ImageVAEEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify encoding stage inputs.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.ImageVAEEncodingStage.verify_output
¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify encoding stage outputs.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.RefImageEncodingStage
¶
Bases: ImageEncodingStage
Stage for encoding reference image prompts into embeddings for Wan2.1 Control models.
This stage extends ImageEncodingStage with specialized preprocessing for reference images.
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.RefImageEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into image encoder hidden states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
ForwardBatch
|
The current batch information. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments. |
required |
Returns:
| Type | Description |
|---|---|
ForwardBatch
|
The batch with encoded prompt embeddings. |
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.VideoVAEEncodingStage
¶
Bases: ImageVAEEncodingStage
Stage for encoding video pixel representations into latent space.
This stage handles the encoding of video pixel representations for video-to-video generation and control. Inherits from ImageVAEEncodingStage to reuse common functionality.
Source code in fastvideo/pipelines/stages/image_encoding.py
Functions¶
fastvideo.pipelines.stages.image_encoding.VideoVAEEncodingStage.forward
¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode video pixel representations into latent space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
ForwardBatch
|
The current batch information. |
required |
fastvideo_args
|
FastVideoArgs
|
The inference arguments. |
required |
Returns:
| Type | Description |
|---|---|
ForwardBatch
|
The batch with encoded outputs. |
Source code in fastvideo/pipelines/stages/image_encoding.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
fastvideo.pipelines.stages.image_encoding.VideoVAEEncodingStage.verify_input
¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify video encoding stage inputs.
Source code in fastvideo/pipelines/stages/image_encoding.py
fastvideo.pipelines.stages.image_encoding.VideoVAEEncodingStage.verify_output
¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify video encoding stage outputs.