TensorsToDataset
Two tensors walk into a node and come out a labeled dataset
- input_data
- labels
- TORCH_DATASET
TrainModel accepts data two ways: a ready-made TORCH_DATASET, or separate features and labels tensors that it bundles itself. TensorsToDataset is the node that does that bundling for you - take a features tensor and a labels tensor, pair them up row by row, and get a proper torch.utils.data.TensorDataset out the other side. If your data pipeline produces tensors (which this whole pack does), this is the bridge into training.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the raw-PyTorch-in-ComfyUI pack. It's the natural partner to PyTorchDatasetDownloader in "tensors" mode: that node hands you features and labels, this one turns them into a dataset, and TrainModel eats it.
How it works
The node builds torch.utils.data.TensorDataset(input_data, labels), which pairs the two tensors by index - row i of features gets row i of labels. Two behaviors in the source are worth knowing.
First, it turns on gradient tracking: if the tensors are leaf tensors, it sets requires_grad = True on them (skipping labels that are integer dtype, since gradients only exist for floats). The point is to let gradients flow back into your input data if you ever want that - but for normal supervised training it's mostly invisible. Just know your "dataset" now contains grad-tracking tensors, which is a little unusual versus standard ML.
Second, the "move to device" dropdown (default cpu) moves both tensors to the chosen device inside the dataset. Pick cuda and the whole dataset lives on the GPU, which can speed up training - or blow up your VRAM if the dataset is large. Most beginners should leave it on cpu and let TrainModel's device setting handle placement.
The classic usage: download MNIST in "tensors" mode, SliceTensor a chunk for speed, TensorsToDataset to bundle, then straight into TrainModel.
Inputs and outputs
- input_data (required
TORCH_TENSOR) - the features. - labels (required
TORCH_TENSOR) - matching labels. - move to device (optional enum) -
cuda/cpu, defaultcpu. - Output: TORCH_DATASET - wire into
TrainModel(orPyTorchInferenceNode).
Installing it
Shared with the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes.git
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI and it's under ETK/pytorch - or ComfyUI Manager, searching "EternalKernel PyTorch Nodes".
Troubleshooting
The one hard requirement is that the two tensors have the same length along the first dimension - mismatch them and TensorDataset throws a clean ValueError about sizes. Also, since the node sets requires_grad on leaves, don't be surprised if a subsequent "inference" pass on this dataset produces gradient warnings - that's expected, not a bug. If you pick cuda and the run dies with an out-of-memory or CUDA error, it's usually the dataset being too big for VRAM; drop back to cpu or slice smaller. And as with every node in this pack, None flowing in where a tensor belongs (say, from a downloader output you didn't fill) fails confusingly downstream because the pack's validation patch lets bad types through the ports.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_data | TORCH_TENSOR | — | |
| labels | TORCH_TENSOR | — | |
| move to deviceopt | COMBO | cpu | 2 options: cuda, cpu |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_DATASET | TORCH_DATASET | — |