Fine‑Tune Tool‑Calling LLMs with XYZ‑Aquila‑SFT & Qwen3 – Guide

Many developers and researchers struggle to turn raw tool‑use conversation data into a usable training signal for language models. The XYZ‑Aquila‑SFT dataset contains multi‑turn trajectories with embedded tool calls, reasoning blocks, and observations, but extracting clean JSON‑formatted calls, preserving the original system message, and applying token‑level loss only to assistant outputs is error‑prone and time‑consuming.

A practical solution is to stream the dataset, parse each trajectory into a structured object that separates questions, answers, tool schemas, and parsed calls, then verify that the parser matches the declared number of tool calls per example. From this structure you can extract the embedded tool definitions, render them back into a system message to confirm lossless conversion, and manually build ChatML prompts where loss is masked to assistant‑generated tokens only—avoiding the loss of reasoning supervision that standard chat templates cause.

Next, tokenize the rendered examples, enforce a sequence‑length policy (truncation or dropping), and split the data into training and evaluation sets. Using a simple PyTorch Dataset and a collator that pads to the longest batch, you can feed the data to a model such as Qwen3‑0.6B. Apply LoRA adapters for efficient fine‑tuning, train with gradient accumulation, mixed‑precision, and a cosine learning‑rate schedule, then evaluate tool‑call prediction before and after adaptation using teacher‑forced probes that cut the trajectory just before an assistant tool call.

The workflow yields a fine‑tuned LoRA adapter, a structured JSONL export of all trajectories, and a corpus statistics report covering tool frequency, trajectory length, and supervised‑token ratios. These artifacts let you quickly iterate on alternative length policies, scale to larger datasets, or experiment with different base models—all while retaining the full reasoning and observation context essential for reliable tool‑using agents.

#AI #MachineLearning #LLM #FineTuning #ToolUse #PEFT