Sign In

Multi-Prompt Batching, Bypass LoRAs, and Wan2.1 VAE Bottlenecks for Anima in ComfyUI

1

Multi-Prompt Batching, Bypass LoRAs, and Wan2.1 VAE Bottlenecks for Anima in ComfyUI

Hardware: single RTX 5080 (16 GB GDDR7), ComfyUI 0.46.0, Anima (28-block DiT, Wan2.1 16-channel [B, 16, 1, H/8, W/8] latents, Qwen3 [B, 512, 1024] conditioning).

A normal batch of 4 in ComfyUI repeats one conditioning tensor across four seeds. When I'm exploring a new subject or checking 8 style LoRAs against a locked character LoRA, that forces either 32 separate queue items or hand-editing prompts between runs. Even worse, running the full Wan2.1 3D VAE after every micro-batch just to look at small previews drove a 16 GB card to 15.85 GB VRAM and ate nearly half the wall clock.

I wrote a small ComfyUI node pack (comfyui-blindbox-draft, Apache-2.0) to stack four distinct prompts per forward pass, co-group LoRA swaps, stream previews to a separate wall node, and resume high-res restore from saved latents. Measuring each piece on the 5080 gave these numbers:

  • micro_batch=4 with 4 unrelated prompts (512x640, 8 steps, CFG 1.0): 0.12 s encode, 1.63 s DiT sample, 2.23 s full Wan2.1 VAE decode (3.86 s total). Four warm solo calls take 0.455 s each (1.82 s for 4), so batching itself barely beats warm solo compute.

  • 8 real 28-block Anima LoRAs across 32 images (micro_batch=4, host-RAM cached): load_bypass_lora_for_models finished in 16.37 s (7.50 GB VRAM, 0.0 MAE base drift) against 18.78 s for weight patching (7.32 GB).

  • End-to-end 32-card wall: 38.48 s and 15.85 GB peak VRAM at 512x640, 8 steps with full Wan2.1 VAE every batch, versus 24.69 s (0.77 s/card) and 7.5 to 8.1 GB VRAM at 576x768, 6 steps using lighttaew2_1.safetensors (TAEHV) for wall previews. Those two runs differ in both step count (8 vs 6) and resolution (512x640 vs 576x768), so the 13.8 s drop combines two fewer steps with removing the 3D VAE from the preview loop.

  • Two-variation 896x1152 high-res re-imagine: 125.96 s when vae.decode ran inside the variation loop, down to 29.45 s once decode moved after the loop.

BlindBoxPreviewWall 8-column fullscreen wall showing 32 Anima cards rendered in 24.69s across 8 style LoRAs

1. Multi-Prompt Batching on [B, 512, 1024]

Anima runs preprocess_text_embeds(c_in, t5_ids, t5xxl_weights=t5_w) per prompt and pads every conditioning tensor to [1, 512, 1024]. Because the width is fixed, four unrelated prompts can be pre-encoded individually on CPU/GPU and concatenated along dim 0 before comfy.sample.sample. From comfy_runtime/anima_batch.py:

