Stacked RNNs › Computational Cost Scaling
Language AI HandbookAll chapters Stacked RNNs › Computational Cost ScalingOne section · Sections in this chapter11 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Stacking layers has a direct and significant impact on computational cost. Understanding these costs helps you make informed decisions about architecture design.
Time Complexity
For a single LSTM layer processing a sequence of length with hidden size , the computation at each timestep involves matrix multiplications of size (the recurrent matrix ) and (the input matrix ). The total time for one forward pass is:
For a stacked model with layers and the same hidden size (and noting that after the first layer the "input" is also size ):
Time scales linearly with the number of layers. A 4-layer model takes approximately 4 times as long per batch as a 1-layer model with the same hidden size.
Memory Complexity
During training, you must store intermediate activations for backpropagation. For a single-layer LSTM:
- Hidden states: per sample
- Cell states: per sample
- Gate activations: per sample (4 gates)
Total memory per sample:
For an -layer stack, memory scales as : you must store the full state history for every layer to compute gradients.
For a 4-layer LSTM processing sequences of length 100 with hidden size 512:
- Memory for activations: K floats per sample
- At batch size 32: roughly 100 MB just for LSTM activations (in float32)
This is why long sequences with deep stacks require careful batch size management.
Parameter Count
Parameter count for a stacked LSTM with layers, input size , and hidden size :
Simplified: the first layer has parameters and each subsequent layer has parameters. Total parameters scale as for .


The linear scaling in both time and memory confirms that adding layers has predictable costs. For a given computational budget, this creates a hard cap on useful depth: a 5-layer model that takes 5x the training time and fills all available GPU memory might not be the right choice even if, in theory, it could learn better representations.