DocsAI Training Coach⚙️ Hyperparameters

Learning Rate (In Depth)

Fully understanding the most important hyperparameter

The learning rate (LR) determines the step size in gradient descent. It's the most influential hyperparameter: no other parameter can affect training as strongly, positively or negatively.

Impact on the training run

⚡ Chaos

LR too large (e.g. 1e-2)

Loss oscillates extremely

No convergence

Possible gradient explosion (NaN)

✓ Optimal

LR ideal (e.g. 2e-5)

Loss drops steadily

Stable convergence

Reaches a low minimum

🐌 Too slow

LR too small (e.g. 1e-8)

Barely any progress per epoch

Very slow training

Practically no learning

LR recommendations by model type and task

BERT / RoBERTa fine-tuning (classification)
2e-5 to 5e-5
DeBERTa / ELECTRA fine-tuning
1e-5 to 3e-5
GPT-2 fine-tuning (generation)
5e-5 to 1e-4
LLaMA / Mistral LoRA (rank=8–16)
1e-4 to 3e-4
LLaMA / Mistral LoRA (rank=32–64)
5e-5 to 1e-4
QLoRA (4-bit) fine-tuning
2e-4 to 3e-4
Full fine-tuning (7B, fp16)
1e-5 to 5e-5
Training from scratch (small model)
1e-3 to 3e-3

The LR range test – finding it systematically

LR range test (implementation):

  1. Initialize the model fresh
  2. Train for 1 epoch with LR schedule: 1e-8 → 1e-1
     (exponentially increasing over all steps)
  3. Plot loss vs. LR (log scale)
  4. Identify:
     - Point where loss drops most steeply → LR_steep
     - Point where loss starts to rise → LR_max
  5. Good LR = LR_steep / 10 to LR_steep

Example result:
  LR_steep  = 5e-4
  LR_max    = 2e-3
  → Good LR = 5e-5 (safely below steep)
             or 1e-4 (more aggressive)

Linear scaling rule & batch-LR relationship

Linear scaling rule:
  LR_new = LR_base × (batch_size_new / batch_size_base)

Example:
  Base: BS=8, LR=2e-5
  New:  BS=32 → LR = 2e-5 × (32/8) = 8e-5

For batch size < 512:  linear scaling works well
For batch size > 512:  square root scaling is better:
  LR_new = LR_base × sqrt(BS_new / BS_base)

Note: often optional for small changes (8→16).

Practical approach for FrameTrain

Always start with the default value of the chosen model. If loss barely drops after 1–2 epochs: LR × 3. If loss oscillates: LR ÷ 5. Always set warmup to 5–10% of the steps.