Fine-Tune a Tool-Calling LLM with Qwen3-0.6B and LoRA: Full Guide
Step-by-step guide to fine-tuning Qwen3-0.6B on tool-calling tasks using the XYZ-Aquila-SFT dataset, LoRA, and Hugging Face PEFT. Includes config details.

A new tutorial from Marktechpost walks through a complete supervised fine-tuning (SFT) pipeline that teaches Qwen3-0.6B, a compact open-weight language model, to make structured tool calls. The pipeline uses the XYZ-Aquila-SFT dataset, Hugging Face Transformers, PEFT (Parameter-Efficient Fine-Tuning), and PyTorch. Key parameters include LoRA rank 16, a 1e-4 learning rate, 30 training steps, and a 2,048-token sequence limit. The guide covers everything from streaming dataset rows to evaluating tool-call accuracy before and after training.
What happened
Marktechpost published a step-by-step tutorial for fine-tuning Qwen3-0.6B on tool-calling tasks. The pipeline is built around the XYZ-Aquila-SFT dataset (from XYZAILab on Hugging Face), with LoRA adapters applied via the PEFT library. It runs end-to-end on a single GPU and exports results for further experimentation.
| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen3-0.6B |
| Dataset | XYZAILab/XYZ-Aquila-SFT (English split) |
| Training rows streamed | 400 |
| Evaluation rows | 40 |
| Post-training eval probes | 24 |
| Max sequence length | 2,048 tokens |
| LoRA rank | 16 |
| Learning rate | 1e-4 |
| Max training steps | 30 |
| Gradient accumulation steps | 8 |
| Scheduler | Cosine with warmup |
| Output directory | /content/aquila_out |
How the pipeline works
The tutorial breaks the process into clear stages. Here is the order of operations:
- Install dependencies:
datasets>=3.0.0,transformers>=4.51.0,peft>=0.13.0, andaccelerate>=1.0.0. - Stream 400 rows from the XYZ-Aquila-SFT English split and inspect the schema, including the
question,answer,number of tool calls, andtrajectoryfields. - Parse multi-turn trajectories: extract tool schemas from the system message, identify tool calls inside assistant turns using a nesting-safe JSON scanner, and count observation blocks from tool-response turns.
- Convert tool schemas between message-embedded and structured formats, then render Qwen-compatible ChatML (a structured chat format Qwen3 expects).
- Apply assistant-only loss masking, meaning the model is only trained to predict assistant tokens, not system or user tokens.
- Build a custom PyTorch dataset and data collator, then fine-tune with LoRA adapters.
- Evaluate tool-call prediction accuracy before and after training, then export the transformed dataset and corpus statistics.
Why the custom JSON parser matters
The guide notes that a simple regex like {.*?} breaks on nested tool-call arguments, which appear in every real-world tool call. The solution is a nesting-safe scanner built on Python’s json.JSONDecoder.raw_decode method. This correctly handles nested objects and arrays without false positives.
LoRA: what it does here
LoRA (Low-Rank Adaptation) freezes the base model weights and inserts small trainable matrices into specific layers. With rank 16 and only 30 training steps over 400 streamed examples, the approach keeps compute costs low while still shifting the model’s tool-calling behavior measurably. The tutorial measures this shift with 24 eval probes run before and after training.
Why it matters
Tool calling is the mechanism that lets a language model trigger external functions, search APIs, databases, or custom business logic instead of just generating text. Fine-tuning a small model like Qwen3-0.6B for this task means you can run it on modest hardware or embed it in a product without paying per-token API costs.
For teams building AI integrations into their products, a locally fine-tuned tool-calling model can replace a general-purpose API call in specific, well-defined workflows. The trade-off is the setup cost of building the pipeline versus the ongoing cost of hosted inference. At 0.6B parameters, Qwen3 is small enough that this trade-off can tip toward local deployment quickly.
This tutorial also demonstrates a broader pattern: supervised fine-tuning on structured trajectory data (not just input/output pairs) is becoming the standard approach for teaching models to follow multi-step reasoning and action sequences. Understanding that pattern is useful whether you are building agents, automation workflows, or domain-specific assistants.
Our take
This is a practical, well-structured tutorial that covers the parts other guides skip: the JSON parsing edge cases, loss masking, schema format conversion, and corpus analysis. Those details matter. A pipeline that trains on system-prompt tokens or misparses nested JSON will produce a broken model and no obvious error message.
The 30-step, 400-row setup is essentially a proof-of-concept rather than a production fine-tune. If you are serious about tool-calling reliability, you will need more data, more steps, and rigorous eval. But as a starting template to understand the full pipeline before committing resources, this is a solid foundation. Anyone following our coverage of fine-tuning reasoning LLMs will find this a complementary, more hands-on companion piece.
One honest caveat: fine-tuning at this scale works best when your tool schemas are consistent and your trajectories are clean. Real business data rarely arrives that way. Budget time for data cleaning before you budget time for training.
What to do about it
- Clone or copy the config block from the tutorial and swap in your own model ID and dataset path to test the pipeline on your data.
- Run the corpus analysis section first (before training) to check your trajectory quality: parser-vs-declared-calls match rate and observation counts are useful early signals of data problems.
- Increase
MAX_STEPSandN_STREAMincrementally and track eval probe accuracy at each checkpoint rather than jumping to a large run. - If you need help integrating a fine-tuned model into a live product or automation workflow, talk to the Lumien team about scoping that work.
The practical takeaway: treat the 30-step run as a smoke test, not a finished model. Pass it, then scale.
Frequently asked questions
What is tool calling in a language model?
Tool calling lets a language model trigger external functions or APIs instead of just returning text. The model outputs a structured call (function name plus arguments) that your code executes, then feeds the result back to the model.
What is LoRA and why is it used for fine-tuning?
LoRA (Low-Rank Adaptation) freezes the base model's weights and adds small trainable matrices to specific layers. It drastically reduces the number of parameters you need to train, making fine-tuning feasible on a single GPU with limited data.
What is assistant-only loss masking?
Loss masking means the training loss is only computed on the assistant's tokens in a conversation. System prompts and user messages are ignored during backpropagation, so the model learns to generate assistant responses without being penalized for the parts it never produces.
How much data and compute does this Qwen3-0.6B fine-tune require?
The tutorial uses 400 streamed training rows and runs for 30 steps with gradient accumulation over 8 steps. This is a proof-of-concept scale designed to verify the pipeline on a single GPU, not a production-ready fine-tune.


