Quant Memo
Core

Truncated BPTT and Window Length

Instead of backpropagating gradients through an entire long sequence, truncated BPTT only unrolls and grades the last k steps at a time, trading how far back credit can flow for tractable memory and compute.

Prerequisites: Backpropagation Through Time, Recurrent Neural Networks

Backpropagation through time unrolls a recurrent network across every timestep of a sequence and backpropagates the full chain of gradients from the last step all the way to the first. For a sequence of a few hundred or a few thousand steps — a year of daily bars, a day of minute bars — that means storing and differentiating through the entire unrolled chain at once, which is both memory-expensive and prone to vanishing or exploding gradients over such a long path.

The analogy: grading only the recent pages

Being graded on every single page of a year-long diary at once, all in one sitting, is impractical. Truncated BPTT instead only unrolls and grades the last kk pages at a time: the hidden state still carries forward continuously from page to page, but the gradient — the "grading" signal — only ever looks back kk pages before it stops.

The mechanics

Full BPTT differentiates the loss at time TT with respect to every parameter through the entire chain back to t=1t=1. Truncated BPTT (TBPTT) instead splits the sequence into chunks of length kk: within a chunk, it runs the forward pass and a full backward pass just for those kk steps, then carries the hidden state — but not its gradient history — forward into the next chunk as a fixed starting point.

ht=tanh(Wht1+Uxt)h_t = \tanh(W h_{t-1} + U x_t)

In a simplified linear recurrence, htγht1h_t \approx \gamma\, h_{t-1} for some effective decay factor γ\gamma, the contribution of an input from kk steps back to today's gradient scales roughly like γk\gamma^k — restating: the further back a timestep is from the current truncation window, the more its gradient contribution has already decayed, so the window length kk directly controls how far back the network can be taught to look.

Worked example 1: chunk boundaries

A sequence of length T=20T=20 with window k=5k=5 splits into 4 chunks: steps 1–5, 6–10, 11–15, 16–20. Gradients computed during the chunk covering steps 11–15 never flow back past step 11 — no matter how relevant step 3 might have been, no credit or blame reaches it during that chunk's backward pass.

Worked example 2: how much of the past still gets credited

Take a toy recurrence ht=0.9ht1+xth_t = 0.9\,h_{t-1} + x_t, where 0.90.9 is the effective decay per step. The gradient contribution from an input kk steps back scales like 0.9k0.9^k. With k=3k=3: 0.93=0.7290.9^3 = 0.729 — nearly three-quarters of the signal from 3 steps back still reaches today. With k=10k=10: 0.910=0.3490.9^{10} = 0.349 — only about a third survives from 10 steps back. Choosing window length kk this small effectively caps how far back the network is trained to notice anything, regardless of the sequence's true length.

gradient wall chunk 1 (gradients flow within) chunk 2 (gradients flow within)
The hidden state (horizontal arrows) passes continuously across the chunk boundary, but gradients (the "wall") stop there — credit assignment only ever reaches back k steps within the current chunk.

The gradient contribution from k steps back decays exponentially with the decay factor raised to the k-th power — exactly the shape below:

Function explorer
-2260.1
x = 1.00f(x) = 2.718

Truncated BPTT unrolls and backpropagates only k steps at a time to keep training tractable, letting the hidden state carry information forward indefinitely while gradients only ever teach the network to use roughly the last k steps of context.

What this means in practice

Window length kk is chosen based on how far back dependence plausibly matters for the task — a few days for a fast mean-reverting signal, weeks for a slower trend — balanced against GPU memory and training speed, since a longer kk means a longer chain to store and differentiate per chunk.

Truncating the gradient is not the same as truncating memory. The hidden state itself can still, in principle, carry information across chunk boundaries indefinitely — it just never gets actively taught to rely on anything beyond roughly kk steps back, because no gradient signal ever reaches that far. A model can therefore behave as if it has a hard k-step memory limit even though nothing architecturally prevents longer-range state from persisting.

Related concepts

Practice in interviews

Further reading

  • Williams & Peng, An Efficient Gradient-Based Algorithm for On-Line Training of Recurrent Network Trajectories (1990)
ShareTwitterLinkedIn