ComfyUI Node

Pt Zeros

A tensor full of zeros, on demand — more useful than it sounds

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Zeros
    • TENSOR
    size
    data_type

    Pt Zeros creates a brand-new tensor where every value is zero. You type the shape, pick the data type, and out pops an initialized tensor ready to be filled, added to, or fed somewhere. It sounds like the most pointless node in existence until you realize how often real ML code does exactly this - initializing a bias, seeding an RNN's hidden state, creating a mask, or reserving a tensor to accumulate results into.

    It's part of ComfyUI-Pt-Wrapper, the ~200-node pack that puts PyTorch tensor operations and training into ComfyUI's node graph. Pt Zeros is one of the tensor-creation nodes (PtArange, PtLinspace, PtFull, PtFloatCreate…), the "make me a tensor from scratch" family that feeds everything downstream.

    How it works

    Under the hood it's torch.zeros(shape, dtype=...). You enter the shape as a text list - the author's own example: to build a 4D tensor of batch size 2, 3 channels, height 96, width 32, enter:

    [2,3,96,32]
    

    The node parses that, creates the zero tensor, and hands it out. Zero tensors matter in this pack for a concrete reason: the RNN training node (PtTrainRNNModel) takes an optional initial hidden state h_0, and a zeros tensor is exactly the neutral starting point you'd wire in there. Same trick applies to masks and bias-like constants anywhere in a custom model you're assembling from layer nodes.

    Inputs and outputs

    Two inputs, one output:

    • size (STRING, multiline) - the shape as a list, e.g. [2,3,96,32]. The multiline box gives you room if you're building shapes programmatically.
    • data_type (dropdown) - the dtype, from a full menu: float32, float16, bfloat16, float64, uint8, int8, int16, int32, int64, bool.
    • TENSOR output - the zero-filled tensor.

    For most training work float32 is the default you want. Reach for float16/bfloat16 when you're matching a half-precision model, and bool when you're building a boolean mask to multiply or index with.

    Installing the pack

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
    

    Restart ComfyUI. Or ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → install (it's on the Comfy Registry, so dependencies like pandas, scikit-learn, transformers and sentencepiece get pulled automatically). As ever with this pack, a tiny utility node rides in on a big dependency list - the trade-off for having the whole PyTorch toolkit in the graph.

    Common issues

    • Malformed size string. The node expects a list literal like [2,3,96,32]. Typos, missing brackets, or comma mistakes will fail at parse time - the error message points right at the string, so check the format first.
    • Wrong dtype for the job. A zeros tensor created as float16 stays float16; if the model expects float32, you'll get a dtype mismatch. If unsure, use float32 and let a PtToFloat32/PtToFloat16 node handle conversions at the boundary.
    • Shape confusion with a dataloader batch. The RNN h_0 needs [num_layers, batch_size, hidden_size] (or [2 * num_layers, batch_size, hidden_size] for bidirectional models) - not the input shape. Read the training node's docs on the shape before you wire zeros in.

    It's the kind of node you don't think about until you need a neutral tensor and realize there's no other way to make one in the graph. Now there is.

    CategoryData Analysis

    Inputs (2)

    NameTypeDefaultDescription
    sizeSTRING
    data_typeCOMBO10 options: float32, float16, bfloat16, float64, uint8, int8, +4

    Outputs (1)

    NameTypeDescription
    TENSORTENSOR