Backpropagation Through Time › Truncated BPTT
Language AI HandbookAll chapters Backpropagation Through Time › Truncated BPTTOne section · Sections in this chapter4 / 15 ↓
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
Full BPTT requires storing all hidden states and all activations for the entire sequence before running the backward pass. For a sequence of length , this means memory for activations and computation for the backward pass. When is thousands or tens of thousands of tokens, full BPTT becomes impractical.
Truncated BPTT addresses this by dividing the sequence into fixed-length chunks and running a separate forward/backward pass through each chunk. Within each chunk, gradients flow freely. Across chunks, the hidden state is passed forward but gradients are stopped at the chunk boundary.
How Truncated BPTT Works
The sequence of length is divided into non-overlapping chunks of length (the truncation length). For chunk spanning timesteps :
- The forward pass starts with the final hidden state from the previous chunk, , carried forward without gradient tracking
- The forward pass runs through all steps in the chunk, accumulating hidden states and losses
- The backward pass propagates gradients back through the steps in the chunk only
- The weight gradients are accumulated across all chunks
The stopping of gradients at chunk boundaries is implemented using PyTorch's detach() operation, which creates a new tensor with the same values but no gradient history.
The forward-pass hidden state still carries information from earlier in the sequence. When chunk begins, the initial hidden state encodes everything the network saw in chunks 0 through . That information is used in the forward pass to make predictions and compute losses. But the backward pass cannot trace gradients through into earlier chunks, because detach() has severed the computational graph. The result is an asymmetry: the model can use long-range information to make predictions, but cannot learn from gradient signal that would require looking beyond the current chunk boundary.
Truncated BPTT makes a practical trade-off: it gives up the ability to learn dependencies that span more than timesteps in exchange for bounded memory and predictable computation per update step. In practice, for most RNN training tasks, a truncation length between 20 and 200 captures the dependencies that matter. The exact value is a hyperparameter that depends on the sequence structure, and it interacts with the model's capacity to represent longer-range information in its hidden state.
Truncated BPTT limits gradient propagation to the most recent timesteps. The hidden state carries information from earlier in the sequence via forward propagation, but the gradient signal only travels back steps. This means the model can use long-range information for predictions but cannot update weights based on gradients from beyond steps ago.
The following visualization shows how gradient coverage changes with the truncation window relative to the full sequence length. Each bar represents the fraction of the sequence covered by one backward pass:

With , the 200-step sequence requires 10 separate backward passes. With , only 2 passes are needed. The trade-off is that larger chunks require more memory to store activations during the forward pass of each chunk.
Selecting the Truncation Length
The truncation length controls the trade-off between several competing factors:
- Memory cost: full BPTT requires memory; truncated BPTT requires memory per chunk
- Computational cost: each backward pass covers steps; you run backward passes per sequence
- Gradient quality: longer chunks capture more long-range dependencies; shorter chunks lose information about distant correlations
A common choice is for language modeling, matching the LSTM training paper by Zaremba et al. (2014). For tasks with explicit long-range dependencies, larger values or gated architectures such as LSTMs help.
Choosing the truncation length is not purely a memory decision; it should reflect the structure of the data. If the sequence contains strong dependencies that span 100 tokens, a truncation window of 20 will prevent the model from ever learning them through gradient updates. In practice, you can estimate the relevant dependency range by examining what information would be needed to make accurate predictions. For next-word prediction in typical English text, dependencies rarely need to span more than a few dozen words, which explains why modest truncation windows work well for language modeling.
One underappreciated consideration is the interaction between the truncation length and the learning dynamics. Very short truncation windows produce gradients that are effectively local to a small context window. The model learns to make predictions using only nearby context, which is fast but limits what it can ultimately learn. Very long truncation windows give the model more gradient signal but also give it vanishing gradient problems of its own, since the gradient still has to propagate through matrix multiplications to reach the beginning of the chunk.
Memory Requirements
The memory comparison between full BPTT and truncated BPTT is significant. For a sequence of length with hidden size and batch size :
- Full BPTT activations: bytes (all hidden states stored)
- Truncated BPTT activations: bytes (only current chunk's states stored)
For long sequences (e.g., , ), truncated BPTT reduces memory by roughly . The computational cost per step is similar, but the memory savings allow much larger batch sizes or hidden state sizes.
Beyond hidden states, the backward pass also requires storing intermediate activations, including the pre-activation values (the inputs to the tanh function) at each step, since the tanh derivative must be computed from these values. The total activation memory scales with the depth of the backward pass, making truncation doubly beneficial: it reduces both the hidden state storage and the intermediate activation storage.