|
2 | 2 | ComfyUI nodes for autoregressive video generation (Causal Forcing, Self-Forcing, etc.). |
3 | 3 | - EmptyARVideoLatent: create 5D [B, C, T, H, W] video latent tensors |
4 | 4 | - SamplerARVideo: SAMPLER for the block-by-block autoregressive denoising loop |
| 5 | + - ARVideoI2V: image-to-video conditioning for AR models (seeds KV cache with start image) |
5 | 6 | """ |
6 | 7 |
|
7 | 8 | import torch |
8 | 9 | from typing_extensions import override |
9 | 10 |
|
10 | 11 | import comfy.model_management |
11 | 12 | import comfy.samplers |
| 13 | +import comfy.utils |
12 | 14 | from comfy_api.latest import ComfyExtension, io |
13 | 15 |
|
14 | 16 |
|
@@ -71,12 +73,62 @@ def execute(cls, num_frame_per_block) -> io.NodeOutput: |
71 | 73 | return io.NodeOutput(comfy.samplers.ksampler("ar_video", extra_options)) |
72 | 74 |
|
73 | 75 |
|
| 76 | +class ARVideoI2V(io.ComfyNode): |
| 77 | + """Image-to-video setup for AR video models (Causal Forcing, Self-Forcing). |
| 78 | +
|
| 79 | + VAE-encodes the start image and stores it in the model's transformer_options |
| 80 | + so that sample_ar_video can seed the KV cache before denoising. |
| 81 | + Uses the same T2V model checkpoint -- no separate I2V architecture needed. |
| 82 | + """ |
| 83 | + |
| 84 | + @classmethod |
| 85 | + def define_schema(cls): |
| 86 | + return io.Schema( |
| 87 | + node_id="ARVideoI2V", |
| 88 | + category="conditioning/video_models", |
| 89 | + inputs=[ |
| 90 | + io.Model.Input("model"), |
| 91 | + io.Vae.Input("vae"), |
| 92 | + io.Image.Input("start_image"), |
| 93 | + io.Int.Input("width", default=832, min=16, max=8192, step=16), |
| 94 | + io.Int.Input("height", default=480, min=16, max=8192, step=16), |
| 95 | + io.Int.Input("length", default=81, min=1, max=1024, step=4), |
| 96 | + io.Int.Input("batch_size", default=1, min=1, max=64), |
| 97 | + ], |
| 98 | + outputs=[ |
| 99 | + io.Model.Output(display_name="MODEL"), |
| 100 | + io.Latent.Output(display_name="LATENT"), |
| 101 | + ], |
| 102 | + ) |
| 103 | + |
| 104 | + @classmethod |
| 105 | + def execute(cls, model, vae, start_image, width, height, length, batch_size) -> io.NodeOutput: |
| 106 | + start_image = comfy.utils.common_upscale( |
| 107 | + start_image[:1].movedim(-1, 1), width, height, "bilinear", "center" |
| 108 | + ).movedim(1, -1) |
| 109 | + |
| 110 | + initial_latent = vae.encode(start_image[:, :, :, :3]) |
| 111 | + |
| 112 | + m = model.clone() |
| 113 | + to = m.model_options.setdefault("transformer_options", {}) |
| 114 | + ar_cfg = to.setdefault("ar_config", {}) |
| 115 | + ar_cfg["initial_latent"] = initial_latent |
| 116 | + |
| 117 | + lat_t = ((length - 1) // 4) + 1 |
| 118 | + latent = torch.zeros( |
| 119 | + [batch_size, 16, lat_t, height // 8, width // 8], |
| 120 | + device=comfy.model_management.intermediate_device(), |
| 121 | + ) |
| 122 | + return io.NodeOutput(m, {"samples": latent}) |
| 123 | + |
| 124 | + |
74 | 125 | class ARVideoExtension(ComfyExtension): |
75 | 126 | @override |
76 | 127 | async def get_node_list(self) -> list[type[io.ComfyNode]]: |
77 | 128 | return [ |
78 | 129 | EmptyARVideoLatent, |
79 | 130 | SamplerARVideo, |
| 131 | + ARVideoI2V, |
80 | 132 | ] |
81 | 133 |
|
82 | 134 |
|
|
0 commit comments