Run this model with HF Jobs
Run gyung/LFM2-350M-ToolLLaMA on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/gyung/LFM2-350M-ToolLLaMA. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/gyung/LFM2-350M-ToolLLaMA on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/gyung/LFM2-350M-ToolLLaMA. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/gyung/LFM2-350M-ToolLLaMA. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use gyung/LFM2-350M-ToolLLaMA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gyung/LFM2-350M-ToolLLaMA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="gyung/LFM2-350M-ToolLLaMA") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("gyung/LFM2-350M-ToolLLaMA") model = AutoModelForCausalLM.from_pretrained("gyung/LFM2-350M-ToolLLaMA", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use gyung/LFM2-350M-ToolLLaMA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gyung/LFM2-350M-ToolLLaMA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gyung/LFM2-350M-ToolLLaMA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/gyung/LFM2-350M-ToolLLaMA
- SGLang
How to use gyung/LFM2-350M-ToolLLaMA with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gyung/LFM2-350M-ToolLLaMA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gyung/LFM2-350M-ToolLLaMA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gyung/LFM2-350M-ToolLLaMA" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gyung/LFM2-350M-ToolLLaMA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use gyung/LFM2-350M-ToolLLaMA with Docker Model Runner:
docker model run hf.co/gyung/LFM2-350M-ToolLLaMA
Download README.md from gyung/LFM2-350M-ToolLLaMA: direct link, hf CLI and curl.
- Browser
- Download file 32.6 kB
-
https://huggingface.co/gyung/LFM2-350M-ToolLLaMA/resolve/main/README.md
- Command line
-
hf download hf://gyung/LFM2-350M-ToolLLaMA/README.md
-
curl -L -o README.md https://huggingface.co/gyung/LFM2-350M-ToolLLaMA/resolve/main/README.md
base_model: LiquidAI/LFM2-350M
library_name: transformers
model_name: LFM2-350M-ToolLLaMA
tags:
- tool-calling
- react-agent
- sft
- trl
- toolbench
- liquid-ai
- lfm2
- lnn
license: other
datasets:
- gyung/toolbench-lfm-chatml
language:
- en
- ko
pipeline_tag: text-generation
π§ LFM2-350M-ToolLLaMA
πΊπΈ English
π°π· νκ΅μ΄
354M νλΌλ―Έν° μν λͺ¨λΈλ‘ Tool Callingμ μννλ ReAct μμ΄μ νΈ
Liquid AIμ LFM2-350Mμ ToolBench λ°μ΄ν°μ (187,494 μμ)μΌλ‘ Full SFTνμ¬, ReAct(Thought/Action/Action Input) νμμ Tool Callingμ μννλλ‘ νμ΅ν λͺ¨λΈμ λλ€.
λ Όλ¬Έ "Small Language Models for Efficient Agentic Tool Calling" (arXiv:2512.15943v1)μ μ€νμ LFM2 μν€ν μ²(LNN κΈ°λ°)λ‘ μ¬ννμμ΅λλ€.
Quick Start
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "gyung/LFM2-350M-ToolLLaMA"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
system_prompt = """You are AutoGPT, you can use many tools(functions) to do the following task.
At each step, you need to give your thought to analyze the status now and what to do next, with a function call to actually execute your step.
Your output should follow this format:
Thought:
Action:
Action Input:"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "What is the current weather in Seoul, South Korea?"},
]
inputs = tokenizer.apply_chat_template(
messages, return_tensors="pt", add_generation_prompt=True
).to(model.device)
with torch.no_grad():
outputs = model.generate(inputs, max_new_tokens=256, do_sample=True, temperature=0.1)
result = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
print(result)
μ€μ μΆλ ₯ μμ:
Thought: To find the current weather in Seoul, South Korea, I need to use the "weather" API.
I will call the "weather" function with the argument "location" set to "Seoul, South Korea"
to retrieve the weather information for that location.
Action: weather
Action Input: {"location": "Seoul, South Korea"}
λͺ¨λΈ μμΈ
| νλͺ© | λ΄μ© |
|---|---|
| Base Model | LiquidAI/LFM2-350M (LNN κΈ°λ°) |
| νλΌλ―Έν° | 354M |
| νμ΅ λ°μ΄ν° | gyung/toolbench-lfm-chatml (187,494 νμ΅ μμ) |
| μΆλ ₯ νμ | ReAct β Thought: / Action: / Action Input: |
| νμ΅ λ°©μ | Full SFT (TRL SFTTrainer) |
| μ λ°λ | BF16 |
| νμ΅ νκ²½ | NVIDIA H100 80GB Γ 1 (VESSL AI) |
νμ΅ μ€μ
λ Όλ¬Έ arXiv:2512.15943v1μ νμ΄νΌνλΌλ―Έν°λ₯Ό μ¬ννμμ΅λλ€.
SFTConfig(
output_dir="./sft-output",
# === νμ΅ νλΌλ―Έν° (λ
Όλ¬Έ κΈ°λ°) ===
num_train_epochs=1,
per_device_train_batch_size=8, # H100 80GB: 350M BF16μ΄λ©΄ 16 μ¬μ
gradient_accumulation_steps=4, # effective batch size = 8 Γ 4 = 32
gradient_checkpointing=True,
# === μ΅μ ν (λ
Όλ¬Έ μ€μ ) ===
learning_rate=5e-5, # λ
Όλ¬Έ: 5Γ10β»β΅
lr_scheduler_type="cosine",
warmup_steps=100, # λ
Όλ¬Έ: 100 warmup steps
max_grad_norm=0.3, # λ
Όλ¬Έ: aggressive clipping
weight_decay=0.01, # λ
Όλ¬Έ: AdamW 0.01
optim="adamw_torch",
# === μ λ°λ (H100: BF16 λ€μ΄ν°λΈ) ===
bf16=True,
fp16=False,
# === μνμ€ μ€μ ===
max_length=8192, # λ
Όλ¬Έ: 8192 tokens
# === 체ν¬ν¬μΈνΈ + Hub μ
λ‘λ ===
# μ΄ ~5,800 steps β 500 stepλ§λ€ μ μ₯ β ~12ν 체ν¬ν¬μΈνΈ
logging_steps=50,
save_strategy="steps",
save_steps=500, # μμ£Ό μ μ₯ (μ₯μ λλΉ + μ€κ° μ±λ₯ λΉκ΅)
save_total_limit=5,
# === HuggingFace Hub μ
λ‘λ ===
push_to_hub=True,
hub_model_id="gyung/LFM2-350M-ToolLLaMA",
hub_strategy="every_save", # λ§€ 체ν¬ν¬μΈνΈλ§λ€ HF μ
λ‘λ
# === λ°μ΄ν°μ
μ€μ ===
dataset_text_field="messages",
packing=False,
report_to="none",
)
- μ΄ νμ΅ Step: 5,891 (187,494 / 32)
- νμ΅ μκ°: 4μκ° 4λΆ 14μ΄ (H100 80GB Γ 1)
- μ΅μ’ Loss: 0.1668
- 체ν¬ν¬μΈνΈ: λ§€ 500 stepλ§λ€ μλ HuggingFace μ λ‘λ
Training Loss Curve
| Step | Loss | Step | Loss | Step | Loss |
|---|---|---|---|---|---|
| 50 | 1.5385 | 500 | 0.3496 | 2000 | 0.1959 |
| 100 | 0.6595 | 1000 | 0.2441 | 3000 | 0.1717 |
| 200 | 0.4875 | 1500 | 0.2223 | 4000 | 0.1746 |
| 300 | 0.4343 | 1800 | 0.2081 | 5000 | 0.1743 |
| 5850 | 0.1668 |
νμ΅ μ΄λ° κΈκ²©ν loss κ°μ ν, ~1000 step μ΄ν μμ μ μΌλ‘ μλ ΄. μ΅μ’ loss 0.1668.
νμ΅ ν΅κ³
| νλͺ© | κ° |
|---|---|
| μ΅λ VRAM | 53.73 GB / 80 GB |
| νκ· νμ΅ μλ | 12.86 samples/s, 0.40 steps/s |
| νκ· Train Loss | 0.2236 |
| Mean Token Accuracy | 95.64% |
| μ΄ νμ΅ ν ν° | ~500M tokens |
| Total FLOPs | 1.42 Γ 10ΒΉβΈ |
Framework Versions
- TRL: 0.20.0
- Transformers: 4.54.0
- PyTorch: 2.9.1+cu128
- Datasets: 4.6.0
- Tokenizers: 0.21.4
μ΅μ’ λͺ¨λΈ ν μ€νΈ
1) λꡬ λͺ©λ‘ μμ΄ μμ μμ±
| Query | Thought | Action | Action Input | νκ° |
|---|---|---|---|---|
| "What is the current weather in Seoul?" | β λ Όλ¦¬μ | weather |
{"location": "Seoul, South Korea"} |
βββββ |
| "Search for the latest news about AI" | β λ Όλ¦¬μ | news_api |
μ μ ν νλΌλ―Έν° | ββββ |
| "Find info about movie 'Inception'" | β λ Όλ¦¬μ | search |
{"query": "Inception"} |
ββββ |
λꡬ μ΄λ¦μ΄ genericν κ²μ system promptμ λꡬ λͺ©λ‘μ λͺ μνμ§ μμκΈ° λλ¬Έ. νμκ³Ό μΆλ‘ μ μλ²½.
2) λꡬ λͺ©λ‘ ν¬ν¨ ν μ€νΈ β 4/4 (100%)
ToolBench νμμΌλ‘ μ¬μ© κ°λ₯ν λꡬλ₯Ό system promptμ λͺ μν κ²½μ°:
| Query | Expected Action | Predicted Action | Match |
|---|---|---|---|
| Current weather in Seoul | get_current_weather_for_weatherapi |
get_current_weather_for_weatherapi |
β |
| Latest news about AI | search_news_for_newsapi |
search_news_for_newsapi |
β |
| Movie info for 'Inception' | search_movie_for_imdb |
search_movie_for_imdb |
β |
| Ultimate Oscillator BTCUSDT | ultimateoscillator_for_qvantana |
ultimateoscillator_for_qvantana |
β |
π μ€μ μλ΅ μμ (ν΄λ¦νμ¬ νΌμΉκΈ°)
Query: "Get the Ultimate Oscillator data for BTCUSDT on Binance with daily interval."
Thought: I need to call the 'ultimateoscillator_for_qvantana' function to get the
Ultimate Oscillator data for BTCUSDT on Binance with a daily interval. The current
arguments for the function call are: exchange - "Binance", market - "BTCUSDT",
and interval - "1d". This will allow me to retrieve the necessary data for analysis.
Action: ultimateoscillator_for_qvantana
Action Input: {
"exchange": "Binance",
"market": "BTCUSDT",
"interval": "1d"
}
π‘ λꡬ λͺ©λ‘μ΄ 2~3κ°λ‘ λͺ νν μλ리μ€μμλ 100% μ νλ. 볡μ‘ν μλ리μ€(λꡬ 10κ°+)μμλ ToolBench eval κΈ°μ€ ~55%.
νκ° κ²°κ³Ό
νκ° νκ²½
- Hardware: NVIDIA A100-SXM4-80GB
- νκ° λ°μ΄ν°:
gyung/toolbench-lfm-chatml(eval split, 762 samples) - μμ± μ€μ :
max_new_tokens=512,temperature=0.1
νκ° μ§ν
| μ§ν | μ€λͺ |
|---|---|
| Completion Rate | μλ―Έ μλ μλ΅(10μ μ΄μ)μ μμ±ν λΉμ¨ |
| Format Accuracy | ReAct νμ(Thought: + Action:) ν¬ν¨ λΉμ¨ |
| Action Match Rate | μ λ΅ Action μ΄λ¦κ³Ό μ νν μΌμΉνλ λΉμ¨ |
κ²°κ³Ό λΉκ΅
| λͺ¨λΈ | Params | Completion | Format Acc. | Action Match |
|---|---|---|---|---|
| LFM2-350M (Base) | 354M | 100% | 62.7% | 0.0% |
| LFM2-350M-ToolLLaMA (1K step) | 354M | 100% | 100.0% | 55.1% |
| LFM2-350M-ToolLLaMA (2.5K step) | 354M | 100% | 100.0% | 54.1% |
| LFM2-350M-ToolLLaMA (5.9K step, μ΅μ’ ) | 354M | 100% | 99.9% | 56.3% |
| LFM2-1.2B-Tool (Liquid AI 곡μ) | 1.2B | 100% | 97.9% | 0.0% |
| GPT-5-Nano (OpenAI, νμ΅ μμ) | β | 100%* | 78.6%* | 8.5%* |
| ToolLLaMA-2-7b-v2 (λ Όλ¬Έ μλ³Έ) | 6.7B | 100% | 99.7% | 75.3% |
ν΅μ¬ μΈμ¬μ΄νΈ
- SFT ν¨κ³Ό: νμ΅ μ 0.0% β μ΅μ’ 56.3% Action Match Rate, Format Accuracy 99.9% λ¬μ±
- μ΅μ 체ν¬ν¬μΈνΈ: 1K step(55.1%) β 2.5K(54.1%) β 5.9K(56.3%) β μ΅μ’ λͺ¨λΈμ΄ κ°μ₯ λμ μ±λ₯
- LFM2-1.2B-Tool λΉκ΅: 3.5λ°° ν° κ³΅μ λͺ¨λΈ(0.0%)μ μλ β νμ΅ λ°μ΄ν° νμ μ λ ¬μ μ€μμ±
- ToolLLaMA-7B λλΉ: 20λ°° μμ λͺ¨λΈλ‘ 75.3% λλΉ 56.3% λ¬μ± (74.8% μμ€)
λ Όλ¬Έ νκ° λ°©μκ³Όμ μ°¨μ΄
λ Όλ¬Έμμ λ³΄κ³ λ OPT-350Mμ Pass Rate 77.55% μ λ³Έ λͺ¨λΈμ Action Match Rateλ μ§μ λΉκ΅κ° λΆκ°λ₯ν©λλ€.
| νλͺ© | λ Όλ¬Έ (ToolEval) | λ³Έ νλ‘μ νΈ |
|---|---|---|
| νκ° λ°©λ² | ChatGPT-based judge (4ν νμ + λ€μκ²°) | λ¬Έμμ΄ μ ν μΌμΉ |
| νκ° κΈ°μ€ | ν΄κ²° κ²½λ‘μ μ μ μ± (Pass/Fail) | Action μ΄λ¦ μ ν μΌμΉ |
| ν μ€νΈμ | 1,100 queries (G1~G3, 6κ° μΉ΄ν κ³ λ¦¬) | 762 samples (eval split) |
| μ€ν λ°©μ | λ€λ¨κ³ μΆλ‘ (μ΅λ 10ν λ°λ³΅) | λ¨μΌ ν΄ μμ± |
π‘ λ Όλ¬Έμ ToolEvalμ λͺ¨λΈμ΄ μ€μ λ‘ μ¬λ¬ ν΄μ κ±Έμ³ toolμ νΈμΆνλ©° λ¬Έμ λ₯Ό ν΄κ²°νλ μ 체 κ³Όμ μ ChatGPTκ° νκ°νλ λ°©μμ λλ€. λ³Έ νλ‘μ νΈμ Action Match Rateλ 첫 λ²μ§Έ tool νΈμΆμ μ νν μ΄λ¦ μΌμΉλ§ μΈ‘μ νλ―λ‘, λ 보μμ μΈ(μ격ν) μ§νμ λλ€.
LLM-as-Judge νκ° (ToolEval μ€νμΌ)
λ
Όλ¬Έμ ToolEvalμ κ°κΉμ΄ νκ°λ₯Ό μν΄, eval_judge.pyμμ GPT κΈ°λ° judgeλ₯Ό ꡬννμμ΅λλ€:
# λ¨μΌ λΌμ΄λ νκ° (λΉ λ₯Έ ν
μ€νΈ)
python eval_judge.py --input results/eval_results.json --rounds 1
# λ
Όλ¬Έ μ¬ν (4λΌμ΄λ λ€μκ²° ν¬ν)
python eval_judge.py --input results/eval_results.json --rounds 4
μ΄ judgeλ Action μ΄λ¦μ μ νν μΌμΉκ° μλ, λꡬ μ νμ λ Όλ¦¬μ μ μ μ±μ κΈ°μ€μΌλ‘ νμ ν©λλ€.
λ°μ΄ν° νμ
λ³Έ λͺ¨λΈμ ChatML νμμ λν λ°μ΄ν°λ‘ νμ΅λμμ΅λλ€.
{
"messages": [
{"role": "system", "content": "You are AutoGPT, you can use many tools(functions) to do the following task..."},
{"role": "user", "content": "μ¬μ©μ 쿼리..."},
{"role": "assistant", "content": "Thought: ...\nAction: tool_name\nAction Input: {\"param\": \"value\"}"},
{"role": "tool", "content": "{\"response\": ...}"}
]
}
μλ³Έ ToolBenchμ "function" μν μ LFM2 ChatML νΈνμ μν΄ "tool"λ‘ λ³ννμμ΅λλ€.
μ€μ λ°°ν¬ μ λ΅
354M λͺ¨λΈμ κ°μ (λΉ λ₯Έ μΆλ‘ , μ λΉμ©, μ£μ§ λ°°ν¬)μ μ΄λ¦¬λ €λ©΄, λΌμ°ν° + λꡬ μ λ³ μ£Όμ νμ΄νλΌμΈμ΄ κ°μ₯ ν¨κ³Όμ μ λλ€.
μ¬μ©μ 쿼리 β [λΌμ°ν°: μΈν
νΈ λΆλ₯] β ν΄λΉ λꡬ 2~3κ°λ§ ν둬ννΈμ μ£Όμ
β LFM2-350M β ~100% μ νλ
| λΉκ΅ | λꡬ μ 체 μ£Όμ (ToolBenchμ) | λΌμ°ν° + μ λ³ μ£Όμ |
|---|---|---|
| ν둬ννΈ λꡬ μ | 10~50κ° | 2~3κ° |
| Action Match | ~56% | ~100% |
| ν둬ννΈ κΈΈμ΄ | μμ² ν ν° | μλ°± ν ν° |
| μΆλ‘ μλ | λλ¦Ό | λΉ λ¦ |
# Stage 1: λΌμ°ν° (μΈμ½λ λͺ¨λΈ / μλ² λ© μ μ¬λ κΈ°λ°)
TOOL_CATEGORIES = {
"weather": ["get_current_weather_for_weatherapi", "get_forecast_for_weatherapi"],
"finance": ["ultimateoscillator_for_qvantana", "typicalprice_for_qvantana"],
"news": ["search_news_for_newsapi", "get_top_headlines_for_newsapi"],
}
# Stage 2: ν΄λΉ λκ΅¬λ§ ν둬ννΈμ μ£Όμ
β LFM2-350M β ~100%
category = classify_query(user_query) # BERT, μ½μ¬μΈ μ μ¬λ λ±
tools = TOOL_CATEGORIES[category] # 2~3κ°λ§ μ ν
prompt = build_prompt(tools, user_query)
response = model.generate(prompt) # β κ±°μ 100%
μ΄κ²μ΄ λ Όλ¬Έμμ λ§νλ **"Small Language Models for Efficient Agentic Tool Calling"**μ μ€μ μ μλ―Έμ λλ€: μμ λͺ¨λΈ + μ€λ§νΈ λΌμ°ν = ν° λͺ¨λΈλ³΄λ€ λΉ λ₯΄κ³ μ λ ΄νκ³ μ νν μμ€ν .
μ ν μ¬ν
- π νκ° μ§ν νκ³ β Action Match Rateλ μ격ν λ¬Έμμ΄ λ§€μΉμΌλ‘, μλ―Έμ μΌλ‘ λμΌν λꡬλ₯Ό λ€λ₯Έ μ΄λ¦μΌλ‘ μμΈ‘ν κ²½μ° μ€ν¨λ‘ μ²λ¦¬
- π§ λ¨μΌ ν΄ νκ° β λ©ν° ν΄ μμ΄μ νΈ μλ리μ€(λꡬ κ²°κ³Όλ₯Ό λ°κ³ λ€μ μΆλ‘ )μ λν νκ° λ―Έμ€μ
- ποΈ μν€ν μ² μ°¨μ΄ β λ Όλ¬Έμ OPT-350M(Transformer), λ³Έ λͺ¨λΈμ LFM2-350M(LNN κΈ°λ°)μΌλ‘ μ§μ μ μΈ μν€ν μ² λΉκ΅λ λΆκ°
ν₯ν κ°μ λ°©ν₯: κΈΈμ΄λ³ λΆν νμ΅
νμ¬ νμ΅μ λͺ¨λ μνμ max_length=8192λ‘ ν΅μΌνμ¬ μ²λ¦¬ν©λλ€. νμ§λ§ ToolBench λ°μ΄ν°μ λλΆλΆμ 1K~4K ν ν° λ²μμ΄λ―λ‘, κΈΈμ΄λ³λ‘ λ²ν·μ λλ λ°°μΉ μ¬μ΄μ¦λ₯Ό λ€λ₯΄κ² μ€μ νλ©΄ νμ΅ μλλ₯Ό ν¬κ² κ°μ ν μ μμ΅λλ€.
| λ²ν· | context length | batch size | ν¨κ³Ό |
|---|---|---|---|
| μ§§μ λ°μ΄ν° | ~1024 | 64~128 | ν¨λ© λλΉ μ΅μν |
| μ€κ° λ°μ΄ν° | ~2048β4096 | 16~32 | λλΆλΆμ λ°μ΄ν° ν΄λΉ |
| κΈ΄ λ°μ΄ν° | ~8192 | 8 | νμ¬μ λμΌ |
- μλ: μ 체 νμ΅ μκ° 50
60% λ¨μΆ κ°λ₯ (4μκ° β ~1.52μκ°) - μ±λ₯: ν¨λ© κ°μλ‘ gradient μΆμ μ΄ μμ μ μ΄ λμ΄, λμΌνκ±°λ μ½κ° λμ μ±λ₯ κΈ°λ
- κ°νΈν λμ: TRLμ
packing=Trueμ΅μ β μ§§μ μνμ€ μ¬λ¬ κ°λ₯Ό νλμ μ΄μ΄λΆμ¬ ν¨λ© λλΉλ₯Ό μμ¨ μ μμ
νμ΅ μ¬ν
μ¬μ μ€λΉ
- HuggingFace ν ν° (Write κΆν) β λ°κΈ λ§ν¬
- GPU νκ²½ β NVIDIA H100/A100 80GB κΆμ₯
νμ΅ μ€ν
# VESSL AIμμ μ€ν
vessl run create -f vessl_notebook.yaml
# β Jupyterμμ notebooks/01_train_trl.ipynb μ
λ‘λ ν μμλλ‘ μ€ν
νκ° μ€ν
# VESSL AI κ°μ μΈμ€ν΄μ€μμ
# β notebooks/03_evaluate.ipynb μ
λ‘λ ν μμλλ‘ μ€ν
μ°Έκ³ μλ£
- π λ Όλ¬Έ: Small Language Models for Efficient Agentic Tool Calling
- π€ Base Model: LiquidAI/LFM2-350M
- π Dataset: gyung/toolbench-lfm-chatml
- π§ ToolBench: OpenBMB/ToolBench
- π Liquid AI Docs: Tool Use Guide
Citation
@misc{vonwerra2022trl,
title = {{TRL: Transformer Reinforcement Learning}},
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
year = 2020,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/huggingface/trl}}
}
@article{qin2023toolllm,
title = {ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIs},
author = {Qin, Yujia and others},
journal = {arXiv preprint arXiv:2307.16789},
year = {2023}
}
@article{liquidai2025lfm2,
title={LFM2 Technical Report},
author={Liquid AI},
journal={arXiv preprint arXiv:2511.23404},
year={2025}
}
πΊπΈ English
A 354M parameter ReAct agent for Tool Calling, fine-tuned on ToolBench
This model is a full SFT of Liquid AI's LFM2-350M on the ToolBench dataset (187,494 training examples), trained to perform Tool Calling in the ReAct (Thought/Action/Action Input) format.
It reproduces the experiment from "Small Language Models for Efficient Agentic Tool Calling" (arXiv:2512.15943v1) using the LFM2 architecture (LNN-based).
Quick Start
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "gyung/LFM2-350M-ToolLLaMA"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
system_prompt = """You are AutoGPT, you can use many tools(functions) to do the following task.
At each step, you need to give your thought to analyze the status now and what to do next, with a function call to actually execute your step.
Your output should follow this format:
Thought:
Action:
Action Input:"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "What is the current weather in Seoul, South Korea?"},
]
inputs = tokenizer.apply_chat_template(
messages, return_tensors="pt", add_generation_prompt=True
).to(model.device)
with torch.no_grad():
outputs = model.generate(inputs, max_new_tokens=256, do_sample=True, temperature=0.1)
result = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
print(result)
Actual Output Example:
Thought: To find the current weather in Seoul, South Korea, I need to use the "weather" API.
I will call the "weather" function with the argument "location" set to "Seoul, South Korea"
to retrieve the weather information for that location.
Action: weather
Action Input: {"location": "Seoul, South Korea"}
Model Details
| Item | Details |
|---|---|
| Base Model | LiquidAI/LFM2-350M (LNN-based) |
| Parameters | 354M |
| Training Data | gyung/toolbench-lfm-chatml (187,494 examples) |
| Output Format | ReAct β Thought: / Action: / Action Input: |
| Training Method | Full SFT (TRL SFTTrainer) |
| Precision | BF16 |
| Training Hardware | NVIDIA H100 80GB Γ 1 (VESSL AI) |
Training Configuration
Hyperparameters reproduced from arXiv:2512.15943v1.
SFTConfig(
output_dir="./sft-output",
# === Training Parameters (Paper-based) ===
num_train_epochs=1,
per_device_train_batch_size=8, # H100 80GB: 350M BF16 fits 16 easily
gradient_accumulation_steps=4, # effective batch size = 8 Γ 4 = 32
gradient_checkpointing=True,
# === Optimization (Paper Settings) ===
learning_rate=5e-5, # Paper: 5Γ10β»β΅
lr_scheduler_type="cosine",
warmup_steps=100, # Paper: 100 warmup steps
max_grad_norm=0.3, # Paper: aggressive clipping
weight_decay=0.01, # Paper: AdamW 0.01
optim="adamw_torch",
# === Precision (H100: native BF16) ===
bf16=True,
fp16=False,
# === Sequence Settings ===
max_length=8192, # Paper: 8192 tokens
# === Checkpointing + Hub Upload ===
# Total ~5,800 steps β save every 500 β ~12 checkpoints
logging_steps=50,
save_strategy="steps",
save_steps=500, # Frequent saves (fault tolerance + perf comparison)
save_total_limit=5,
# === HuggingFace Hub Upload ===
push_to_hub=True,
hub_model_id="gyung/LFM2-350M-ToolLLaMA",
hub_strategy="every_save", # Upload to HF at every checkpoint
# === Dataset Settings ===
dataset_text_field="messages",
packing=False,
report_to="none",
)
- Total Training Steps: 5,891 (187,494 / 32)
- Training Time: 4h 4m 14s (H100 80GB Γ 1)
- Final Loss: 0.1668
- Checkpoints: Auto-uploaded to HuggingFace every 500 steps
Training Loss Curve
| Step | Loss | Step | Loss | Step | Loss |
|---|---|---|---|---|---|
| 50 | 1.5385 | 500 | 0.3496 | 2000 | 0.1959 |
| 100 | 0.6595 | 1000 | 0.2441 | 3000 | 0.1717 |
| 200 | 0.4875 | 1500 | 0.2223 | 4000 | 0.1746 |
| 300 | 0.4343 | 1800 | 0.2081 | 5000 | 0.1743 |
| 5850 | 0.1668 |
Rapid loss drop in early training, stabilizing after ~1000 steps. Final loss: 0.1668.
Training Statistics
| Item | Value |
|---|---|
| Peak VRAM | 53.73 GB / 80 GB |
| Avg. Throughput | 12.86 samples/s, 0.40 steps/s |
| Avg. Train Loss | 0.2236 |
| Mean Token Accuracy | 95.64% |
| Total Tokens Trained | ~500M tokens |
| Total FLOPs | 1.42 Γ 10ΒΉβΈ |
Framework Versions
- TRL: 0.20.0
- Transformers: 4.54.0
- PyTorch: 2.9.1+cu128
- Datasets: 4.6.0
- Tokenizers: 0.21.4
Final Model Test
1) Free generation (no tool list)
| Query | Thought | Action | Action Input | Rating |
|---|---|---|---|---|
| "What is the current weather in Seoul?" | β Logical | weather |
{"location": "Seoul, South Korea"} |
βββββ |
| "Search for the latest news about AI" | β Logical | news_api |
Appropriate params | ββββ |
| "Find info about movie 'Inception'" | β Logical | search |
{"query": "Inception"} |
ββββ |
Generic tool names are expected since no tool list was given. Format and reasoning are perfect.
2) With tool list in prompt β 4/4 (100%)
When available tools are specified in the system prompt (ToolBench style):
| Query | Expected Action | Predicted Action | Match |
|---|---|---|---|
| Current weather in Seoul | get_current_weather_for_weatherapi |
get_current_weather_for_weatherapi |
β |
| Latest news about AI | search_news_for_newsapi |
search_news_for_newsapi |
β |
| Movie info for 'Inception' | search_movie_for_imdb |
search_movie_for_imdb |
β |
| Ultimate Oscillator BTCUSDT | ultimateoscillator_for_qvantana |
ultimateoscillator_for_qvantana |
β |
π Actual response example (click to expand)
Query: "Get the Ultimate Oscillator data for BTCUSDT on Binance with daily interval."
Thought: I need to call the 'ultimateoscillator_for_qvantana' function to get the
Ultimate Oscillator data for BTCUSDT on Binance with a daily interval. The current
arguments for the function call are: exchange - "Binance", market - "BTCUSDT",
and interval - "1d". This will allow me to retrieve the necessary data for analysis.
Action: ultimateoscillator_for_qvantana
Action Input: {
"exchange": "Binance",
"market": "BTCUSDT",
"interval": "1d"
}
π‘ 100% accuracy with 2β3 clear tool choices. For complex scenarios (10+ tools), ToolBench eval shows ~55% Action Match Rate.
Evaluation Results
Evaluation Setup
- Hardware: NVIDIA A100-SXM4-80GB
- Eval Data:
gyung/toolbench-lfm-chatml(eval split, 762 samples) - Generation Settings:
max_new_tokens=512,temperature=0.1
Metrics
| Metric | Description |
|---|---|
| Completion Rate | Ratio of non-empty responses (β₯10 chars) |
| Format Accuracy | Ratio containing ReAct format (Thought: + Action:) |
| Action Match Rate | Exact string match with ground truth Action name |
Results Comparison
| Model | Params | Completion | Format Acc. | Action Match |
|---|---|---|---|---|
| LFM2-350M (Base) | 354M | 100% | 62.7% | 0.0% |
| LFM2-350M-ToolLLaMA (1K step) | 354M | 100% | 100.0% | 55.1% |
| LFM2-350M-ToolLLaMA (2.5K step) | 354M | 100% | 100.0% | 54.1% |
| LFM2-350M-ToolLLaMA (5.9K step, Final) | 354M | 100% | 99.9% | 56.3% |
| LFM2-1.2B-Tool (Liquid AI Official) | 1.2B | 100% | 97.9% | 0.0% |
| GPT-5-Nano (OpenAI, no ToolBench training) | β | 100%* | 78.6%* | 8.5%* |
| ToolLLaMA-2-7b-v2 (Paper Original) | 6.7B | 100% | 99.7% | 75.3% |
Key Insights
- SFT Effect: Base 0.0% β Final 56.3% Action Match Rate, Format Accuracy 99.9%
- Best checkpoint: 1K(55.1%) β 2.5K(54.1%) β 5.9K(56.3%) β final model achieves the highest score
- vs LFM2-1.2B-Tool: Outperforms 3.5Γ larger official model (0.0%) β importance of training data format alignment
- vs ToolLLaMA-7B: 56.3% vs 75.3% with a 20Γ smaller model (74.8% of 7B performance)
Difference from Paper's Evaluation
The paper's reported OPT-350M Pass Rate of 77.55% and this model's Action Match Rate are not directly comparable.
| Aspect | Paper (ToolEval) | This Project |
|---|---|---|
| Method | ChatGPT-based judge (4 rounds + majority vote) | Exact string match |
| Criteria | Solution path adequacy (Pass/Fail) | Exact Action name match |
| Test Set | 1,100 queries (G1~G3, 6 categories) | 762 samples (eval split) |
| Execution | Multi-step reasoning (up to 10 iterations) | Single-turn generation |
π‘ The paper's ToolEval evaluates the entire multi-turn tool-calling process via ChatGPT judge. This project's Action Match Rate only measures exact first-turn tool name match, making it a more conservative (stricter) metric.
LLM-as-Judge Evaluation (ToolEval Style)
For evaluation closer to the paper's ToolEval, a GPT-based judge is implemented in eval_judge.py:
# Single round (quick test)
python eval_judge.py --input results/eval_results.json --rounds 1
# Paper reproduction (4-round majority voting)
python eval_judge.py --input results/eval_results.json --rounds 4
This judge evaluates logical appropriateness of tool selection rather than exact string matching.
Data Format
The model was trained on ChatML-formatted conversation data.
{
"messages": [
{"role": "system", "content": "You are AutoGPT, you can use many tools(functions) to do the following task..."},
{"role": "user", "content": "User query..."},
{"role": "assistant", "content": "Thought: ...\nAction: tool_name\nAction Input: {\"param\": \"value\"}"},
{"role": "tool", "content": "{\"response\": ...}"}
]
}
The original ToolBench "function" role was converted to "tool" for LFM2 ChatML compatibility.
Practical Deployment Strategy
To maximize the 354M model's strengths (fast inference, low cost, edge deployment), a router + selective tool injection pipeline is most effective.
User Query β [Router: Intent Classification] β Inject 2-3 relevant tools β LFM2-350M β ~100% accuracy
| Comparison | All tools injected (ToolBench style) | Router + Selective injection |
|---|---|---|
| Tools in prompt | 10β50 | 2β3 |
| Action Match | ~56% | ~100% |
| Prompt length | Thousands of tokens | Hundreds of tokens |
| Inference speed | Slow | Fast |
# Stage 1: Router (encoder model / embedding similarity)
TOOL_CATEGORIES = {
"weather": ["get_current_weather_for_weatherapi", "get_forecast_for_weatherapi"],
"finance": ["ultimateoscillator_for_qvantana", "typicalprice_for_qvantana"],
"news": ["search_news_for_newsapi", "get_top_headlines_for_newsapi"],
}
# Stage 2: Inject only relevant tools β LFM2-350M β ~100%
category = classify_query(user_query) # BERT, cosine similarity, etc.
tools = TOOL_CATEGORIES[category] # Select only 2-3
prompt = build_prompt(tools, user_query)
response = model.generate(prompt) # β Near 100%
This is the practical meaning of "Small Language Models for Efficient Agentic Tool Calling": small model + smart routing = faster, cheaper, and more accurate than a single large model.
Limitations
- π Evaluation metric limitation β Action Match Rate uses strict string matching; semantically equivalent tools predicted under different names count as failures
- π§ Single-turn evaluation β Multi-turn agent scenarios (receiving tool results and reasoning again) not yet evaluated
- ποΈ Architecture difference β Paper uses OPT-350M (Transformer), this model uses LFM2-350M (LNN-based); direct architecture comparison not possible
Potential Improvements: Length-Bucketed Training
The current training uses a uniform max_length=8192 for all samples. However, most ToolBench data falls in the 1Kβ4K token range, meaning significant compute is wasted on padding. Bucketing by sequence length with different batch sizes could substantially improve training speed.
| Bucket | Context Length | Batch Size | Effect |
|---|---|---|---|
| Short data | ~1024 | 64β128 | Minimal padding waste |
| Medium data | ~2048β4096 | 16β32 | Covers majority of data |
| Long data | ~8192 | 8 | Same as current |
- Speed: Could reduce total training time by 50β60% (4h β ~1.5β2h)
- Performance: Reduced padding leads to more stable gradient estimation β expect equal or slightly better performance
- Simple alternative: TRL's
packing=Trueβ concatenates multiple short sequences into one, eliminating padding waste
Reproduction
Prerequisites
- HuggingFace Token (Write permission) β Get token
- GPU Environment β NVIDIA H100/A100 80GB recommended
Training
# Run on VESSL AI
vessl run create -f vessl_notebook.yaml
# β Upload notebooks/01_train_trl.ipynb in Jupyter and run cells sequentially
Evaluation
# On the same VESSL AI instance
# β Upload notebooks/03_evaluate.ipynb and run cells sequentially
References
- π Paper: Small Language Models for Efficient Agentic Tool Calling
- π€ Base Model: LiquidAI/LFM2-350M
- π Dataset: gyung/toolbench-lfm-chatml
- π§ ToolBench: OpenBMB/ToolBench
- π Liquid AI Docs: Tool Use Guide
Citation
@misc{vonwerra2022trl,
title = {{TRL: Transformer Reinforcement Learning}},
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
year = 2020,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/huggingface/trl}}
}
@article{qin2023toolllm,
title = {ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIs},
author = {Qin, Yujia and others},
journal = {arXiv preprint arXiv:2307.16789},
year = {2023}
}
@article{liquidai2025lfm2,
title={LFM2 Technical Report},
author={Liquid AI},
journal={arXiv preprint arXiv:2511.23404},
year={2025}
}