Fine-Tuning, and When Not ToLesson 35 of 84

Module 4 · Building the dataset

Packing, document boundaries and long context

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 8 of 11 in this chapter

This chapter’s goalAssemble a training set from named sources with checked licences, convert it to one chat format, filter and deduplicate it, mix in replay data at a stated ratio, and publish a data card that lets a stranger reproduce the set.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

The padding problem

If your examples average 300 tokens and your training window is 2,048, then padding every sequence to the window means roughly 85% of the tensor is padding. You pay for those matrix multiplications in full.

Two fixes, with different risk profiles.

Length-grouped batching (group_by_length=True) sorts similar-length examples together so each batch pads to its own longest member rather than to a global maximum. Safe, simple, and it recovers most of the waste.

Packing concatenates examples end to end until the window is full. Zero padding, maximum throughput, and one hazard that is invisible unless you look for it.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Running Models Yourself exam.

Stuck on something?Ask Rafael, your AI tutor

How to cite: Addaly (2026) ‘Packing, document boundaries and long context’, in Fine-Tuning, and When Not To. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/fine-tuning/packing-and-long-context (Accessed: 29 November 2026).