ComfyUI Node

ListToTensor

Turn plain Python lists into real PyTorch tensors

By TashaSkyUp·Created about a year ago·Updated about a year ago· 1
ListToTensor
  • list
  • TORCH_TENSOR
dtype

Somewhere in a real workflow you always end up with plain Python numbers - a hand-typed label list, a set of weights, a range of values - and the pack's training and tensor nodes all want a TORCH_TENSOR. ListToTensor is the conversion node for that gap: feed it a LIST and it builds a proper tensor with torch.tensor(...), letting you pick the dtype from a dropdown. In a pack that otherwise speaks only tensors, this is the on-ramp for data you typed yourself.

The typical use: you want to feed TrainModel a small custom dataset of features and labels. Type (or compute) the lists, run them through ListToTensor, and you have tensors you can hand to the training node. It's also handy for turning the LIST output of the pack's TensorToList back into a tensor after an edit - a round-trip that sounds silly until you need to tweak a number by hand.

How it works

It calls torch.tensor(list, dtype=...). The dtype dropdown is generated from every dtype your installed torch exposes - torch.float32, torch.int64, torch.bool, and so on - and defaults to float32. Give it a nested list and you get a multi-dimensional tensor; give it a flat list and you get a 1D one.

Inputs and output

  • list (LIST) - the Python list (or list-of-lists) to convert.
  • dtype - optional dropdown of torch dtypes; default torch.float32.

Output: one TORCH_TENSOR.

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 ComfyUI stack plus scipy, scikit-learn, transformers, einops.

Common issues

  • Ragged nested lists fail. torch.tensor needs rectangular data. A list of lists where the inner lists have different lengths throws a "sizes of tensors must match" error. Pad them or keep them even.
  • Integer data becomes float by default. If you convert [1, 2, 3] with the default float32, you get floats - usually harmless for training, but if you need integer labels for a classification loss, pick torch.int64 in the dropdown. Mismatched label dtypes are a classic silent failure.
  • Where does the LIST come from? The pack's own list-producing node is TensorToList (which goes tensor → list). There's no general-purpose list-input node in this pack, so you'll typically build lists with another pack or from a tensor round-trip.

Small, quiet pack, no tutorials - but this one is a single torch.tensor call, so the PyTorch docs apply verbatim. One pack-wide quirk to keep in mind: it patches ComfyUI's validator to ignore return_type_mismatch errors, so a wrongly-typed connection may not flag itself - double-check dtypes manually.

CategoryETK/pytorch

Inputs (2)

NameTypeDefaultDescription
listLIST
dtypeoptCOMBO55 options: torch.uint8, torch.int8, torch.int16, torch.int16, torch.int32, torch.int32, +49

Outputs (1)

NameTypeDescription
TORCH_TENSORTORCH_TENSOR