
Teach a Small Open Model to Use Your Functions Reliably: Fine-Tune With the xLAM Dataset and TRL
Chris Harper
2 min read
Jul 19, 2026 · 04:03 UTC
Fine-tune a 3B open model on 5,000 function-calling examples and it matches a 70B model at tool routing — xLAM dataset + TRL SFTTrainer, one free Colab GPU.
Prompting a small model to output correctly-formatted tool calls is a constant fight: right function name, mangled arguments; two calls when you wanted one; strings unquoted. Fine-tuning fixes this at the source — after a few thousand examples the model understands your tool format, rather than trying to follow a hint in the system prompt.
What you'll be able to do after this:
- Understand why SFT outperforms prompting alone for narrow tool-routing tasks
- Load the xLAM 60k dataset and run TRL SFTTrainer with LoRA in ~30 lines
- Evaluate the fine-tune by comparing parsed tool calls before and after on a held-out set
The xLAM dataset
Salesforce AI Research released xlam-function-calling-60k — 60,000 multi-turn examples spanning 200+ APIs. Each row includes a tools key (JSON schema) and a conversation with properly-formatted tool_calls messages. TRL passes the tools key through apply_chat_template automatically — no preprocessing needed.
The HuggingFace Cookbook notebook walks through the full pipeline end-to-end. Start there.
Training in ~30 lines
from datasets import load_dataset
from trl import SFTConfig, SFTTrainer
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import LoraConfig
dataset = load_dataset("Salesforce/xlam-function-calling-60k", split="train[:5000]")
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.2-3B-Instruct", load_in_4bit=True
)
tok = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
trainer = SFTTrainer(
model=model,
args=SFTConfig(
output_dir="./fn-call-lora",
num_train_epochs=1,
per_device_train_batch_size=4,
gradient_checkpointing=True,
max_length=1024,
),
train_dataset=dataset,
peft_config=LoraConfig(r=16, lora_alpha=32, target_modules="all-linear"),
processing_class=tok,
)
trainer.train()
After training, call trainer.model.merge_and_unload() to fold the adapter in, then push to HuggingFace Hub.
Quick eval
Pick 50 held-out examples. Run the base model and your fine-tuned adapter on the same prompts. Parse the tool_calls blocks and compare: function name correct, argument keys correct, argument types correct. A well-trained 3B adapter reaches >90% exact-match on single-API routing tasks where the base model sits around 55–65%.
Sources: Fine-tuning LLMs for Function Calling with xLAM Dataset — HuggingFace Cookbook · xlam-function-calling-60k dataset — HuggingFace Hub · TRL SFTTrainer docs — HuggingFace · Practical Guide to Fine-Tuning for Tool Calling — Falcon LM