glaiveai/glaive-function-calling-v2
Viewer β’ Updated β’ 113k β’ 60.1k β’ 526
How to use balaguhanesh/tool-call-ft with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct")
model = PeftModel.from_pretrained(base_model, "balaguhanesh/tool-call-ft")A QLoRA LoRA adapter that teaches Qwen/Qwen2.5-3B-Instruct to emit reliable,
schema-correct tool calls in the compact {"name": ..., "arguments": {...}}
format.
Code, training staircase, and eval harness: https://github.com/balaguhanesh/tool-call-ft
Base vs. this adapter on 300 held-out examples (greedy decoding, strict exact-match grader):
| Metric | Base | Fine-tuned | Ξ |
|---|---|---|---|
| JSON-valid rate | 51.7% | 100.0% | +48.3 |
| Function-name accuracy | 1.0% | 100.0% | +99.0 |
| Argument match (exact) | 0.3% | 95.0% | +94.7 |
The grader is strict: unparseable output fails all three axes, function name is
exact/case-sensitive, and arguments require exact dict equality ("5" != 5, any
extra/missing key fails the row). Fine-tuning here teaches format compliance and
schema discipline, not reasoning.
bitsandbytes), LoRA via peft
(r=16, Ξ±=32, all attention + MLP projections; ~30M trainable params, 0.96%)trl.SFTTrainer (supervised fine-tuning)glaiveai/glaive-function-calling-v2 β 2000 train / 300 evalfrom peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = "Qwen/Qwen2.5-3B-Instruct"
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, device_map="auto")
model = PeftModel.from_pretrained(model, "Balaguhanesh/tool-call-ft")
messages = [
{"role": "system", "content": "You are a helpful assistant with access to the following functions. Use them if required -\n{...function schema...}"},
{"role": "user", "content": "What's the weather in Paris?"},
]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))