सामग्री पर जाएँ

लेसन 19 · Fine-tuning

Evaluate and Ship a Fine-tuned Llama

Compare a fine-tune with its baseline, check regressions and safety, then merge or load a LoRA adapter, convert it for local runtimes and release it safely.

A training run that finishes without errors proves nothing about quality. A fine-tuned model is ready only when it beats your baseline on an untouched test set, does not break other behavior and is served the same way it was tested.

Compare against the baseline

Run these systems on the same test set with the same generation settings:

  1. the base instruct model with your best prompt,
  2. the fine-tuned model with its intended prompt,
  3. optionally, the base model with retrieval or few-shot examples.

Report more than an average. Look at each category, especially rare ones. An overall gain can hide a collapse in one class.

Python Stand-in: per-category comparison and regressions

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The overall score goes up while return gets worse. That would be a reason to hold the release.

Be careful with small test sets

With ten examples, one answer changes the score by ten points. Collect more examples before you claim a small improvement. For open-ended answers, use a clear rubric and human review. A second model can help as a judge, but check the judge against human decisions. See LLM as judge and human evaluation.

Safety and behavior checks

Retest:

  • requests your product must refuse,
  • attempts to override instructions,
  • privacy leaks, such as asking for names from the training data,
  • your supported languages,
  • format rules and tool calls.

Using the adapter

You have two main options. Keep it separate: load the base model and then the adapter with PEFT. Merge: fold the adapter into the base weights.

Python
from peft import AutoPeftModelForCausalLM

model = AutoPeftModelForCausalLM.from_pretrained("llama-support-lora")
merged = model.merge_and_unload()
merged.save_pretrained("llama-support-merged")   # current Transformers saves safetensors

Save the tokenizer with the merged model too. If the base was loaded in 4 bits during training, merge into a higher-precision copy of the base rather than the 4-bit one, and then test the result.

For llama.cpp or Ollama, you can convert the merged folder to GGUF with convert_hf_to_gguf.py and then quantize it. llama.cpp also has tooling for LoRA adapters; check its current documentation for conversion and loading options. Ollama can import a GGUF file with a FROM line in a Modelfile.

Test the artifact you ship

Merging, converting and quantizing can each change behavior. So can a different chat template. Run your test set on the final file, in the final runtime, with the final settings. A strong score in the training notebook does not carry over automatically.

License and naming

If you distribute the model or make it available, apply your Llama version's rules. The licenses checked for this tutorial require the new model's name to begin with "Llama", and distribution brings duties such as including the license and displaying "Built with Llama". Also respect the terms of your training data. Review the license lesson.

Write a model card

A short document helps users and your future self:

TEXT
Name: Llama-BikeShop-Labeler-v1
Base model and revision:
Adapter or merged; quantization:
Intended use and out-of-scope use:
Training data: source, size, date, privacy review
Evaluation: test set, per-category scores, baseline
Known limits and risks:
License and attribution:
Owner and contact:

Release gradually

Use shadow mode first (the new model runs but users do not see its replies), then a small share of traffic. Keep the old model ready for a quick rollback. Monitor error rates, format failures, latency and user reports, without logging more personal data than needed.

Do not release only because the average score is higher. A regression in a critical category or a safety test can matter more than the average.

Read the outputs yourself

Scores hide details. Read a sample of answers from both systems side by side, without knowing which is which if possible. You may notice that the fine-tune became very short, repeats a phrase from the training data, refuses things it should answer or states guesses with too much confidence. Add each problem you find to your test set, so the next version is checked for it automatically.

Test for memorized data

If your training data contained sensitive material, try prompts that begin the way training examples began and see whether the model completes them with real details. Passing a few such probes does not prove safety, but a single leak is a clear warning. The best protection is to keep sensitive data out of training in the first place.

Set the release rule before you look

Write down the conditions for release before you see the results, for example: overall score not lower than the baseline, no critical category worse, all safety cases pass and response time within your limit. A rule written in advance protects you from talking yourself into a weak release after weeks of work.

Latency and size count too

Quality is not the only result. Compare the final file size, memory use, time to first token and generation speed with those of the baseline. A fine-tuned small model that matches a larger one can be a clear win. A fine-tune that is only slightly better but needs a much longer prompt or more memory may not be worth its upkeep.

After the release

Plan how you will notice trouble. Sample real outputs for review within your privacy rules, give users an easy way to report a bad answer and watch for changes in the kind of input you receive. Data drifts: new products, new questions and new wording appear. When quality falls, add the new cases to your test set first, then decide whether to change the prompt, the retrieval or the training data.

Keep the evidence. Store the test report next to the released file.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What is the main comparison for a fine-tuned model?

    A fair baseline shows whether tuning helped.
  2. 2. After converting and quantizing, what should you do?

    Each processing step can change behavior.
  3. 3. What does a shadow release do?

    It lets you compare on real traffic without affecting replies.

Summary

  • Compare with a baseline, per category, on untouched data.
  • Recheck safety, privacy and formats.
  • Merge or load the adapter, then test the final artifact.
  • Follow naming and attribution rules, document the model and release gradually.

Next: Serving Llama

आपकी प्रगति इसी ब्राउज़र में सेव होती है। खाते की ज़रूरत नहीं है।