Concepts / Learning Rate Warmup for Stable LLM Training

Learning Rate Warmup for Stable LLM Training

The total number of training steps is the number of batches in the training loader multiplied by the number of epochs, and every warmup value is derived from that total.

  • Programming

A Printed Number With a Purpose

This lesson begins with a small program that prints one number. The program first computes how many training steps a run will take, then computes how many of those steps should be used for warmup, and finally prints the warmup count. Warmup is the first phase of training, in which the learning rate is increased from a small starting value. So the program is answering a practical question: how many of the earliest training steps should be spent on that increase?

Keep that question in mind as you read. The printed value only makes sense once you know what it counts. It counts steps, not a percentage, even though the percentage is what the program uses to decide the count.

Counting the Total Training Steps

Every warmup calculation starts from the total number of training steps. In this program that total is the number of batches in the training loader multiplied by the number of epochs. An epoch is one full pass over the training data, and the loader splits that data into batches. If the loader yields a fixed number of batches per pass, then running several passes multiplies that count. The product is the total number of steps the run will take.

Epoch 1B batchesTotal stepsB times EEpoch 2B batchesEpoch EB batchessame batches againsame batches againall passes summed
How does the number of batches per epoch combine with the number of epochs to give the total step count, and how does one epoch's batches repeat?

Written as a relationship, the total is the batch count times the epoch count, where B stands for batches per epoch and E for the number of epochs. The first line of the program is the foundation for everything after it. If the total is wrong, every value derived from it will be wrong too.

Formula
python
Output (expected)
135
Notes on the code
  • batches_per_epoch is the number of batches the loader yields in one pass
  • total_steps multiplies that count by the number of passes

Turning a Percentage Into a Step Count

The source states that warmup steps are usually set between 0.1% and 20% of the total number of steps. The program uses the upper end of that range, 20%, and writes it as the decimal 0.2. Multiplying the total by 0.2 gives a fraction of the total. Steps are countable, so the fractional part is discarded by int(), which converts the result into a whole number of steps.

Formula
python
Output (expected)
27
Notes on the code
  • 0.2 * 135 gives 27.0, a float
  • int() discards the .0 and returns the whole number 27

The count is not an end in itself. The source explains that the warmup steps are used to increase the initial learning rate. In the example it describes, the learning rate rises from 0.0001 to 0.01 across the first 27 training steps. The warmup count therefore sets how long that climb takes. A larger count spreads the increase over more steps, and a smaller count compresses it into fewer steps.

When a Small Share Rounds Down to Zero

The lower end of the range can produce a surprise. Take a total of 500 steps and a warmup share of 0.1 percent. The direct calculation is 0.001 times 500, which equals 0.5. The integer conversion then discards the fraction and produces 0. A learner who expects at least one warmup step from a small percentage will be surprised, but the cause is the truncation, not an error in the multiplication.

Tracing the Calculation Line by Line

When a printed warmup count looks wrong, do not start by questioning the percentage. Walk the calculation in order and check each intermediate value. The trace has three stages: the number of batches, the total after multiplying by epochs, and the warmup count after applying 0.2 and truncating. The first stage that disagrees with your expected value is the location of the problem.

Batches per epoch45Total steps45 times 3 equals 135Scaled share0.2 times 135 equals 27.0Warmup countint gives 27times epochstimes 0.2truncate
At which line of the calculation does the value first deviate from what is expected, and how does that error carry into later lines?
Worked example

Working backward from a printed 27

The program prints 27. What total step count T is consistent with that output?

  1. 1
    Set up the bounds

    int(0.2 times T) equals 27 means 27 is less than or equal to 0.2T, and 0.2T is less than 28.

  2. 2
    Write the inequality

    $27 \leq 0.2T < 28$

  3. 3
    Multiply by 5

    $135 \leq T < 140$, since 0.2 times 5 is 1.

  4. 4
    Check a candidate

    For T equal to 135, 0.2 times 135 is 27.0, and int gives 27. So 135 is consistent.

Result

A total of 135 is one consistent value. Any total from 135 up to 139 also gives 27. The source does not state the loader and epoch settings, so this trace establishes what the total must be, not the specific loader used.

The trace also shows where to look first. The printed 27 corresponds to a total near 135, so a mismatch usually traces back to the total rather than to the final line. This is why the most useful debugging habit with this program is to check the total before looking at the percentage logic.

Percentage Versus Step Count

A percentage describes a share of the run. A warmup count describes a number of steps. For a total of 135 steps, 20% is a share of the run, while the warmup count it produces is 27 steps. The 20 in the lesson describes the share; the 27 is the count the program prints. Mixing the two up leads to misreadings of the output.

QuantityWhat it measuresValue for a 135-step run
Warmup percentageShare of the total run20%
Scaled share0.2 times the total, before truncation27.0
Warmup countWhole training steps used for warmup27

The percentage, the scaled share, and the warmup count are three different things derived from the same total.

Mistakes When Reading the Warmup Count

  • Common mistake

    Reading the printed count as a percentage

    What it looks like

    Seeing 27 and concluding that warmup is 27% of training.

    Why it fails

    The printed value is a count of steps. The source says the 20 describes the share and the program prints 27.

    Do this instead

    Read the output as a number of steps, then compare it with the total.

  • Common mistake

    Questioning the percentage first when the count looks wrong

    What it looks like

    Changing 0.2 to another value before checking the total.

    Why it fails

    Every warmup value is derived from the total, so an error in the total propagates into the count.

    Do this instead

    Check the batch count, then the total after multiplying by epochs, then the warmup count.

  • Common mistake

    Expecting a small percentage to always give at least one step

    What it looks like

    A total of 500 with 0.1 percent gives 0.5, which truncates to 0.

    Why it fails

    int() discards the fractional part, so small shares can round down to zero.

    Do this instead

    Check any small count against the expected range, and treat zero as a value to verify.

  • Common mistake

    Forgetting that epochs multiply the batch count rather than adding to it

Predict Then Check the Warmup Count

What do you think happens?

If the total number of training steps is 135, what does the program print for the warmup count?

  • 15

  • 27

  • 135

  • 0.2

Reveal answer
Answer:

27

0.2 times 135 is 27.0, and int() keeps the whole number 27. The 0.2 is the share, not the count, and 135 is the total, not the warmup length.

EASY

A loader yields 60 batches per epoch and the run uses 4 epochs. Compute the total number of steps, then compute the warmup count using 20%. Before computing, decide which line you would check first if your answer disagreed with a classmate's.

Hints
  • Multiply batches per epoch by the number of epochs first
  • Multiply the total by 0.2 and then apply int() to the product

Key Takeaways

  • The total number of training steps is the number of batches in the training loader multiplied by the number of epochs, and every warmup value is derived from that total.
  • Warmup steps are usually set between 0.1% and 20% of the total; the program uses 0.2 and applies int() to truncate the product to a whole number of steps.
  • Because int() truncates, small shares can round down to zero, which is a valid output that still needs checking against the expected range.
  • When a warmup count looks wrong, trace the calculation in order (batches, total, warmup count) and find the first stage that disagrees with your expected value.
  • A percentage describes a share of the run, while the warmup count is the number of steps that share produces; they are not the same quantity.

Related concepts

More concepts starting with L