ComfyUI Node

Save SDLI Image

Stash Your Latents Inside a Normal-Looking .webp

By MitoshiroPJ·Created about a year ago·Updated about a year ago· 1
Save SDLI Image
  • samples
  • vae
    latent_typeSDXL
    reduction_ratio1/1
    quality80
    filename_prefixComfyUI
    positive_prompt
    negative_prompt

    If you've ever re-run a whole Flux generation just to try a different upscale, or kept a workflow open for days because you're scared of losing a good seed's latents, this is the node that quietly fixes that. Save SDLI Image takes the latents straight out of your sampler and writes them to disk - inside a file that also happens to be a perfectly ordinary .webp you can open anywhere. The preview is just for you. The latents are the payload.

    What SDLI actually is

    SDLI stands for "Stable Diffusion Latents in Imagefile," the format documented in MitoshiroPJ's companion sdli_tools repo. A generated file looks like a WebP image, but it's really a RIFF container holding two things: the decoded preview image and an SDLI chunk containing the latents, serialized as safetensors. This pack is the writer half of that format - the README points to sdli_tools for the spec and the tooling to read files back.

    Why you'd want latents on disk

    The stock Save Image node decodes your latents to pixels and throws the latent away. That's fine for archiving, but it's a one-way door: VAE decode and encode are both lossy, so every pixel → latent → pixel round trip grinds a little quality off your image. If you want to resume sampling, try a different sampler on the same seed, or upscale and re-diffuse, you normally have to re-encode pixels or just re-run the sampler from scratch. SDLI skips all of that - the latent tensor that came out of the KSampler is stored exactly as-is (well, cast to fp16, more on that below), so you can pick up from where diffusion stopped without paying the encode tax.

    How it works

    Wire samples (LATENT) from your KSampler into the node. It decodes the latent with whatever VAE you connect, or - if vae is empty - with the matching TAESD approximation, shrinks that image according to reduction_ratio, writes it as a WebP at your chosen quality, then appends the safetensors-serialized latents as an SDLI chunk in the same RIFF file. Prompt and workflow metadata ride along in the WebP EXIF and the safetensors headers.

    The inputs that actually matter:

    • samples (required) - the latents. This node wants latents, not an image; feeding it a decoded image defeats the entire point.
    • latent_type - SD1, SDXL, SD3, or FLUX.1. Picks which TAESD the fallback loads and tags the file so the reader knows what it's dealing with.
    • vae (optional) - wire your real VAE here. Leave it empty and the node auto-loads TAESD from models/vae_approx. Fast, but the embedded preview comes out visibly softer than a full VAE decode. Your latents are unaffected either way.
    • reduction_ratio - 1/1 through 1/8. Shrinks only the preview WebP, never the latents. 1/4 or 1/8 gives you a cheap thumbnail next to full-resolution latents.
    • quality - WebP quality (default 80) for that preview. The latents are lossless regardless.
    • filename_prefix - output naming with %year%/%month%/%day%/%hour%/%minute%/%second%/%width%/%height% tokens and subfolder support; files come out as {prefix}_00001.webp and auto-increment. If positive_prompt is left empty, the node helpfully grabs the text from the first CLIPTextEncode in your graph.

    It's a terminal output node - no output sockets, files land in ComfyUI/output/ and show up in the UI viewer.

    Installing it

    ComfyUI Manager works (search "ComfyUI SaveImage SDLI"), or the old-fashioned way:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MitoshiroPJ/ComfyUI_save_image_sdli
    

    Restart ComfyUI. There's no requirements.txt and no extra pip deps - it leans entirely on the torch, safetensors, PIL, and numpy ComfyUI already ships. The only model files you might need are for the TAESD fallback.

    Gotchas

    • No VAE, no TAESD, error. If vae is empty, the node calls ComfyUI's built-in TAESD loader, which reads models/vae_approx and expects taesd_encoder/taesd_decoder, taesdxl_*, taesd3_*, or taef1_* files (from madebyollin/taesd releases). Drop the matching encoder+decoder pair into ComfyUI/models/vae_approx and it just works.
    • Don't judge the output from the preview. It's a lossy WebP, and if you skipped the VAE it's TAESD-decoded on top of that. The real image is in the latents, not the thumbnail.
    • Latents are stored fp16. Fine for resampling and further diffusion, but don't expect bit-identical continuation of a full-precision run if you're chasing exact reproducibility.

    For a quick look without touching your output folder, the sibling Preview SDLI Image node does the same thing into the temp directory.

    Categoryimage

    Inputs (8)

    NameTypeDefaultDescription
    samplesLATENTThe latent to be decoded.
    latent_typeCOMBOSDXL4 options: SD1, SDXL, SD3, FLUX.1
    reduction_ratioCOMBO1/14 options: 1/1, 1/2, 1/4, 1/8
    qualityINT80
    filename_prefixSTRINGComfyUIThe prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes.
    vaeoptVAEThe VAE model used for decoding the latent.
    positive_promptoptSTRING
    negative_promptoptSTRING

    Outputs (0)

    No outputs