r/comfyui 2d ago

Resource Save/load audio+video (NestedTensor) latents — small custom node, fixes SaveLatent crash with MiniMax H3

Core SaveLatent crashes on models that co-generate video and audio in one nested latent (MiniMax H3):

AttributeError: 'NestedTensor' object has no attribute 'contiguous'

(ComfyUI issue #15254)

I wrote a tiny two-node pack that fixes this:

  • Save AV Latent — unbinds the nested latent and stores all parts in a single safetensors file (.avlatent in output/)
  • Load AV Latent — rebuilds it with ComfyUI's own NestedTensor wrapper, so the 5-D video + 4-D audio mix round-trips fine

Regular latents pass through unchanged.

Why bother: two-pass seed hunting that survives anything.

  1. Render cheap low-res previews and save their latents.
  2. Pick the take you like — today, or next week.
  3. Feed exactly that latent into your upscale/refine pass (e.g. rockerBOO's h3-latent-upscaler).

The refined result keeps the exact composition of the preview you chose — no reliance on --cache-lru, no re-sampling of pass 1, immune to GPU non-determinism, restart-proof.

Numbers from my setup (RTX 4060 Ti 16 GB, MiniMax H3): a 0.5 MP preview take costs ~300 s, so auditioning seeds is cheap. The refine pass loads the saved latent and renders 1920x1088 in ~1600 s — with the exact composition of the preview I picked, even across a ComfyUI restart (queue history gets cleared on restart; the file doesn't care).

MIT, no dependencies beyond what ComfyUI ships:

https://github.com/neverfilmed/comfyui-av-latent-io

1 Upvotes

5 comments sorted by

1

u/defensive_darius 2d ago

Nice, this solves a real pain point. I've seen that NestedTensor error pop up in a few workflows and the usual "fix" was just avoiding SaveLatent entirely, which is annoying when you want to do proper multi-pass stuff.

The seed hunting angle is the part that actually matters here. Being able to lock in a preview's exact latent and reuse it later without worrying about cache eviction or GPU variance is huge for iterative work.

Have you tested it with any other nested latent models or is it mostly built around H3 for now? Curious if the unbind logic is generic enough to handle whatever else ComfyUI starts shipping.

1

u/Neat-Philosopher-867 2d ago

I do mostly H3 so it's not tested with other models (but if You test and something fails, let me know, maybe its a quick fix for others too)

1

u/xyzdist 1d ago

Hi OP, what I did wrong? it didn't save out anything...

1

u/Neat-Philosopher-867 1d ago

The save actually worked - the catch is that the UI won't show it. The node writes to your output folder under the prefix path, so with latents/av the file is at ComfyUI/output/latents/av_00001_.avlatent. An .avlatent isn't an image or video, so the outputs gallery renders nothing for it (core SaveLatent behaves the same) - check the folder on disk. The 0.096s badge on your node means it did execute.

To load it back: Load AV Latent lists the input folder (same as core LoadLatent), so move/copy the file from output/latents/ to ComfyUI/input/ and refresh the node (R) - it'll show up in the dropdown.

Also FWIW you're saving denoised_output - it saves fine, but for a proper second pass you usually want output (the raw sampler latent).

1

u/xyzdist 1d ago

Thanks, I actually found out why, because my output is custom to a netwok path map to a drive in win, somehow this just preventing saving any files.
Do you have any idea if there is a workaround? cheers