Nodes/XB_ToolBox/XB-BOX - 🎨 Bernini 条件注入(VAE分块)
ComfyUI Node

XB-BOX - 🎨 Bernini 条件注入(VAE分块)

Feed source video and reference images into Bernini without OOMing

By wjluoxiao·Created 5 months ago·Updated 6 days ago· 302
XB-BOX - 🎨 Bernini 条件注入(VAE分块)
  • positive
  • negative
  • vae
  • source_video
  • reference_video
  • reference_image_0
  • reference_image_1
  • reference_image_2
  • reference_image_3
  • reference_image_4
  • reference_image_5
  • reference_image_6
  • reference_image_7
  • positive
  • negative
  • latent
width832
height480
length81
batch_size1
ref_max_size848
vae_tile_size256
scale_methodarea

Bernini is ByteDance's Wan-derived video editing model, and the thing that makes it work is context latents - the source video you're editing and up to eight reference images get VAE-encoded and injected into the conditioning so the model can actually see what it's editing. In stock ComfyUI you'd wire up a pile of encode steps and hope your VRAM survives. XB_BerniniConditioning wraps the whole job into one node: it builds the empty latent, encodes every context input you give it, and returns ready-made positive/negative conditioning plus the latent. With a tiled-VAE option to keep the memory bill sane.

It's categorized under XB_ToolBox/Wan, and it exists because Bernini is heavy - the KB's own panel notes that editing effectively doubles compute (the source video is part of the model input), and VRAM is the recurring complaint. The node's VAE tiling is aimed straight at that.

How it works

The node does three things in go():

  1. Builds the output latent: a zero tensor of shape [batch, 16, ((length-1)//4)+1, height//8, width//8] - the standard Wan-style latent for your chosen width/height/length/batch.
  2. Encodes context inputs: any of source_video, reference_video, or the eight reference_image_0…7 slots that are connected get resized (long edge to ref_max_size, default 848) and VAE-encoded via a tiled encoder (vae_tile_size, default 256) so a large frame doesn't blow VRAM.
  3. Injects: the encoded context is stored under context_latents on both positive and negative conditioning, then positive/negative/latent are returned together.

So one node does what the stock Bernini workflow scatters across a half-dozen encode + set-values steps, and the tiling is the memory knob.

The inputs that matter

  • positive / negative - your text conditioning (from a CLIP/Flux encode step).
  • vae - the Wan VAE.
  • width / height / length / batch_size - output latent geometry. Length is in frames (default 81, the classic Wan native length); note it's the output length, independent of your source video's frame count.
  • source_video - the clip you're editing (for v2v). Optional; leave unconnected for pure text/image-to-video.
  • reference_image_0…7 - up to eight reference images (for multi-ref character consistency). Each is treated as an individual context frame.
  • ref_max_size - long-edge resize cap for references; keeps big images from inflating the context.
  • vae_tile_size - the VRAM lever. Lower it if encoding OOMs; raise it for speed if you have headroom.
  • scale_method - resize algorithm for inputs (area default).

Outputs: positive, negative (CONDITIONING with context latents baked in), latent (the empty latent to sample from).

Installing

Comes with XB_ToolBox - ComfyUI Manager → XB_ToolBox, or

cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git

restart. It needs a working Wan VAE and the Bernini model loaded elsewhere in the graph (this node doesn't load any model itself).

Common issues

  • OOM during encode - drop vae_tile_size (256 → 192 → 128). Tiling is the whole point here; if you still OOM, reduce ref_max_size or feed fewer references.
  • Output latent and video don't match - source_video is truncated to length frames but not otherwise downsampled temporally; keep your source ≤ the length you set, or you'll silently get only the first N frames as context.
  • No context, no edit - if you forget to connect source_video, you get a text-to-video latent with context-latent conditioning that references nothing. For edits, the source clip is the whole show.
  • Frame-count rule - keep length in the 4N+1 family (81, 121…) that Wan expects, or the sampler may reject it.

This is the node that makes a Bernini workflow actually fits on a consumer card. It won't make Bernini cheap - nothing does - but it removes the encode-side explosion that used to kill runs before the first denoising step.

CategoryXB_ToolBox/Wan

Inputs (20)

NameTypeDefaultDescription
positiveCONDITIONING
negativeCONDITIONING
vaeVAE
widthINT83216–8192
heightINT48016–8192
lengthINT811–8192
batch_sizeINT11–4096
source_videooptIMAGE
reference_videooptIMAGE
reference_image_0optIMAGE
reference_image_1optIMAGE
reference_image_2optIMAGE
reference_image_3optIMAGE
reference_image_4optIMAGE
reference_image_5optIMAGE
reference_image_6optIMAGE
reference_image_7optIMAGE
ref_max_sizeoptINT84816–8192
vae_tile_sizeoptINT25664–3840
scale_methodoptCOMBOarea5 options: lanczos, bilinear, bicubic, nearest-exact, area

Outputs (3)

NameTypeDescription
positiveCONDITIONING
negativeCONDITIONING
latentLATENT