Nodes/ComfyUI_mittimiTools/SaveLatentToInputFolder
ComfyUI Node

SaveLatentToInputFolder

Save a latent into ComfyUI's input folder, so you can load it back — or hand it to someone

By mittimi·Created 7 months ago·Updated 6 months ago· 0
SaveLatentToInputFolder
  • samples
    filename_prefixlatents/ComfyUI

    This is core ComfyUI's SaveLatent, pointed at a different folder. Instead of writing your .latent file to the output directory, SaveLatentToInputFolder writes it into ComfyUI's input folder - the same place LoadLatent reads from. Which means the latent you save here shows up in the Load Latent dropdown on the next workflow, ready to be picked back up.

    Why you'd actually use it

    Three reasons, in order of how often people actually hit them:

    1. Latent sharing. The pack even ships an example.latent file in its toInputFolder directory as a demo of the idea. A .latent file is a snapshot of the latent tensor - the compressed representation the diffusion model actually works with, before the VAE decodes it to pixels. Send someone a .latent and they can Load Latent it and continue from exactly your point, without the lossy decode-then-re-encode round trip. That's a real thing in the community: two models sharing the same VAE can pass latents to each other directly, skipping a whole lossy cycle.
    2. Checkpoint-style staging. Save a latent mid-workflow, then in a later session Load Latent and keep going from that exact state. Great for iterating on an img2img or refinish pass without regenerating.
    3. Cross-workflow handoff. Generate in one graph, process the latent in another. Since it lands in the input folder, it behaves like any other input asset.

    How it works

    The mechanism is right in the source, and it's short:

    self.output_dir = folder_paths.get_input_directory()
    ...
    file = f"{filename}_{counter:05}_.latent"
    output["latent_tensor"] = samples["samples"].contiguous()
    output["latent_format_version_0"] = torch.tensor([])
    comfy.utils.save_torch_file(output, file, metadata=metadata)
    

    It uses ComfyUI's own save path machinery (get_save_image_path) with the input directory, names the file {prefix}_{counter:05}_.latent, and writes a safetensors file containing latent_tensor plus a version marker - the same format core ComfyUI's SaveLatent produces, which is exactly why LoadLatent reads it back without fuss. Prompt metadata is embedded as JSON unless you've disabled metadata in ComfyUI's settings.

    One behavior worth knowing: if samples isn't connected, the node does nothing and returns silently. So it's safe to leave in a workflow with the latent unhooked - it just won't save anything.

    The inputs that matter

    Both inputs are optional, which is the giveaway that this node is a convenience wrapper:

    • samples - the LATENT you want to save. Wire this from your KSampler (or wherever your latent comes from).
    • filename_prefix - the name and subfolder. Default is latents/ComfyUI, so files land in input/latents/ComfyUI_00001_.latent and keep counting up. Change it if you want them somewhere else in the input tree.

    There are no outputs - this is an output node, so it runs last and the saved file is reported in the UI results. In the node search box, it's also findable by the alias "export latent".

    Installing it

    Part of mittimi/ComfyUI_mittimiTools, a small personal pack by mittimi. ComfyUI Manager: search ComfyUI_mittimiTools and install. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/mittimi/ComfyUI_mittimiTools
    

    Restart ComfyUI. Only dependency is toml (already shipped with ComfyUI), no models to download.

    Where people get burned

    • Your input folder fills up. The whole point is writing to input, and input files get treated as assets - they show up in your Load Latent dropdown and clutter the input directory. The default latents/ subfolder helps; keeping the prefix tidy is on you.
    • Don't confuse it with core SaveLatent. Core writes to output/, this writes to input/. If you save with the wrong one you'll be hunting through the wrong folder when the file isn't where you expect.
    • It's a .latent, not an image. No VAE decode happens, so there's nothing to preview here - if you want to look at what you saved, decode it in the same workflow before or after saving. The file format only opens via LoadLatent, which is the point, but it surprises people the first time.
    CategorymittimiTools

    Inputs (2)

    NameTypeDefaultDescription
    samplesoptLATENT
    filename_prefixoptSTRINGlatents/ComfyUI

    Outputs (0)

    No outputs