stages ¶
Pipeline stages for diffusion models.
This package contains the various stages that can be composed to create complete diffusion pipelines.
Classes¶
fastvideo.pipelines.stages.CausalDMDDenosingStage ¶
Bases: DenoisingStage
Denoising stage for causal diffusion.
Source code in fastvideo/pipelines/stages/causal_denoising.py
Methods:¶
fastvideo.pipelines.stages.CausalDMDDenosingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify denoising stage inputs.
Source code in fastvideo/pipelines/stages/causal_denoising.py
fastvideo.pipelines.stages.CausalDenoisingStage ¶
Bases: CausalDMDDenosingStage
Causal block-by-block denoising with standard multi-step flow matching (scheduler.step), not DMD few-step.
Each block is fully denoised through all scheduler timesteps before moving to the next block. After each block is denoised, the KV cache is updated with clean context so subsequent blocks can attend to prior clean frames.
Source code in fastvideo/pipelines/stages/causal_denoising.py
fastvideo.pipelines.stages.ConditioningStage ¶
Bases: PipelineStage
Stage for applying conditioning to the diffusion process.
This stage handles the application of conditioning, such as classifier-free guidance, to the diffusion process.
Methods:¶
fastvideo.pipelines.stages.ConditioningStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Apply conditioning to the diffusion process.
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 applied conditioning. |
Source code in fastvideo/pipelines/stages/conditioning.py
fastvideo.pipelines.stages.ConditioningStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify conditioning stage inputs.
Source code in fastvideo/pipelines/stages/conditioning.py
fastvideo.pipelines.stages.ConditioningStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify conditioning stage outputs.
Source code in fastvideo/pipelines/stages/conditioning.py
fastvideo.pipelines.stages.Cosmos25AutoDenoisingStage ¶
Bases: PipelineStage
Route Cosmos 2.5 denoising to T2W vs V2W/I2W.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.Cosmos25AutoLatentPreparationStage ¶
Bases: PipelineStage
Route Cosmos 2.5 latent prep to T2W vs V2W/I2W.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.Cosmos25DenoisingStage ¶
Bases: CosmosDenoisingStage
Denoising stage for Cosmos 2.5 DiT (expects 1D/2D timestep, not 5D).
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.Cosmos25LatentPreparationStage ¶
Bases: CosmosLatentPreparationStage
Latent preparation for Cosmos 2.5 DiT input conventions.
Source code in fastvideo/pipelines/stages/latent_preparation.py
Methods:¶
fastvideo.pipelines.stages.Cosmos25LatentPreparationStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify Cosmos latent preparation stage inputs.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.Cosmos25LatentPreparationStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify latent preparation stage outputs.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.Cosmos25T2WDenoisingStage ¶
Bases: Cosmos25DenoisingStage
Cosmos 2.5 Text2World denoising stage.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.Cosmos25T2WLatentPreparationStage ¶
Bases: PipelineStage
Cosmos 2.5 Text2World latent preparation.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.Cosmos25TextEncodingStage ¶
Bases: PipelineStage
Cosmos 2.5 text encoding stage.
Cosmos 2.5 uses Reason1 (Qwen2.5-VL) and relies on the encoder's compute_text_embeddings_online().
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.Cosmos25TimestepPreparationStage ¶
Bases: TimestepPreparationStage
Cosmos 2.5 timestep preparation with scheduler-specific kwargs.
Source code in fastvideo/pipelines/stages/timestep_preparation.py
fastvideo.pipelines.stages.Cosmos25V2WDenoisingStage ¶
Bases: Cosmos25DenoisingStage
Cosmos 2.5 Video2World denoising stage.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.Cosmos25V2WLatentPreparationStage ¶
Bases: Cosmos25LatentPreparationStage
Cosmos 2.5 V2W/I2W latent preparation stage (conditioning-aware).
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.CosmosDenoisingStage ¶
Bases: DenoisingStage
Denoising stage for Cosmos models.
Uses FlowMatchEulerDiscreteScheduler with manual EDM preconditioning (c_in, c_skip, c_out) to match the pretrained Cosmos model's training convention.
Source code in fastvideo/pipelines/stages/denoising.py
Methods:¶
fastvideo.pipelines.stages.CosmosDenoisingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify Cosmos denoising stage inputs.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.CosmosDenoisingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify Cosmos denoising stage outputs.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.CosmosLatentPreparationStage ¶
Bases: PipelineStage
Cosmos-specific latent preparation stage that properly handles the tensor shapes and conditioning masks required by the Cosmos transformer.
This stage replicates the logic from diffusers' Cosmos2VideoToWorldPipeline.prepare_latents()
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.DecodingStage ¶
Bases: PipelineStage
Stage for decoding latent representations into pixel space.
This stage handles the decoding of latent representations into the final output format (e.g., pixel values).
Source code in fastvideo/pipelines/stages/decoding.py
Methods:¶
fastvideo.pipelines.stages.DecodingStage.decode ¶
decode(latents: Tensor, fastvideo_args: FastVideoArgs) -> Tensor
Decode latent representations into pixel space using VAE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents | Tensor | Input latent tensor with shape (batch, channels, frames, height_latents, width_latents) | required |
fastvideo_args | FastVideoArgs | Configuration containing: - disable_autocast: Whether to disable automatic mixed precision (default: False) - pipeline_config.vae_precision: VAE computation precision ("fp32", "fp16", "bf16") - pipeline_config.vae_tiling: Whether to enable VAE tiling for memory efficiency | required |
Returns:
| Type | Description |
|---|---|
Tensor | Decoded video tensor with shape (batch, channels, frames, height, width), |
Tensor | normalized to [0, 1] range and moved to CPU as float32 |
Source code in fastvideo/pipelines/stages/decoding.py
fastvideo.pipelines.stages.DecodingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Decode latent representations into pixel space.
This method processes the batch through the VAE decoder, converting latent representations to pixel-space video/images. It also optionally decodes trajectory latents for visualization purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch containing: - latents: Tensor to decode (batch, channels, frames, height_latents, width_latents) - return_trajectory_decoded (optional): Flag to decode trajectory latents - trajectory_latents (optional): Latents at different timesteps - trajectory_timesteps (optional): Corresponding timesteps | required |
fastvideo_args | FastVideoArgs | Configuration containing: - output_type: "latent" to skip decoding, otherwise decode to pixels - vae_cpu_offload: Whether to offload VAE to CPU after decoding - model_loaded: Track VAE loading state - model_paths: Path to VAE model if loading needed | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | Modified batch with: - output: Decoded frames (batch, channels, frames, height, width) as CPU float32 - trajectory_decoded (if requested): List of decoded frames per timestep |
Source code in fastvideo/pipelines/stages/decoding.py
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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
fastvideo.pipelines.stages.DecodingStage.streaming_decode ¶
streaming_decode(latents: Tensor, fastvideo_args: FastVideoArgs, cache: list[Tensor | None] | None = None, is_first_chunk: bool = False) -> tuple[Tensor, list[Tensor | None]]
Decode latent representations into pixel space using VAE with streaming cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents | Tensor | Input latent tensor with shape (batch, channels, frames, height_latents, width_latents) | required |
fastvideo_args | FastVideoArgs | Configuration object. | required |
cache | list[Tensor | None] | None | VAE cache from previous call, or None to initialize a new cache. | None |
is_first_chunk | bool | Whether this is the first chunk. | False |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, list[Tensor | None]] | A tuple of (decoded_frames, updated_cache). |
Source code in fastvideo/pipelines/stages/decoding.py
fastvideo.pipelines.stages.DecodingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify decoding stage inputs.
Source code in fastvideo/pipelines/stages/decoding.py
fastvideo.pipelines.stages.DecodingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify decoding stage outputs.
Source code in fastvideo/pipelines/stages/decoding.py
fastvideo.pipelines.stages.DenoisingStage ¶
Bases: PipelineStage
Stage for running the denoising loop in diffusion pipelines.
This stage handles the iterative denoising process that transforms the initial noise into the final output.
Source code in fastvideo/pipelines/stages/denoising.py
Methods:¶
fastvideo.pipelines.stages.DenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run the denoising loop.
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 denoised latents. |
Source code in fastvideo/pipelines/stages/denoising.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
fastvideo.pipelines.stages.DenoisingStage.prepare_extra_func_kwargs ¶
Prepare extra kwargs for the scheduler step / denoise step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func | The function to prepare kwargs for. | required | |
kwargs | The kwargs to prepare. | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | The prepared kwargs. |
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.DenoisingStage.progress_bar ¶
Create a progress bar for the denoising process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable | Iterable | None | The iterable to iterate over. | None |
total | int | None | The total number of items. | None |
Returns:
| Type | Description |
|---|---|
tqdm | A tqdm progress bar. |
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.DenoisingStage.rescale_noise_cfg ¶
Rescale noise prediction according to guidance_rescale.
Based on findings of "Common Diffusion Noise Schedules and Sample Steps are Flawed" (https://arxiv.org/pdf/2305.08891.pdf), Section 3.4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
noise_cfg | The noise prediction with guidance. | required | |
noise_pred_text | The text-conditioned noise prediction. | required | |
guidance_rescale | The guidance rescale factor. | 0.0 |
Returns:
| Type | Description |
|---|---|
Tensor | The rescaled noise prediction. |
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.DenoisingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify denoising stage inputs.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.DenoisingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify denoising stage outputs.
Source code in fastvideo/pipelines/stages/denoising.py
fastvideo.pipelines.stages.DmdDenoisingStage ¶
Bases: DenoisingStage
Denoising stage for DMD.
Source code in fastvideo/pipelines/stages/denoising.py
Methods:¶
fastvideo.pipelines.stages.DmdDenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run the denoising loop.
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 denoised latents. |
Source code in fastvideo/pipelines/stages/denoising.py
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 | |
fastvideo.pipelines.stages.EncodingStage ¶
EncodingStage(vae: ParallelTiledVAE)
Bases: PipelineStage
Stage for encoding pixel space representations into latent space.
This stage handles the encoding of pixel-space video/images into latent representations for further processing in the diffusion pipeline.
Source code in fastvideo/pipelines/stages/encoding.py
Methods:¶
fastvideo.pipelines.stages.EncodingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode pixel space 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 latents. |
Source code in fastvideo/pipelines/stages/encoding.py
fastvideo.pipelines.stages.EncodingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify encoding stage inputs.
Source code in fastvideo/pipelines/stages/encoding.py
fastvideo.pipelines.stages.EncodingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify encoding stage outputs.
Source code in fastvideo/pipelines/stages/encoding.py
fastvideo.pipelines.stages.GameCraftDenoisingStage ¶
Bases: DenoisingStage
Denoising stage for HunyuanGameCraft with camera/action conditioning.
This stage handles: - Camera state encoding via CameraNet (Plücker coordinates) - Concatenation of latents with gt_latents and mask (33 channels) - Flow matching denoising with camera conditioning - Support for autoregressive generation with history frames
Source code in fastvideo/pipelines/stages/gamecraft_denoising.py
Methods:¶
fastvideo.pipelines.stages.GameCraftDenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run the denoising loop with camera/action conditioning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. Must contain: - latents: Noise latents [B, 16, T, H, W] - camera_states: Plücker coordinates [B, T_video, 6, H_video, W_video] - gt_latents (optional): Ground truth latents for conditioning [B, 16, T, H, W] - conditioning_mask (optional): Mask for conditioning [B, 1, T, H, W] | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | The batch with denoised latents. |
Source code in fastvideo/pipelines/stages/gamecraft_denoising.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.GameCraftDenoisingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify that required inputs are present.
Source code in fastvideo/pipelines/stages/gamecraft_denoising.py
fastvideo.pipelines.stages.GameCraftDenoisingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify that outputs are properly set.
Source code in fastvideo/pipelines/stages/gamecraft_denoising.py
fastvideo.pipelines.stages.GameCraftImageVAEEncodingStage ¶
Bases: PipelineStage
Stage for encoding a reference image into gt_latents and conditioning_mask for HunyuanGameCraft image-to-video generation.
Official GameCraft I2V flow: 1. VAE-encode the reference image -> [B, 16, 1, H_lat, W_lat] 2. Scale by VAE scaling_factor (0.476986) 3. Repeat to all temporal frames 4. Zero out non-conditioned frames (first frame only for short videos, first half for longer autoregressive generation) 5. Build a binary mask (1 = conditioned, 0 = generate) 6. Store gt_latents and conditioning_mask on the batch for the denoising stage
If no image is provided (T2V mode), this stage is a no-op; the denoising stage already falls back to zero gt_latents and zero mask.
Source code in fastvideo/pipelines/stages/gamecraft_image_encoding.py
Methods:¶
fastvideo.pipelines.stages.GameCraftImageVAEEncodingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode reference image for I2V, or skip for T2V.
Source code in fastvideo/pipelines/stages/gamecraft_image_encoding.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
fastvideo.pipelines.stages.Gen3CCFGPolicyStage ¶
Bases: PipelineStage
Explicitly control when GEN3C runs a conditional/unconditional pair (CFG).
Policies: - legacy: enable CFG only when guidance_scale > 1.0 (current FastVideo behavior) - official_uncond_at_unity: also run CFG at guidance_scale == 1.0
fastvideo.pipelines.stages.Gen3CConditioningStage ¶
Bases: PipelineStage
3D cache conditioning stage for GEN3C.
This stage performs the core GEN3C innovation: 1. Loads the input image 2. Predicts depth via MoGe 3. Initializes a 3D point cloud cache 4. Generates a camera trajectory 5. Renders warped frames from the cache at each target camera pose 6. Stores rendered warps on the batch for VAE encoding in the latent prep stage
Source code in fastvideo/pipelines/stages/gen3c_stages.py
Methods:¶
fastvideo.pipelines.stages.Gen3CConditioningStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run 3D cache conditioning pipeline.
Source code in fastvideo/pipelines/stages/gen3c_stages.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.Gen3CDenoisingStage ¶
Bases: DenoisingStage
Denoising stage for GEN3C models.
This stage extends the base denoising stage with support for: - condition_video_input_mask: Binary mask indicating conditioning frames - condition_video_pose: VAE-encoded 3D cache buffers - condition_video_augment_sigma: Noise augmentation sigma
Source code in fastvideo/pipelines/stages/gen3c_stages.py
fastvideo.pipelines.stages.Gen3CLatentPreparationStage ¶
Bases: LatentPreparationStage
Latent preparation stage for GEN3C.
This stage prepares latents and encodes 3D cache buffers through the VAE. If rendered warped frames are available on the batch (from Gen3CConditioningStage), they are VAE-encoded to produce real conditioning. Otherwise falls back to zeros.
Source code in fastvideo/pipelines/stages/gen3c_stages.py
Methods:¶
fastvideo.pipelines.stages.Gen3CLatentPreparationStage.encode_warped_frames ¶
encode_warped_frames(condition_state: Tensor, condition_state_mask: Tensor, vae: Any, frame_buffer_max: int, dtype: dtype) -> Tensor
Encode rendered 3D cache buffers through VAE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition_state | Tensor | (B, T, N, 3, H, W) rendered RGB images in [-1, 1]. | required |
condition_state_mask | Tensor | (B, T, N, 1, H, W) rendered masks in [0, 1]. | required |
vae | Any | VAE encoder. | required |
frame_buffer_max | int | Maximum number of buffers. | required |
dtype | dtype | Target dtype. | required |
Returns:
| Name | Type | Description |
|---|---|---|
latent_condition | Tensor | (B, buffer_channels, T_latent, H_latent, W_latent) |
Source code in fastvideo/pipelines/stages/gen3c_stages.py
fastvideo.pipelines.stages.Gen3CLatentPreparationStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Prepare latents and encode 3D cache buffers.
Source code in fastvideo/pipelines/stages/gen3c_stages.py
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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
fastvideo.pipelines.stages.HYWorldDenoisingStage ¶
Bases: DenoisingStage
Denoising stage for HYWorld-style chunk-based video generation.
This stage implements bi_rollout denoising with: - Chunk-based processing (generates video in chunks, e.g., 4 frames at a time) - Context frame selection based on camera view alignment - 3D-aware generation using view matrices and camera intrinsics - Support for action conditioning - Dual timestep handling (context frames use different timestep than current frames) - Context frame selection based on camera view alignment
Source code in fastvideo/pipelines/stages/hyworld_denoising.py
Methods:¶
fastvideo.pipelines.stages.HYWorldDenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run the chunk-based denoising loop with context frame selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. Must contain: - viewmats: torch.Tensor | None - Camera view matrices (B, T, 4, 4) - Ks: torch.Tensor | None - Camera intrinsics (B, T, 3, 3) - action: torch.Tensor | None - Action conditioning (B, T) - chunk_latent_frames: int - Number of frames per chunk (default: 16 for bidirectional model) These can be passed via batch.extra dict or as direct attributes. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | The batch with denoised latents. |
Source code in fastvideo/pipelines/stages/hyworld_denoising.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
fastvideo.pipelines.stages.HYWorldDenoisingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify HYWorld denoising stage inputs.
Source code in fastvideo/pipelines/stages/hyworld_denoising.py
fastvideo.pipelines.stages.HYWorldDenoisingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify HYWorld denoising stage outputs.
Source code in fastvideo/pipelines/stages/hyworld_denoising.py
fastvideo.pipelines.stages.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
Methods:¶
fastvideo.pipelines.stages.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
135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.HYWorldImageEncodingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
fastvideo.pipelines.stages.Hy15ImageEncodingStage ¶
Bases: ImageEncodingStage
Stage for encoding image prompts into embeddings for HunyuanVideo1.5 models.
Source code in fastvideo/pipelines/stages/image_encoding.py
Methods:¶
fastvideo.pipelines.stages.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.Hy15ImageEncodingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
fastvideo.pipelines.stages.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
Methods:¶
fastvideo.pipelines.stages.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.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.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.ImageVAEEncodingStage ¶
ImageVAEEncodingStage(vae: ParallelTiledVAE)
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
Methods:¶
fastvideo.pipelines.stages.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
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 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 | |
fastvideo.pipelines.stages.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.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.InputValidationStage ¶
Bases: PipelineStage
Stage for validating and preparing inputs for diffusion pipelines.
This stage validates that all required inputs are present and properly formatted before proceeding with the diffusion process.
Methods:¶
fastvideo.pipelines.stages.InputValidationStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Validate and prepare inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | The validated batch information. |
Source code in fastvideo/pipelines/stages/input_validation.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.InputValidationStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify input validation stage inputs.
Source code in fastvideo/pipelines/stages/input_validation.py
fastvideo.pipelines.stages.InputValidationStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify input validation stage outputs.
Source code in fastvideo/pipelines/stages/input_validation.py
fastvideo.pipelines.stages.Kandinsky5DenoisingStage ¶
Bases: PipelineStage
Source code in fastvideo/pipelines/stages/kandinsky5.py
Methods:¶
fastvideo.pipelines.stages.Kandinsky5DenoisingStage.fast_sta_nabla staticmethod ¶
fast_sta_nabla(T: int, H: int, W: int, wT: int = 3, wH: int = 3, wW: int = 3, device: device | str = 'cuda') -> Tensor
Create a sparse temporal attention (STA) mask for efficient video generation.
This method generates a mask that limits attention to nearby frames and spatial positions, reducing computational complexity for video generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T | int | Number of temporal frames | required |
H | int | Height in latent space | required |
W | int | Width in latent space | required |
wT | int | Temporal attention window size | 3 |
wH | int | Height attention window size | 3 |
wW | int | Width attention window size | 3 |
device | str | Device to create tensor on | 'cuda' |
Returns:
| Type | Description |
|---|---|
Tensor | torch.Tensor: Sparse attention mask of shape (THW, THW) |
Source code in fastvideo/pipelines/stages/kandinsky5.py
fastvideo.pipelines.stages.Kandinsky5DenoisingStage.get_sparse_params ¶
Generate sparse attention parameters for the transformer based on sample dimensions.
This method computes the sparse attention configuration needed for efficient video processing in the transformer model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample | Tensor | Input sample tensor | required |
device | device | Device to place tensors on | required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict | dict[str, Any] | None | Dictionary containing sparse attention parameters |
Source code in fastvideo/pipelines/stages/kandinsky5.py
fastvideo.pipelines.stages.LTX2AudioDecodingStage ¶
Bases: PipelineStage
Decode LTX-2 audio latents into a waveform.
Source code in fastvideo/pipelines/basic/ltx2/stages/ltx2_audio_decoding.py
fastvideo.pipelines.stages.LTX2DenoisingStage ¶
LTX2DenoisingStage(transformer, *, sigmas_override: list[float] | None = None, num_inference_steps_override: int | None = None, force_guidance_scale: float | None = None, initial_audio_latents_key: str | None = 'ltx2_audio_latents')
Bases: PipelineStage
Run the LTX-2 denoising loop over the sigma schedule.
Source code in fastvideo/pipelines/basic/ltx2/stages/ltx2_denoising.py
fastvideo.pipelines.stages.LTX2LatentPreparationStage ¶
Bases: PipelineStage
Prepare initial LTX-2 latents without relying on a diffusers scheduler.
Source code in fastvideo/pipelines/basic/ltx2/stages/ltx2_latent_preparation.py
fastvideo.pipelines.stages.LTX2TextEncodingStage ¶
Bases: TextEncodingStage
LTX2 text encoding stage with sequence parallelism support.
When SP is enabled (sp_world_size > 1), only rank 0 runs the text encoder and broadcasts embeddings to other ranks. This avoids I/O contention from all ranks loading the Gemma model simultaneously, which can cause text encoding to take 100+ seconds instead of ~5 seconds.
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.LatentPreparationStage ¶
LatentPreparationStage(scheduler, transformer, use_btchw_layout: bool = False)
Bases: PipelineStage
Stage for preparing initial latent variables for the diffusion process.
This stage handles the preparation of the initial latent variables that will be denoised during the diffusion process.
Source code in fastvideo/pipelines/stages/latent_preparation.py
Methods:¶
fastvideo.pipelines.stages.LatentPreparationStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Prepare initial latent variables for the diffusion process.
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 prepared latent variables. |
Source code in fastvideo/pipelines/stages/latent_preparation.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
fastvideo.pipelines.stages.LatentPreparationStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify latent preparation stage inputs.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.LatentPreparationStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify latent preparation stage outputs.
Source code in fastvideo/pipelines/stages/latent_preparation.py
fastvideo.pipelines.stages.LongCatKVCacheInitStage ¶
Bases: PipelineStage
Pre-compute KV cache for conditioning frames.
After this stage: - batch.kv_cache_dict contains {block_idx: (k, v)} - batch.cond_latents contains the conditioning latents - batch.latents contains ONLY noise latents
Source code in fastvideo/pipelines/stages/longcat_kv_cache_init.py
Methods:¶
fastvideo.pipelines.stages.LongCatKVCacheInitStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Initialize KV cache from conditioning latents.
Source code in fastvideo/pipelines/stages/longcat_kv_cache_init.py
fastvideo.pipelines.stages.LongCatVCDenoisingStage ¶
Bases: LongCatDenoisingStage
LongCat denoising with Video Continuation and KV cache support.
Key differences from I2V denoising: - Supports KV cache (reuses cached K/V from conditioning frames) - Handles larger num_cond_latents - Concatenates conditioning latents back after denoising
When use_kv_cache=True: - batch.latents contains ONLY noise frames (cond removed by KV cache init) - batch.kv_cache_dict contains cached K/V - batch.cond_latents contains conditioning latents for post-concat
When use_kv_cache=False: - batch.latents contains ALL frames (cond + noise) - Timestep masking: timestep[:, :num_cond_latents] = 0 - Selective denoising: only update noise frames
Source code in fastvideo/pipelines/stages/denoising.py
Methods:¶
fastvideo.pipelines.stages.LongCatVCDenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run denoising loop with VC conditioning and optional KV cache.
Source code in fastvideo/pipelines/stages/longcat_vc_denoising.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.LongCatVideoVAEEncodingStage ¶
Bases: PipelineStage
Encode video frames to latent space for VC conditioning.
This stage: 1. Loads video frames from path or uses provided frames 2. Takes the last num_cond_frames from the video 3. Preprocesses and stacks frames 4. Encodes via VAE to latent space 5. Applies LongCat-specific normalization 6. Calculates num_cond_latents
Source code in fastvideo/pipelines/stages/longcat_video_vae_encoding.py
Methods:¶
fastvideo.pipelines.stages.LongCatVideoVAEEncodingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode video frames to latent for VC conditioning.
Source code in fastvideo/pipelines/stages/longcat_video_vae_encoding.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
fastvideo.pipelines.stages.LongCatVideoVAEEncodingStage.normalize_latents ¶
Apply LongCat-specific latent normalization.
Formula: (latents - mean) / std
Source code in fastvideo/pipelines/stages/longcat_video_vae_encoding.py
fastvideo.pipelines.stages.LongCatVideoVAEEncodingStage.retrieve_latents ¶
retrieve_latents(encoder_output: Any, generator: Generator | None) -> Tensor
Sample from VAE posterior.
Source code in fastvideo/pipelines/stages/longcat_video_vae_encoding.py
fastvideo.pipelines.stages.PipelineStage ¶
Bases: ABC
Abstract base class for all pipeline stages.
A pipeline stage represents a discrete step in the diffusion process that can be composed with other stages to create a complete pipeline. Each stage is responsible for a specific part of the process, such as prompt encoding, latent preparation, etc.
Attributes¶
fastvideo.pipelines.stages.PipelineStage.device property ¶
Get the device for this stage.
Methods:¶
fastvideo.pipelines.stages.PipelineStage.__call__ ¶
__call__(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Execute the stage's processing on the batch with optional verification and logging. Should not be overridden by subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | The updated batch information after this stage's processing. |
Source code in fastvideo/pipelines/stages/base.py
fastvideo.pipelines.stages.PipelineStage.forward abstractmethod ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Forward pass of the stage's processing.
This method should be implemented by subclasses to provide the forward processing logic for the stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
ForwardBatch | The updated batch information after this stage's processing. |
Source code in fastvideo/pipelines/stages/base.py
fastvideo.pipelines.stages.PipelineStage.set_logging ¶
set_logging(enable: bool)
Enable or disable logging for this stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable | bool | Whether to enable logging. | required |
fastvideo.pipelines.stages.PipelineStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify the input for the stage.
Example
from fastvideo.pipelines.stages.validators import V, VerificationResult
def verify_input(self, batch, fastvideo_args): result = VerificationResult() result.add_check("height", batch.height, V.positive_int_divisible(8)) result.add_check("width", batch.width, V.positive_int_divisible(8)) result.add_check("image_latent", batch.image_latent, V.is_tensor) return result
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
VerificationResult | A VerificationResult containing the verification status. |
Source code in fastvideo/pipelines/stages/base.py
fastvideo.pipelines.stages.PipelineStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify the output for the stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch | ForwardBatch | The current batch information. | required |
fastvideo_args | FastVideoArgs | The inference arguments. | required |
Returns:
| Type | Description |
|---|---|
VerificationResult | A VerificationResult containing the verification status. |
Source code in fastvideo/pipelines/stages/base.py
fastvideo.pipelines.stages.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
Methods:¶
fastvideo.pipelines.stages.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.SRDenoisingStage ¶
Bases: PipelineStage
Stage for running the denoising loop in SR diffusion pipelines. Used by Hunyuan15 SR pipeline.
This stage handles the iterative denoising process that transforms the initial noise into the final output.
Source code in fastvideo/pipelines/stages/sr_denoising.py
Methods:¶
fastvideo.pipelines.stages.SRDenoisingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Run the denoising loop.
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 denoised latents. |
Source code in fastvideo/pipelines/stages/sr_denoising.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 | |
fastvideo.pipelines.stages.SRDenoisingStage.prepare_extra_func_kwargs ¶
Prepare extra kwargs for the scheduler step / denoise step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func | The function to prepare kwargs for. | required | |
kwargs | The kwargs to prepare. | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | The prepared kwargs. |
Source code in fastvideo/pipelines/stages/sr_denoising.py
fastvideo.pipelines.stages.SRDenoisingStage.progress_bar ¶
Create a progress bar for the denoising process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterable | Iterable | None | The iterable to iterate over. | None |
total | int | None | The total number of items. | None |
Returns:
| Type | Description |
|---|---|
tqdm | A tqdm progress bar. |
Source code in fastvideo/pipelines/stages/sr_denoising.py
fastvideo.pipelines.stages.SRDenoisingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify denoising stage inputs.
Source code in fastvideo/pipelines/stages/sr_denoising.py
fastvideo.pipelines.stages.SRDenoisingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify denoising stage outputs.
Source code in fastvideo/pipelines/stages/sr_denoising.py
fastvideo.pipelines.stages.TextEncodingStage ¶
Bases: PipelineStage
Stage for encoding text prompts into embeddings for diffusion models.
This stage handles the encoding of text 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 text encoder. | required |
Source code in fastvideo/pipelines/stages/text_encoding.py
Methods:¶
fastvideo.pipelines.stages.TextEncodingStage.encode_text ¶
encode_text(text: str | list[str], fastvideo_args: FastVideoArgs, encoder_index: int | list[int] | None = None, return_attention_mask: bool = False, return_type: str = 'list', device: device | str | None = None, dtype: dtype | None = None, max_length: int | None = None, truncation: bool | None = None, padding: bool | str | None = None)
Encode plain text using selected text encoder(s) and return embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | list[str] | A single string or a list of strings to encode. | required |
fastvideo_args | FastVideoArgs | The inference arguments providing pipeline config, including tokenizer and encoder settings, preprocess and postprocess functions. | required |
encoder_index | int | list[int] | None | Encoder selector by index. Accepts an int or list of ints. | None |
return_attention_mask | bool | If True, also return attention masks for each selected encoder. | False |
return_type | str | "list" (default) returns a list aligned with selection; "dict" returns a dict keyed by encoder index as a string; "stack" stacks along a new first dimension (requires matching shapes). | 'list' |
device | device | str | None | Optional device override for inputs; defaults to local torch device. | None |
dtype | dtype | None | Optional dtype to cast returned embeddings to. | None |
max_length | int | None | Optional per-call tokenizer override. | None |
truncation | bool | None | Optional per-call tokenizer override. | None |
padding | bool | str | None | Optional per-call tokenizer override. | None |
Returns:
| Type | Description |
|---|---|
| Depending on return_type and return_attention_mask: | |
| |
| |
|
Source code in fastvideo/pipelines/stages/text_encoding.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
fastvideo.pipelines.stages.TextEncodingStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Encode the prompt into text 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/text_encoding.py
fastvideo.pipelines.stages.TextEncodingStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify text encoding stage inputs.
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.TextEncodingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify text encoding stage outputs.
Source code in fastvideo/pipelines/stages/text_encoding.py
fastvideo.pipelines.stages.TimestepPreparationStage ¶
Bases: PipelineStage
Stage for preparing timesteps for the diffusion process.
This stage handles the preparation of the timestep sequence that will be used during the diffusion process.
Source code in fastvideo/pipelines/stages/timestep_preparation.py
Methods:¶
fastvideo.pipelines.stages.TimestepPreparationStage.forward ¶
forward(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> ForwardBatch
Prepare timesteps for the diffusion process.
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 prepared timesteps. |
Source code in fastvideo/pipelines/stages/timestep_preparation.py
fastvideo.pipelines.stages.TimestepPreparationStage.verify_input ¶
verify_input(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify timestep preparation stage inputs.
Source code in fastvideo/pipelines/stages/timestep_preparation.py
fastvideo.pipelines.stages.TimestepPreparationStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify timestep preparation stage outputs.
Source code in fastvideo/pipelines/stages/timestep_preparation.py
fastvideo.pipelines.stages.VideoVAEEncodingStage ¶
VideoVAEEncodingStage(vae: ParallelTiledVAE)
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
Methods:¶
fastvideo.pipelines.stages.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
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
fastvideo.pipelines.stages.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.VideoVAEEncodingStage.verify_output ¶
verify_output(batch: ForwardBatch, fastvideo_args: FastVideoArgs) -> VerificationResult
Verify video encoding stage outputs.