The training algorithm finds a model’s weights, while the developer chooses the hyperparameters before the run: how fast to change the weights, how many examples to take per step, how many times to pass over the data. They affect the quality of the result, the speed and the memory use, so they are tuned by trial runs.
What is tuned most often
| Hyperparameter | What it sets | Default in Trainer |
|---|---|---|
learning_rate | learning rate: the size of the step when the weights change; with warmup, its peak | 5e-5 |
per_device_train_batch_size | number of examples per device per step | 8 |
num_train_epochs | how many times to pass over the whole dataset | 3.0 |
warmup_steps | how many steps the learning rate takes to rise from zero to the set value | 0 |
weight_decay | strength of the penalty for large weights | 0.0 |
Fine-tuning hyperparameters
The LoRA method has its own settings: the rank r determines the size of the added matrices, lora_alpha sets the scale of their contribution, and target_modules says which layers get an adapter. The PEFT documentation examples use, for instance, r=16 and lora_alpha=16. The higher the rank, the more trainable parameters and capacity, but also the more memory needed.
How they are chosen
Usually you take values from the model card or the paper describing the method and change them one at a time, comparing the loss on a held-out part of the data. The search can be done by hand, as a grid or at random. If the loss falls on the training data but rises on the held-out data, the model is overfitting: fewer epochs, a lower learning rate or more data can help.
Sources
the term is written from these pagesVerified 18 Nov