ComfyUI Node

ChangeTensorType

The dtype converter for when your tensor doesn't match your model

By TashaSkyUp·Created about a year ago·Updated about a year ago· 1
ChangeTensorType
  • input_data
  • TORCH_TENSOR
dtypetorch.float32

Every ComfyUI user knows the flavor of this error: "Expected all tensors to be on the same device" or "expected scalar type Float but found Double". Tensor dtype mismatches are the quiet killers of ML workflows, and ChangeTensorType is the pack's fix - it converts any TORCH_TENSOR from one dtype to another via a simple text field. Feed it a float64 tensor that's about to hit a float32 model, and it comes out the other side matching.

In the EternalKernel PyTorch Nodes pack you'll mostly hit this at the seams: your dataset's labels come out as int64 but TrainModel with a regression loss wants floats; or ListToTensor built a float32 tensor and your hand-written loss wants float64. It's a plumbing node - boring, but you'll be glad it's there on the day it saves you a 20-minute hunt.

How it works

The dtype input is a string you type (default torch.float32), not a dropdown. The node maps your text through PyTorch's dtype names - torch.float32, torch.float64, torch.int64, torch.bool, torch.bfloat16, torch.half, and the int types - and calls input_data.type(dtype). If you type something it doesn't recognize, it falls back to float32, so double-check your spelling when the output suddenly looks floaty.

Inputs and output

  • input_data (TORCH_TENSOR) - any tensor the pack produces: from ComfyUIImageToPytorchTENSOR, ListToTensor, FlattenTensor, a dataset's features/labels, etc.
  • dtype - the target type as text, e.g. torch.float32, torch.int64, torch.bool.

Output: one TORCH_TENSOR in the requested dtype.

Install

ComfyUI Manager, search "EternalKernel PyTorch Nodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes
cd EternalKernelPytorchNodes
pip install -r requirements.txt

Restart ComfyUI; node under ETK/pytorch. No model files. Requirements are the standard stack plus scipy, scikit-learn, transformers, einops.

Common issues

  • Unknown strings silently become float32. The fallback is torch.float32. If you meant torch.int64 and typed torch.integer or left a typo, you'll get floats with no error. The default and the fallback are the same, so a wrong value can be invisible.
  • Casting to int truncates. Going float64 → int64 rounds toward zero and silently loses decimals. If that's not what you meant, you probably wanted to stay in floats.
  • float16 vs bfloat16. For training, bfloat16 is usually the safer half-precision choice on modern cards; plain float16 can overflow on gradients. The node supports both - it's a matter of knowing which you want.
  • Dtype still mismatched downstream? The pack patches ComfyUI's validator to ignore return_type_mismatch errors on load, so a dtype mismatch between two nodes may not flag itself. That's exactly when you'd insert this node manually and re-check.

No tutorials exist for this pack's nodes, but dtype conversion is pure PyTorch, so the rules are universal. Keep it simple: match the dtype of the tensor to whatever model or loss is eating it, and you're done.

CategoryETK/pytorch

Inputs (2)

NameTypeDefaultDescription
input_dataTORCH_TENSOR
dtypeSTRINGtorch.float32

Outputs (1)

NameTypeDescription
TORCH_TENSORTORCH_TENSOR