AI Hints
Home›Fine-Tuning LLMs Tutorial›Decoding, Instruct Models and Chat Templates
Fine-Tuning LLMs · Lesson 17 of 120

Base vs Instruct Models

Continue text, or follow instructions.

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

You may have noticed. Our model keeps rambling, and repeating itself. That's because it's a base model. Most models come in two versions, base, and instruct.

  • Our model rambles
  • It's a base model
  • Two versions: base and instruct

Two versions

A base model has only been pretrained. It continues text, like a very good autocomplete. An instruct model is a base model that was then fine-tuned, on many examples of questions and good answers. So it follows instructions, and knows when to stop. In other words, every instruct model is itself a fine-tuned model.

Base model

  • Only pretrained
  • Continues text
  • Rambles, rarely stops

Instruct model

  • Pretrained + fine-tuned
  • Follows instructions
  • Answers, then stops

Same question, two models

We ask both versions the same question. The instruct model gets the question through its chat template, which we'll explain next. The base model has no template, so it gets plain text. Run it. The base model gives one sentence, then repeats it, again and again. The instruct model gives a proper answer. Still small, and not perfect, but it's trying to help.

app.pypython
from transformers import AutoTokenizer, AutoModelForCausalLM

question = "What is a bookshop?"
for name in ["HuggingFaceTB/SmolLM2-135M", "HuggingFaceTB/SmolLM2-135M-Instruct"]:
    tok = AutoTokenizer.from_pretrained(name)
    model = AutoModelForCausalLM.from_pretrained(name)
    if tok.chat_template:
        ids = tok.apply_chat_template(
            [{"role": "user", "content": question}], add_generation_prompt=True,
            return_dict=True, return_tensors="pt")
    else:
        ids = tok(question, return_tensors="pt")
    out = model.generate(**ids, max_new_tokens=30, do_sample=False)
    print(f"== {name.split('/')[1]}")
    print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True).strip())
Output
== SmolLM2-135M
A bookshop is a place where you can buy books. It is a place where you can buy books,
and it is a place where
== SmolLM2-135M-Instruct
A bookshop is a place where you can find a wide variety of books, from fiction and non-
fiction to children's and children's-themed

Which one should you fine-tune?

So which version should you start from? Usually the instruct version. It already understands questions and answers, so it needs fewer examples. Start from a base model only when you want full control over the format, or when you have lots of data. In our project, we'll start from the instruct model.

keyvalue
Usuallystart from instruct
Whyit already follows instructions
Base modelfor full control, lots of data
Our projectSmolLM2-135M-Instruct

Summary

Let's recap. A base model only continues text. An instruct model was fine-tuned to follow instructions. And we'll usually fine-tune an instruct model. Next, the chat template that instruct models need.

Key takeaways
  • Base: continues
  • Instruct: follows
  • Start from instruct
Next up: Chat Templates — how a conversation becomes text