HunyuanVideo Prepare Latents
Making the noise that becomes your HunyuanVideo 1.5 clip
- hyvid_cfg
- vae
- latents
- reference_image
- latents_dict
- height
- width
- n_tokens
Every diffusion video starts as noise - a tensor of random values that the transformer gradually denoises into frames. In the complete HunyuanVideo 1.5 workflow, HyVideo15LatentsPrepare is the node that makes that starting noise and works out its shape. It's the spiritual equivalent of EmptyLatentImage in an SD workflow, except it has to think about the temporal axis too: the latent video isn't just 16x smaller in each spatial dimension, it's 4x shorter in time, because the 1.5 VAE compresses both.
What it does
Given hyvid_cfg (from HyVideo15CFG, which supplies the frame count, seed, and scheduler) and the vae (so it knows the compression ratios), it:
- Works out the target pixel resolution - from
aspect_ratio(e.g. "16:9") mapped to the nearest supported bucket for the model's resolution, or fromreference_imageif you're doing I2V and want the output to match your input frame. - Compresses that to latent size:
(video_length - 1) // 4 + 1frames, andheight / 16×width / 16spatial. - Generates the random noise latents with your seed, scaled by the scheduler's
init_noise_sigma.
The four outputs are latents_dict (the noise tensor plus its temporal length), and height, width, n_tokens (total latent token count). The height/width outputs wire straight into HyVideo15VaeEncode, which needs the same pixel dimensions for its image conditioning.
The optional latents input accepts a LATENT from elsewhere. Feed one in and this node becomes an img2img-style entry point - instead of fresh noise, the transformer starts from your provided latents, which is how you'd do things like video interpolation or restyling within the complete workflow.
Where it sits
Complete workflow order: HyVideo15CFG → HyVideo15LatentsPrepare → feeds HyVideo15VaeEncode, HyVideo15VisionEncode, and HyVideo15Transformer. In the simplified sampler this whole job happens inside HyVideo15I2VSampler/HyVideo15T2VSampler, so again - you only meet this node when you're building the graph by hand.
Installing it
Part of comfyui_hunyuanvideo_1.5_plugin. ComfyUI Manager → "HunyuanVideo-1.5 nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yuanyuan-spec/comfyui_hunyuanvideo_1.5_plugin
cd comfyui_hunyuanvideo_1.5_plugin
pip install -r requirements.txt
Restart. Needs the VAE present (HyVideo15VaeLoader with path "None" auto-downloads it) and a wired hyvid_cfg.
Common issues
target_dtype defaults to bfloat16 and the node will happily make noise in any of the nine listed dtypes - but if the transformer is running in a different dtype, you get a mismatch error at the first step. Keep them in sync. Also, aspect_ratio must be "W:H" with positive integers (the code explicitly validates this), and a typo like "16x9" throws a ValueError that reads scary but just means "fix the ratio string." If your I2V output keeps coming out at a different size than your reference image, that's this node's bucket-mapping choosing a supported resolution - normal, not a bug.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| hyvid_cfg | HYVID15CFG | — | |
| vae | HYVID15VAE | — | |
| aspect_ratio | STRING | 16:9 | — |
| target_dtype | COMBO | bfloat16 | 9 options: float32, float64, float16, bfloat16, uint8, int8, +3 |
| latentsopt | LATENT | — | |
| reference_imageopt | IMAGE | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| latents_dict | HYVID15LATENTSDICT | — |
| height | INT | — |
| width | INT | — |
| n_tokens | INT | — |