ComfyUI Node

Pt To Float32

Casting tensors back to full-precision float32

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt To Float32
  • tens_a
  • TENSOR

Pt To Float32 casts a tensor to 32-bit floating point - the default precision that most of PyTorch and most of this pack's nodes expect. It's the "un-squish" to PtToFloat16's "squish": wherever half precision got you into trouble, this node is how you get back to full-precision float32.

It's part of ComfyUI-Pt-Wrapper, the ~200-node pack that puts PyTorch tensor math and model training into ComfyUI's node graph. Like its siblings PtToFloat16, PtToBfloat16, PtToInt32 and the rest of the cast family, it changes a tensor's dtype mid-pipeline without touching its shape.

How it works

One line under the hood: tens_a.to(torch.float32). A new tensor comes out with the same shape and the same values, just promoted to full precision; the input is left alone. Where the node earns its keep:

  • Undoing a half-precision cast. You cast something to fp16 to save VRAM, fed it through the heavy part, and now a downstream node complains or your math is drifting. Cast back to fp32 and your values get their precision back.
  • Dtype mismatch fixes. Lots of nodes - and plenty of model code - silently assume float32. If you're getting "expected Float but got Half" style errors in your tensor pipeline, a PtToFloat32 placed right before the offending node is the classic fix.
  • Sensitive math. If you're accumulating losses, computing means, or doing anything where precision compounds, doing it in fp32 instead of fp16 is meaningfully more accurate.

Inputs and outputs

Minimal, like all the cast nodes:

  • tens_a (TENSOR) - the input tensor.
  • TENSOR output - the same data as float32.

Wire the output straight on to whatever needed the full precision.

Installing the pack

Standard pack install, done once for all ~200 nodes:

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

Restart ComfyUI. Or use ComfyUI Manager and search "ComfyUI-Pt-Wrapper" - it's on the Comfy Registry, so Manager installs it and pulls the Python dependencies (pandas, scikit-learn, transformers, sentencepiece, and the rest) automatically. As always with this pack: a single cast node brings the whole dependency train, but the pack is built for people doing real data/training work in the graph.

Common issues

  • It doesn't "restore" information. Casting fp16 → fp32 recovers range and precision for future math, but values already rounded away in half precision stay rounded. Round-trips are a one-way door for the low bits.
  • Memory goes back up. You converted to fp16 to save VRAM; converting back doubles the footprint again. Do it at the point where you need the precision, not earlier.

There's nothing glamorous here, and that's the point. When your pipeline hands you a dtype error or your numbers start drifting, this is the quiet fix that makes everything work again.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tens_aTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR