AI Hints
Home›Fine-Tuning LLMs Tutorial›Mistakes, Troubleshooting and Interview Basics
Fine-Tuning LLMs · Lesson 113 of 120

Troubleshooting

When training goes wrong.

⏱ 2 min read▶ Video at 2:51:02🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

Sooner or later, something will go wrong. The loss won't fall, or memory runs out, or the output is nonsense. Here's a quick guide to the most common problems.

  • Something will go wrong
  • Loss, memory, nonsense
  • A quick guide

The loss looks wrong

If the loss doesn't fall at all, the learning rate is probably too low, or the adapter isn't attached. If the loss is NAN, or explodes, the learning rate is too high. And if the training loss falls, but the eval loss rises, the model is overfitting.

SymptomLikely cause
loss flatlr too low, no adapter
loss NaN or explodeslr too high
train ↓ but eval ↑overfitting
loss ~0 very fastdata too easy or leaked

Memory and speed

Out of memory errors are very common. Lower the batch size, and use gradient accumulation to keep the same effective batch. Turn on gradient checkpointing. Use QLoRA, with a four bit model. Or shorten max length. And if training is very slow, check you're really using the GPU.

ProblemTry
out of memorysmaller batch + accumulation
still out of memorygradient checkpointing
big modelQLoRA, 4-bit
very slowcheck the GPU is used

Bad output

If the output is wrong after training, check these. Repeating text often means a missing end of sequence token. A wrong format usually means a different chat template, or system message. Strange output right after training, means you forgot model dot eval. And the base model's answers mean the adapter isn't loaded.

OutputCheck
repeats foreverend-of-sequence token
wrong formattemplate, system message
odd after trainingmodel.eval()
like the base modelis the adapter loaded?

Summary

Let's recap. A flat loss usually means a low learning rate. Out of memory means smaller batches, checkpointing, or QLoRA. And bad output usually means a template, or setup problem. Next, interview questions.

Key takeaways
  • Loss problems
  • Memory problems
  • Output problems
Next up: Interview: Core — the questions you will hear