Nodes/ComfyUI_Base64_IO/Base64 -> Latent
ComfyUI Node

Base64 -> Latent

Rehydrate a Latent on Another Machine (Carefully)

By lenML·Created 9 months ago·Updated 9 months ago· 2
Base64 -> Latent
    • LATENT
    b64_string

    This is the flagship use of the ComfyUI_Base64_IO pack: take a Base64 string that AnyToBase64 produced and turn it back into a LATENT socket you can plug straight into a KSampler or a VAE Decode. It's how you split a workflow across machines without splitting your graph.

    The pitch, concretely: on a weak box or a CPU you run the cheap steps - CLIP text encode, building a fresh latent from your seed and resolution. AnyToBase64 flattens that latent to a string, you ship the string over an HTTP API (or a database column, or a clipboard), and this node on the GPU machine rebuilds the exact tensor - batch size, channel count, resolution, the whole state. The KSampler downstream just keeps going, as if the graph had never crossed a network. The heavy U-Net work stays on the big GPU, and nothing but text crossed the wire. The same trick works for caching: a latent you'll reuse can live as a string in storage instead of being re-randomized every run.

    How it works

    The decode is base64.b64decode followed by torch.load(buffer, map_location="cpu", weights_only=False). The CPU pin is the part that makes cross-machine transfers work - wherever the latent was saved, it rehydrates on CPU, so there's no "this tensor is on a device I don't have" crash. And weights_only=False is why the round-trip preserves ComfyUI's full internal structure rather than just bare tensors.

    Which brings us to the security warning, stated plainly: that same weights_only=False means loading a string runs whatever Python was pickled into it. This is the node where the README's warning is load-bearing, not a formality. Only feed it strings you generated yourself or got from a source you control. A Base64 blob from a stranger is arbitrary code execution wearing a text-file costume.

    Inputs and output

    One input: b64_string, a multiline STRING widget, empty by default. Paste the string in, or wire it from another string node if it's coming from a file or an API. One output: LATENT, typed properly - which is the point of using this node over the wildcard Base64ToAny, because ComfyUI can still type-check everything downstream.

    Installation

    Install once for the whole pack via ComfyUI Manager (search ComfyUI_Base64_IO), or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/lenML/ComfyUI_Base64_IO.git
    

    Then restart ComfyUI. It's a tiny MIT pack from lenML (a solo dev who also maintains Speech-AI-Forge), with no dependencies beyond torch, which ComfyUI already bundles - requirements.txt is empty, so no install scripts, no model downloads.

    The trap: it fails quietly

    Here's the gotcha that will actually bite you, and it's grounded in the source rather than hearsay: when the input is empty or fails to decode, this node does not error. It logs a warning and returns a fallback latent of all zeros at 1×1 resolution - specifically (1, 4, 8, 8). That's a structurally valid LATENT, so your workflow keeps running, and then your VAE decodes an 8×8 latent into a tiny sliver of a picture, or your sampler grinds through a no-op.

    So the failure symptom isn't a red node - it's a mysteriously tiny or garbage output and no error anywhere. If that happens, the string didn't decode: check you copied the whole thing, that nothing truncated it, and that it matches what AnyToBase64 emitted. Contrast this with Base64ToAny, which raises ValueError on bad input. This node chooses mercy, and mercy is a lie. A one-line sanity check before you run a big batch is worth it.

    If your payload is a conditioning rather than a latent, the sibling Base64ToConditioning is the cleaner match - text embeddings are tiny compared to a latent, so prompt caching through that node is the cheap, fast version of this trick. This node is for when the thing crossing the wire is the picture's compressed state itself.

    CategoryBase64_IO

    Inputs (1)

    NameTypeDefaultDescription
    b64_stringSTRING

    Outputs (1)

    NameTypeDescription
    LATENTLATENT