Nodes/ComfyUI-Loopchain/LatentStorageExportLoop
ComfyUI Node Runs on cloud

LatentStorageExportLoop

LatentStorageExportLoop feeds samples back in

By Fannovel16·Created 3 years ago·Updated 3 years ago· 31
LatentStorageExportLoop
  • opt_pipeline
  • LATENT
  • LOOP IDX (INT)
  • IDX_IN_BATCH (INT)
key
batch_size1000
loop_idx0

LatentStorageExportLoop is the latent-flavored twin of ImageStorageExportLoop - same loop mechanic, same batching, but instead of handing back image tensors it hands back latent samples ready for a KSampler. If your loop needs to re-run diffusion passes over frames you already encoded, this saves you the encode round-trip: store latents once, pull slices of them per iteration.

How it works

Like its image sibling, it reads a named bucket from an in-memory Python dict (GLOBAL_LATENT_STORAGE), concatenates everything stored under the key, wraps the result in a torch DataLoader with your batch_size, and returns batch[loop_idx]. The LOOP IDX output walks through the batches and IDX_IN_BATCH (loop_idx % batch_size) tells you where you are inside the current slice.

The typical shape: a LatentStorageImport after VAEEncode (or straight after a KSampler, before decode) collects samples on each pass, and this node reads them back in a second loop - say, for a second-pass refinement where each iteration conditions a different slice. Because latents stay latent, you skip the VAE round-trip entirely on the re-feed.

Inputs

  • key - the bucket name. Must match the import side exactly; the node asserts the bucket exists and raises if it doesn't.
  • batch_size - latents per iteration, default 1000. Set it lower to get one small slice per loop pass.
  • loop_idx - which batch to pull, default 0. The node's Queue button walks it automatically after asking the server how many batches the key holds; you can also drive it from an upstream loop node's index.

Outputs: LATENT (wire it into a KSampler's latent input), LOOP IDX (INT), and IDX_IN_BATCH (INT).

Gotchas

Everything from the image version carries over: storage is RAM-only and server-scoped (restart clears it), re-running an import branch duplicates entries, and the pack is dormant - Fannovel16's Loopchain last saw real work in December 2023 and the README still reads like a draft. There are also genuine quirks in the shipped code: the loop index is known to skip values on some runs, and this node's sibling LatentStorageReset has a bug that makes it crash (more on that in its own article), so clear your storage via the image-side reset or a server restart instead. Install from ComfyUI Manager (search "ComfyUI-Loopchain") or clone into custom_nodes - no pip deps, no model downloads.

CategoryLoopchain/storage

Inputs (4)

NameTypeDefaultDescription
keySTRING
batch_sizeINT1000
loop_idxINT0
opt_pipelineoptLOOPCHAIN_PIPELINE

Outputs (3)

NameTypeDescription
LATENTLATENT
LOOP IDX (INT)INT
IDX_IN_BATCH (INT)INT