RNN (high-level)
One line of history, no hand-written math
- model
A recurrent neural network is the classic way to make a model that carries memory: instead of seeing one token and forgetting it, the network keeps a hidden state that rolls forward through the sequence, so what it predicts at token 10 depends on tokens 1 through 9. ComfyDL's CdlRNN gives you that as a single clean node - the "high-level" version that wraps PyTorch's battle-tested nn.RNN rather than making you assemble the weights yourself.
It sits in ComfyDL, the pack that turns the Dive into Deep Learning (d2l) textbook into a node graph. The "(high-level)" in its name is a hint that there's a from-scratch sibling (in the RNN Scratch node) that shows the raw math with manually-initialized W_xh, W_hh weights. This node is the one you'd actually use for an experiment: you get real, properly-initialized recurrent machinery and can lean on the library's implementation.
How it works
Under the hood it constructs nn.RNN(num_inputs, num_hiddens) - a single-layer, tanh-activated vanilla RNN. Feed it an input tensor of shape (num_steps, batch_size, num_inputs) and it returns two things: the full sequence of hidden states (one per time step) and the final hidden state. The hidden state is the memory: at each step the network blends the current input with its own previous state, and that state is what carries context across the sequence.
That time-major input shape is the one quirk to internalize. Text data usually arrives as (batch, num_steps) token indices; to feed an RNN you transpose to (num_steps, batch, ...) so each time slice is a batch. ComfyDL's tokenizer and vocabulary nodes exist to get you from raw text to those indices.
Inputs and outputs that matter
num_inputs(default 32) - the size of each input vector. In a language model this is your vocabulary size, because each token becomes a one-hot vector of that width.num_hiddens(default 64) - how many hidden units the memory state gets. Bigger = more capacity, slower to train.
The model output is a cdlModel whose forward returns (outputs, hidden_state). The natural next stop is a language model node: feed this model into CdlRNNLM (high-level) or CdlRNNLMScratch to wrap it with an output layer that predicts the next token, then into ComfyDL's RNN LM Predict node to generate text. For pure inspection, run it through a CdlModelForward node.
Installing ComfyDL
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL ./ComfyDL
pip install -r ./ComfyDL/requirements.txt
Restart ComfyUI afterwards. The dependencies are light (matplotlib, IPython, matplotlib-inline) - no model files to fetch for this node. ComfyUI Manager may not list this young educational pack yet; the clone command is the reliable route.
Gotchas
The hidden-state shape trips people up the most. nn.RNN returns the final state as a 2D tensor (batch, num_hiddens) for a single layer, but if you stack layers later via the GRU node the state becomes 3D (num_layers, batch, num_hiddens). And remember this is the vanilla RNN - the one that struggles with long sequences due to vanishing gradients. If your text experiment feels dumb past a few tokens, that's the architecture talking, not your wiring; that's exactly when you graduate to CdlGRU or LSTM.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| num_inputs | INT | 321–100000 | — |
| num_hiddens | INT | 641–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| model | cdlModel | — |