SliceTensor
Take the first N rows of a tensor when you only need a chunk
- input_data
- TORCH_TENSOR
Sometimes you don't want the whole tensor - you want the first five samples, or every other row, or a quick subset to sanity-check a workflow without chewing through 60,000 MNIST images. SliceTensor does exactly that: a plain Python tensor[start:end:step] on the first dimension, exposed as three text inputs. It's the "trim the batch" node, and it's as simple as it sounds.
It's part of EternalKernel PyTorch Nodes (TashaSkyUp), the raw-PyTorch-in-ComfyUI pack. Where ReshapeTensor fixes shape problems, SliceTensor fixes size problems - trimming a big features tensor down to a bite-sized test set before you wire it into training.
How it works
The implementation is a single slice: input_data[start:end:step], applied along dimension 0 (the batch/rows axis). Start, end, and step are typed as strings and cast to ints inside the node - another of this pack's "everything is a text field" quirks.
Some practical notes on how slicing semantics work, because they're the whole game:
- start is inclusive, end is exclusive -
0to5gives you rows 0–4. - end can exceed the tensor's size; Python just stops at the end. So
0to999999is a safe way to say "everything." - step of
1is contiguous;2takes every other row; a negative step reverses (though this node doesn't let you go backwards-and-empty easily, so don't overthink it). - Slicing is a view in PyTorch, not a copy, so it's cheap and memory-friendly.
For a 2D features tensor (N, features), you get back (count, features). For an image stack (N, C, H, W), you get (count, C, H, W). Same dtype, same values, fewer rows.
Inputs and outputs
- input_data (required
TORCH_TENSOR) - the tensor to slice. - start (required STRING) - first index, default
0. - end (required STRING) - exclusive stop, default
5. - step (required STRING) - stride, default
1. - Output: TORCH_TENSOR - the sliced subset.
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 realistic failure modes are few. A non-integer string (a stray space, a letter) throws a plain int() ValueError - the fields aren't validated at the port, so the error hits mid-run. Passing a negative step with a start of 0 gives you an empty tensor rather than an error, which reads as "why is my training doing nothing?" rather than a crash. And remember this slices only the first dimension; if you're trying to cut features off a single sample or slice across channels, this node can't do it - that's a job for ReshapeTensor plus a slice, or a Python-adjacent approach. Also, because this pack loosens ComfyUI's return-type validation globally, a None flowing in here will fail downstream with a mystery error - check the wire feeding input_data.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input_data | TORCH_TENSOR | — | |
| start | STRING | 0 | — |
| end | STRING | 5 | — |
| step | STRING | 1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_TENSOR | TORCH_TENSOR | — |