liveBook · Manning

Stride

As explained in Build a Large Language Model (From Scratch)

The step size by which the sliding window advances between sampled training examples.

Stride is the number of token positions a sliding window advances when creating successive training examples. Smaller strides create overlapping contexts; setting stride equal to the context size prevents overlap. section 2.6

Worked sampling example

With max_length=4 and stride=1, the first input contains four token IDs and the next input begins one position later. With stride=4, successive four-token inputs do not overlap, allowing the dataset to use the text without skipping words.

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Defines stride and implements it in the dataset loop, including overlap behavior and context-size interactions.
Examples
Demonstrates stride values of 1, 2, and 4 with context sizes of 2, 4, and 8.
What it assumes
Requires understanding token IDs, context size, and one-position input-target shifting.
What you can do after
Apply it via GPTDatasetV1 and DataLoader to control overlap among sampled training contexts.
How it connects
Links sliding-window sampling with context size, input tokens, target tokens, batch size, and DataLoader.

Also explained in

Compare how 8 books explain stride →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.