Concepts / Preparing Instruction Data for Batching

Preparing Instruction Data for Batching

The Alpaca dataset is an openly shared instruction dataset of 52,002 entries, roughly fifty times larger than the earlier instruction file, with generally longer entries.

  • Programming

When the Training Data Gets Much Bigger

Up to this point, instruction fine-tuning has relied on a small file of instruction examples. This article asks what changes when the same workflow is pointed at a far larger body of instruction data. Before reading on, think about what could go wrong when a training run becomes much bigger. Consider three questions: how long will it take, how much memory will it need, and how will you know whether the result is any good? The rest of this article answers those questions in order.

What do you think happens?

Before reading on: if a larger training run fails with out-of-memory errors, which setting would you change first, and why?

Reveal answer
Answer:

The batch_size setting, lowered from 8 to 4, is the first adjustment the source suggests.

batch_size controls how many examples are processed together, so reducing it lowers how much work the hardware must hold at one time. The sequence-length setting, allowed_max_length, is lowered only after batch_size has been reduced.

The Alpaca Dataset at a Glance

The Alpaca dataset is an openly shared instruction dataset of 52,002 entries. It is roughly fifty times larger than the earlier instruction file, and its entries are generally longer. It is openly available online, and the source presents it as an option you can substitute for the smaller instruction file used earlier in the chapter. The workflow you already know stays the same while the data changes.

PropertyEarlier instruction fileAlpaca dataset
Number of entriesSmall (about one fiftieth of Alpaca)52,002
Typical entry lengthShorterGenerally longer
Hardware recommendationNot the focus of the sourceGPU strongly recommended
WorkflowThree-stage instruction fine-tuningSame three-stage workflow

How the Alpaca dataset differs from the earlier instruction file, as described in the source

Three Stages of the Workflow

Instruction fine-tuning on the Alpaca dataset follows the same overall plan as the smaller exercise, organized into three stages. The first stage prepares the data. The second stage loads a pretrained model and trains it on the instruction examples. The third stage tests what the trained model learned. Each stage depends on the output of the one before it, so the order matters.

Prepare datainstruction datasetFine-tune modelpretrained model plustraining portionEvaluate on test settrained model plus held-outtest setprepared datatrained model
What does each stage take in and produce, and in what order do the stages hand off to one another?

Notice what each stage produces. The first two stages end with a trained model. The third stage does not train anything. It takes the trained model, asks it for answers to inputs it has not seen during training, and examines those answers.

Evaluation on a Held-Out Test Set

The model in the first two stages is trained on the training portion of the instruction dataset. The evaluation stage uses a different portion, the held-out test set, which the training process did not use. Keeping the two portions separate is what makes the evaluation informative. A model judged only on examples it has already learned from tells you very little about whether it can handle new instructions.

Evaluation has two parts. First, the model-generated response is extracted for each input in the test dataset, and the responses are collected so they can be analyzed by hand. Second, the model is evaluated to quantify the quality of those responses. The source describes this second step as comparing the model's responses with the correct responses in the test set. Together these steps move from raw output to a measured judgment.

Test inputsheld-out test setTrained modeloutput of stages one andtwoExtracted responsescollected for hand analysisScored resultsquality measured bycomparisonCorrect responsesreference answers in testsetinputs givenresponses generatedcomparedreference
How do test-set inputs flow through the model, and how are the collected responses compared with the correct responses?

Adjusting Settings for a Large Dataset

A dataset with 52,002 entries takes much more work to process than a small file. The source gives two practical recommendations. The first concerns hardware: because the dataset is large and the entries are longer on average, training is best done on a GPU, which accelerates the fine-tuning process.

The second recommendation concerns what to adjust when memory runs out. Two settings control how much work the hardware must hold at one time. The batch_size setting controls how many examples are processed together. The allowed_max_length setting caps how long each input may be. If training fails with out-of-memory errors, the source suggests lowering batch_size from 8 to 4, then to 2, or even to 1. It also suggests lowering allowed_max_length from 1,024 to 512, or to 256, to help manage memory.

batch_size 8starting settingbatch_size 4first reductionbatch_size 2second reductionbatch_size 1smallest batchallowed_max_length1,024starting length capallowed_max_length512first length reductionallowed_max_length256lowest length cap suggestedout of memorystill out of memoryor eventhen lengthlower lengthto help manage memory
Which setting is lowered first, and how far does each step go as memory problems persist?
Worked example

Responding to an out-of-memory error

A training run on the Alpaca dataset fails with out-of-memory errors using batch_size 8 and allowed_max_length 1,024. Using the source's suggested order, what adjustments do you try?

  1. 1
    Lower batch_size first

    The source suggests reducing batch_size from 8 to 4 before touching the length cap.

  2. 2
    Retry the run

    If the error persists, the source suggests further reducing batch_size to 2, or even to 1.

  3. 3
    Lower the length cap if needed

    If memory problems still remain, the source suggests lowering allowed_max_length from 1,024 to 512, or to 256.

Result

The adjustments are made one at a time in the suggested order, starting with batch_size. Each step limits how much work the hardware must hold, at the cost of processing fewer examples together or capping input length.

Mistakes When Scaling Up

  • Common mistake

    Judging the model on the examples it trained on

    What it looks like

    Reporting results using the same portion of the dataset that was used for training.

    Why it fails

    A model judged only on examples it has already learned from tells you very little about whether it can handle new instructions.

    Do this instead

    Evaluate on the held-out test set, which the training process did not use.

  • Common mistake

    Reaching for the sequence-length cap before the batch size

    What it looks like

    Lowering allowed_max_length from 1,024 to 256 as the first response to an out-of-memory error.

    Why it fails

    The source suggests lowering batch_size first, then allowed_max_length.

    Do this instead

    Reduce batch_size from 8 to 4 and retry, then continue down the suggested order if needed.

  • Common mistake

    Training a large dataset on hardware without considering a GPU

    Why it fails

    Because the dataset is large and the entries are longer on average, the source says training is best done on a GPU.

    Do this instead

    Plan for GPU hardware before starting a run of this size.

  • Common mistake

    Treating the evaluation stage as more training, when it does not train anything

Practice Predicting Evaluation Outcomes

MEDIUM

A colleague evaluates their fine-tuned model by feeding it inputs from the training portion and comparing the responses with the correct answers. The scores look excellent. Explain why this result says little about whether the model can handle new instructions, and describe the change that would make the evaluation informative.

Hints
  • Recall which portion of the dataset the training process used.
  • Think about what the held-out test set is for.
  • The evaluation stage collects the model's responses and compares them with correct responses in the test set.

Recap of the Workflow Stages

Scaling instruction fine-tuning to the Alpaca dataset keeps the same three-stage workflow and changes the practical concerns: time, memory, and how results are judged. Each stage hands its output to the next, and the evaluation stage tests the trained model on inputs held out from training.

Key Takeaways

  • The Alpaca dataset is an openly shared instruction dataset of 52,002 entries, roughly fifty times larger than the earlier instruction file, with generally longer entries.
  • Instruction fine-tuning has three stages: preparing the data, fine-tuning the model on a pretrained model, and evaluating on a held-out test set.
  • For a large dataset, a GPU is strongly recommended. Out-of-memory errors can be eased by lowering batch_size first (8 to 4, then 2, or 1) and then allowed_max_length (1,024 to 512, or 256).
  • Evaluation extracts the model's responses for each test input, collects them for analysis, and compares them with the correct responses so they can be scored.

Related concepts

More concepts starting with P