empty_1 = torch.zeros([1, 16, 1, height // 8, width // 8], device="cpu")
noise = torch.cat([comfy.sample.prepare_noise(empty_1, c.seed, None) for c in cards], dim=0)
latent_image = torch.zeros_like(noise)

cond_cat = torch.cat([encoded_map[c.card_idx] for c in cards], dim=0)
positive = [[cond_cat, {}]]
negative = [[torch.zeros_like(cond_cat[:1]), {}]]

I checked the four batched outputs against four solo runs at identical seeds to make sure cross-attention didn't bleed across batch slots. Each card kept its own subject, camera angle, and palette, though pixel MAE between batched and solo slots was non-zero (2.40 to 48.01 on a 0-255 scale for slots 1 through 3 because cuBLAS/SDPA batch kernels and sampler noise state diverge across batch dimensions, even when the visual scene stays on its own prompt).

Raw DiT compute barely sped up:

Run (512x640, 8 steps, CFG 1.0)                Time    Note
---------------------------------------------  ------  ----------------------------------
4 solo prompts (call 0 cold + calls 1-3 warm)  2.70 s  1.335 s, 0.455 s, 0.454 s, 0.455 s
4 warm solo calls extrapolated (4 x 0.455 s)   1.82 s  Steady-state floor
micro_batch=4 DiT sample only                  1.63 s  1.12x over warm solo
micro_batch=4 + full Wan2.1 VAE decode         3.86 s  Decode alone took 2.23 s

A 1.12x DiT speedup is small. Keeping micro_batch=4 still pays off because LoRA group mounts, Wan2.1 latent RGB previews (156 to 161 ms per callback), and ComfyUI wrapper overhead amortize across four images, and pre-encoding all 32 prompts to CPU tensors lets Qwen3 leave VRAM before sampling starts.

2. Bypass Hooks vs Weight Patching Across 8 LoRAs

Reading safetensors from disk on every group change stalls a 32-card run. Holding the run's working set in a host-RAM LRU cache limits disk reads to one cold pass (0.58 s total across 8 LoRAs), and sorting cards that share a LoRA set into adjacent micro-batches limits mounts to once per group.

I timed ComfyUI's regular weight patching against load_bypass_lora_for_models across 8 real 28-block Anima LoRAs (32 images, micro_batch=4):

Mode    Median swap  Median batch  32 imgs total  Peak VRAM  Drift on base
------  -----------  ------------  -------------  ---------  -------------
patch   11.9 ms      2.31 s        18.78 s        7.32 GB    0.0 MAE
bypass  13.4 ms      1.95 s        16.37 s        7.50 GB    0.0 MAE

Standard patching recalculates patched linear weights through ModelPatcher.calculate_weight whenever a group loads; bypass mode leaves the frozen base tensors alone and evaluates the low-rank adapters in forward hooks. That shaved 2.41 s off 32 images at a cost of 188 MiB extra VRAM. First-image pixel difference between bypass and patch was 1.88/255 MAE, and unmounting left 0.0 MAE drift on the base UNET. Bypass is the default, with automatic per-group fallback to patch when an adapter layer lacks bypass support.

3. Wan2.1 3D VAE Memory Spikes and Mid-Loop UNET Eviction

On a 16 GB card, the Wan2.1 3D causal-convolution VAE dominated both memory and runtime.

In the first full 32-card run (512x640, 8 steps, full Wan2.1 VAE every batch), peak VRAM hit 15.85 GB (15846 MiB) and total time hit 38.48 s (encode 1.70 s, LoRA swaps 1.43 s, 0 OOM retries). Decoding four [1, 16, 1, 80, 64] latents in one VAE call multiplies 3D activation memory by 4x right while the DiT still occupies VRAM. Capping full-VAE calls to max_vae_batch=2 with a per-slice OOM fallback (comfy_runtime/anima_batch.py) stopped the 15.85 GB spike, and using Apache-2.0 lighttaew2_1.safetensors (45.3 MB) through ComfyUI's native TAEHV path took the 3D VAE out of the wall loop entirely.

Run (RTX 5080 16 GB)      Config                     Time      VRAM        Notes
------------------------  -------------------------  --------  ----------  ----------------------
32-card wall (full VAE)   512x640, 8 st, 8 LoRAs     38.48 s   15.85 GB    1.43 s swap, 14 misses
32-card wall (fast wall)  576x768, 6 st, 8 LoRAs     24.69 s   7.5-8.1 GB  Cold cache, 9 misses
16-card char showdown     512x640, 8 st, char+style  12.35 s   ~7.5 GB     488 ms swap, 7 misses
Enhance strict_turbo      896x1152, disk run_id      6.67 s    ~8.5 GB     bundle=None
Enhance strict_quality    896x1152, 20 st, d=0.48    11.68 s   ~8.5 GB     bundle=None
Enhance creative (2x)     896x1152, mid-loop dec     125.96 s  15.69 GB    Var #2: 4.92 s/it
Enhance creative (2x)     896x1152, post-loop dec    29.45 s   ~9.2 GB     Both vars: 2.79 it/s

The 125.96 s number came from an ordering mistake in comfy_runtime/enhance_runner.py. Calling vae.decode at the end of variation #1 inside the loop forced ComfyUI to offload the UNET to fit the 3D VAE on 16 GB VRAM, then reload the UNET in low-VRAM mode for variation #2, collapsing variation #2 from 2.79 it/s down to 4.92 s/it. Moving vae.decode out of the sampling loop fixed it:

sampled_runs: list[tuple[int, int, Any]] = []
for var_i in range(eff_vars):
    var_seed = base_seed if var_i == 0 else ((base_seed + 1009 * var_i) & 0x7FFFFFFF)
    noise = comfy.sample.prepare_noise(init_latent, var_seed, None)
    samples = comfy.sample.sample(work_model, noise, int(eff_steps), float(eff_cfg), ...)
    sampled_runs.append((var_i, var_seed, samples.detach().cpu()))

for var_i, var_seed, samples_cpu in sampled_runs:
    img_t = vae.decode(samples_cpu)
    if img_t.ndim == 5:
        img_t = img_t[:, 0]
    out_tensors.append(img_t.detach().cpu())

One extra detail on Wan2.1's VAE: vae.decode() returns a 5D [B, 1, H, W, 3] video tensor rather than 4D [B, H, W, 3], which crashes PIL.Image.fromarray unless you squeeze dim 1 (img_t[:, 0]).

Draft 512x640 card compared against 896x1152 strict turbo, strict quality, and two creative re-imagine variations

4. What Stayed Soft or Broke on Live ComfyUI 0.46.0

lighttaew2_1 is still an approximate decoder. Fine eyelashes and thin ink hatching come out visibly softer on the preview wall than through the full Wan2.1 VAE, so feeding a fast-wall preview PNG straight into img2img degrades high-res restore. Every finished micro-batch writes latent_XX.pt, its preview PNG, and manifest.json to temp/blindbox/<run_id>/. DraftPickAndEnhance skips the preview PNG when the wall used lighttaew2_1 and re-decodes latent_XX.pt through the full Wan2.1 VAE before sampling. Per-batch disk writes also mean clicking Abort mid-run leaves completed slots usable through run_id_fallback.

Three integration issues turned up only on live ComfyUI 0.46.0 rather than in unit tests:

  • folder_paths.get_folder_paths("loras")[0] pointed to an empty default directory on a machine configured with extra_model_paths.yaml, returning zero LoRAs until BlindBoxLoRARack walked every configured loras root and verified 28-block safetensors headers across all of them.

  • In Chromium CSS Grid, 4-column Fullscreen compressed all eight implicit rows into one viewport height and squashed every portrait tile into a thin horizontal strip. Bare aspect-ratio: 3 / 4 failed inside the flex-constrained scroll area; switching to a padding-top: 133.3333% pseudo-element with min-height: 0 held 400x532 scrollable posters.

  • LiteGraph invokes onNodeCreated with this.id = -1 before configure() assigns the saved workflow's node ID, so keying WebSocket handlers in a Map by String(this.id) missed live updates on restored graphs until handlers read controller references directly off app.graph nodes.

4-column fullscreen BlindBoxPreviewWall holding 3:4 portrait tiles in Chromium CSS Grid

What I keep enabled now: auto_fast_wall (lighttaew2_1 for the 1200x880 decoupled BlindBoxPreviewWall, full Wan2.1 VAE from latent_XX.pt on Enhance), bypass LoRA mounting with host-RAM caching, max_vae_batch=2 when full VAE runs on the wall, and post-loop vae.decode on multi-variation Enhance.

  • comfyui-blindbox-draft: 5 decoupled ComfyUI nodes, public UI/API workflows, and scripts/draft_cli.py (Apache-2.0).

  • agent-genops: ComfyUI render discipline, workflow compiler, and companion node index.

1

Comments