Full Fine-tuning › Worked Example: Configuring Fine-tuning from Scratch
Language AI HandbookAll chapters Full Fine-tuning › Worked Example: Configuring Fine-tuning from ScratchOne section · Sections in this chapter5 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To build concrete intuition for how these hyperparameters interact, let's walk through a complete configuration calculation from scratch. Suppose we want to fine-tune BERT-base on a sentiment classification dataset with 8,000 training examples, using a batch size of 16 and planning to train for 3 epochs.
Step 1: Calculate total training steps. Each epoch processes all 8,000 training examples in batches of 16.
With 3 epochs, the total number of training steps is:
Step 2: Calculate warmup steps. With a warmup ratio of 0.1, we devote 10% of training to warmup:
So the learning rate increases linearly over the first 150 steps, then decays over the remaining 1,350 steps.
Step 3: Verify the warmup-to-training ratio. The warmup covers 150 out of 500 steps in the first epoch, meaning the learning rate is still ramping up for the first 30% of epoch 1. This is normal and expected. By step 150 (30% into epoch 1), the learning rate reaches its maximum. It then decays linearly over the remaining 1,350 steps.
Step 4: Calculate the learning rate at each step. Using and the linear decay formula, the learning rate at step 750 (halfway through training, midpoint of the decay phase) is:
At the midpoint of the decay phase, the learning rate has decreased to approximately , which is about 55.6% of its maximum value. This is expected from a linear schedule: at the midpoint, you should have approximately half the maximum learning rate remaining.
Step 5: Calculate effective batch size with gradient accumulation. If GPU memory allows only 8 samples per forward pass but we want an effective batch size of 32, we need gradient accumulation:
With gradient accumulation of 4, the number of optimizer steps per epoch becomes:
This means the total number of parameter updates across all 3 epochs is , rather than the 1,500 forward/backward passes. The gradient quality is equivalent to using a batch size of 32, but you need only 8 samples in GPU memory at any time.
Step 6: Verify the linear scaling rule for learning rate. Our baseline learning rate of was validated for batch size 16. If we switch to effective batch size 32, the linear scaling rule suggests:
However, since we are using gradient accumulation to simulate batch size 32 rather than true batch size 32, the effective gradient dynamics are slightly different. In practice, gradient accumulation with 4 steps of batch size 8 is mathematically equivalent to true batch size 32, so the learning rate scaling applies equally. The final configuration for this scenario would be: batch size 8, gradient accumulation 4, effective batch size 32, learning rate , warmup steps 150, total optimizer steps 375.