---
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](https://huggingface.co/gyung/LFM2-350M-ToolLLaMA#%F0%9F%87%BA%F0%9F%87%B8-english)**
## ๐ฐ๐ท ํ๊ตญ์ด
> **354M ํ๋ผ๋ฏธํฐ ์ํ ๋ชจ๋ธ๋ก Tool Calling์ ์ํํ๋ ReAct ์์ด์ ํธ**
[](https://huggingface.co/LiquidAI/LFM2-350M)
[](https://huggingface.co/datasets/gyung/toolbench-lfm-chatml)
[](https://arxiv.org/html/2512.15943v1)
[Liquid AI์ LFM2-350M](https://huggingface.co/LiquidAI/LFM2-350M)์ [ToolBench ๋ฐ์ดํฐ์
](https://github.com/OpenBMB/ToolBench)(187,494 ์์)์ผ๋ก Full SFTํ์ฌ, **ReAct(Thought/Action/Action Input) ํ์**์ Tool Calling์ ์ํํ๋๋ก ํ์ตํ ๋ชจ๋ธ์
๋๋ค.
๋
ผ๋ฌธ *"[Small Language Models for Efficient Agentic Tool Calling](https://arxiv.org/html/2512.15943v1)"* (arXiv:2512.15943v1)์ ์คํ์ LFM2 ์ํคํ
์ฒ(LNN ๊ธฐ๋ฐ)๋ก ์ฌํํ์์ต๋๋ค.
---
### Quick Start
```python
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](https://huggingface.co/LiquidAI/LFM2-350M) (LNN ๊ธฐ๋ฐ) |
| **ํ๋ผ๋ฏธํฐ** | 354M |
| **ํ์ต ๋ฐ์ดํฐ** | [gyung/toolbench-lfm-chatml](https://huggingface.co/datasets/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*์ ํ์ดํผํ๋ผ๋ฏธํฐ๋ฅผ ์ฌํํ์์ต๋๋ค.
```python
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% |
#### ํต์ฌ ์ธ์ฌ์ดํธ
1. **SFT ํจ๊ณผ**: ํ์ต ์ 0.0% โ ์ต์ข
**56.3%** Action Match Rate, Format Accuracy **99.9%** ๋ฌ์ฑ
2. **์ต์ ์ฒดํฌํฌ์ธํธ**: 1K step(55.1%) โ 2.5K(54.1%) โ 5.9K(**56.3%**) โ ์ต์ข
๋ชจ๋ธ์ด ๊ฐ์ฅ ๋์ ์ฑ๋ฅ
3. **LFM2-1.2B-Tool ๋น๊ต**: 3.5๋ฐฐ ํฐ ๊ณต์ ๋ชจ๋ธ(0.0%)์ ์๋ โ ํ์ต ๋ฐ์ดํฐ ํ์ ์ ๋ ฌ์ ์ค์์ฑ
4. **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๋ฅผ ๊ตฌํํ์์ต๋๋ค:
```bash
# ๋จ์ผ ๋ผ์ด๋ ํ๊ฐ (๋น ๋ฅธ ํ
์คํธ)
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** ํ์์ ๋ํ ๋ฐ์ดํฐ๋ก ํ์ต๋์์ต๋๋ค.
```json
{
"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%** |
| ํ๋กฌํํธ ๊ธธ์ด | ์์ฒ ํ ํฐ | ์๋ฐฑ ํ ํฐ |
| ์ถ๋ก ์๋ | ๋๋ฆผ | **๋น ๋ฆ** |
```python
# 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.5~2์๊ฐ)
- **์ฑ๋ฅ**: ํจ๋ฉ ๊ฐ์๋ก gradient ์ถ์ ์ด ์์ ์ ์ด ๋์ด, ๋์ผํ๊ฑฐ๋ ์ฝ๊ฐ ๋์ ์ฑ๋ฅ ๊ธฐ๋
- **๊ฐํธํ ๋์**: TRL์ `packing=True` ์ต์
โ ์งง์ ์ํ์ค ์ฌ๋ฌ ๊ฐ๋ฅผ ํ๋์ ์ด์ด๋ถ์ฌ ํจ๋ฉ ๋ญ๋น๋ฅผ ์์จ ์ ์์
---
### ํ์ต ์ฌํ
#### ์ฌ์ ์ค๋น
1. **HuggingFace ํ ํฐ** (Write ๊ถํ) โ [๋ฐ๊ธ ๋งํฌ](https://huggingface.co/settings/tokens)
2. **GPU ํ๊ฒฝ** โ NVIDIA H100/A100 80GB ๊ถ์ฅ
#### ํ์ต ์คํ
```bash
# VESSL AI์์ ์คํ
vessl run create -f vessl_notebook.yaml
# โ Jupyter์์ notebooks/01_train_trl.ipynb ์
๋ก๋ ํ ์์๋๋ก ์คํ
```
#### ํ๊ฐ ์คํ
```bash
# VESSL AI ๊ฐ์ ์ธ์คํด์ค์์
# โ notebooks/03_evaluate.ipynb ์
๋ก๋ ํ ์์๋๋ก ์คํ
```
---
### ์ฐธ๊ณ ์๋ฃ
- ๐ **๋
ผ๋ฌธ**: [Small Language Models for Efficient Agentic Tool Calling](https://arxiv.org/html/2512.15943v1)
- ๐ค **Base Model**: [LiquidAI/LFM2-350M](https://huggingface.co/LiquidAI/LFM2-350M)
- ๐ **Dataset**: [gyung/toolbench-lfm-chatml](https://huggingface.co/datasets/gyung/toolbench-lfm-chatml)
- ๐ง **ToolBench**: [OpenBMB/ToolBench](https://github.com/OpenBMB/ToolBench)
- ๐ **Liquid AI Docs**: [Tool Use Guide](https://docs.liquid.ai/lfm/key-concepts/tool-use)
---
### Citation
```bibtex
@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}}
}
```
```bibtex
@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}
}
```
```bibtex
@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**
[](https://huggingface.co/LiquidAI/LFM2-350M)
[](https://huggingface.co/datasets/gyung/toolbench-lfm-chatml)
[](https://arxiv.org/html/2512.15943v1)
This model is a full SFT of [Liquid AI's LFM2-350M](https://huggingface.co/LiquidAI/LFM2-350M) on the [ToolBench dataset](https://github.com/OpenBMB/ToolBench) (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](https://arxiv.org/html/2512.15943v1)"* (arXiv:2512.15943v1) using the LFM2 architecture (LNN-based).
---
### Quick Start
```python
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](https://huggingface.co/LiquidAI/LFM2-350M) (LNN-based) |
| **Parameters** | 354M |
| **Training Data** | [gyung/toolbench-lfm-chatml](https://huggingface.co/datasets/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*.
```python
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
1. **SFT Effect**: Base 0.0% โ Final **56.3%** Action Match Rate, Format Accuracy **99.9%**
2. **Best checkpoint**: 1K(55.1%) โ 2.5K(54.1%) โ 5.9K(**56.3%**) โ final model achieves the highest score
3. **vs LFM2-1.2B-Tool**: Outperforms 3.5ร larger official model (0.0%) โ importance of training data format alignment
4. **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`:
```bash
# 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.
```json
{
"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** |
```python
# 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
1. **HuggingFace Token** (Write permission) โ [Get token](https://huggingface.co/settings/tokens)
2. **GPU Environment** โ NVIDIA H100/A100 80GB recommended
#### Training
```bash
# Run on VESSL AI
vessl run create -f vessl_notebook.yaml
# โ Upload notebooks/01_train_trl.ipynb in Jupyter and run cells sequentially
```
#### Evaluation
```bash
# 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](https://arxiv.org/html/2512.15943v1)
- ๐ค **Base Model**: [LiquidAI/LFM2-350M](https://huggingface.co/LiquidAI/LFM2-350M)
- ๐ **Dataset**: [gyung/toolbench-lfm-chatml](https://huggingface.co/datasets/gyung/toolbench-lfm-chatml)
- ๐ง **ToolBench**: [OpenBMB/ToolBench](https://github.com/OpenBMB/ToolBench)
- ๐ **Liquid AI Docs**: [Tool Use Guide](https://docs.liquid.ai/lfm/key-concepts/tool-use)
---
### Citation
```bibtex
@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}}
}
```
```bibtex
@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}
}
```
```bibtex
@article{liquidai2025lfm2,
title={LFM2 Technical Report},
author={Liquid AI},
journal={arXiv preprint arXiv:2511.23404},
year={2025}
}
```