Nodes/ComfyUI-Pt-Wrapper/Ptv Sequential Tensor Dataset
ComfyUI Node

Ptv Sequential Tensor Dataset

Sliding windows for sequence models

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptv Sequential Tensor Dataset
  • tens
  • PTVDATASET
seq_len32

Sequence models don't learn from raw sequences - they learn from pairs: here's the last N values, predict the next one. If you're using the pack's RNN, GRU, or LSTM nodes on time-series or token data, this is the node that builds those training pairs for you. Feed it a tensor and a window length; it carves the data into overlapping (input, target) windows and hands back a PTVDATASET ready for the loader and trainer.

How it works

The sliding-window logic is plain and worth understanding, because it defines your dataset size. Given a tensor of length N and a window seq_len:

  • input x = elements [i : i+seq_len]
  • target y = elements [i+1 : i+seq_len+1] - the same window shifted forward by one step.

So each window predicts the next step in the sequence - the classic "next-token / next-value prediction" framing. The dataset's length is N - seq_len - 1, which matters more than you'd think: a 10,000-sample series with seq_len=32 gives you roughly 9,967 training windows, not 10,000. A 1-D input tensor is automatically expanded to shape [N, 1] so the windowing still works.

The inputs that matter

Just two:

  • tens - the TENSOR holding your sequence data. The code expects a shape of [N, ...], where N is the length of the sequence and the trailing dims are the feature dimensions at each step.
  • seq_len - window length, default 32. How much history each prediction gets to look at. Too small and the model can't see the pattern; too big and you shrink your dataset and train slowly.

Output is a PTVDATASET whose samples are (x, y) pairs, each shaped [seq_len, ...]. It feeds the Pt Data Loader like any other dataset node.

Where you'd actually use it

The pack's RNN/LSTM/GRU text-classification tutorials are the main consumer - the sequence windows feed the recurrent model, and the shifted target teaches it to predict the next step. It also works for any numeric time series you can get into a tensor: temperature readings, sensor logs, token-ID streams. If you're doing classification rather than next-step prediction, check the pack's Hf Dataset With Token Encode path instead - that one gives you (text, label) pairs for labeled data.

Install

One install for the whole pack:

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

Restart ComfyUI, or search "ComfyUI-Pt-Wrapper" in ComfyUI Manager. No extra dependencies.

Common issues

  • "Expected sequence length" / weird sizes - you set seq_len larger than the tensor's length. The math N - seq_len - 1 goes zero or negative and the dataset comes back empty or nonsensical. Keep seq_len comfortably smaller than N.
  • Windows don't line up with your model - the targets are shifted by one step by design; if your model expects unshifted targets, this node isn't the one you want.
  • 1-D confusion - the code auto-unsqueezes 1-D input to [N, 1], which is usually what you want, but remember the output windows then carry that trailing 1 dimension.

It's a quiet utility node, but it's the piece that makes sequence training possible in the graph at all. Pair it with a Pt Arange or Pt From Numpy tensor and you can prototype a next-value predictor entirely in nodes.

CategoryTraining

Inputs (2)

NameTypeDefaultDescription
tensTENSOR
seq_lenINT321–100000

Outputs (1)

NameTypeDescription
PTVDATASETPTVDATASET