File size: 4,695 Bytes
4cc2d93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3f6119
4cc2d93
d3f6119
4cc2d93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
language:
- en
license: apache-2.0
tags:
- llm
- tool-calling
- lightweight
- agentic-tasks
- react
- mlx
model-index:
- name: NanoAgent
  results: []
datasets:
- microsoft/orca-agentinstruct-1M-v1
- microsoft/orca-math-word-problems-200k
- allenai/tulu-3-sft-personas-instruction-following
- xingyaoww/code-act
- m-a-p/Code-Feedback
- weijie210/gsm8k_decomposed
- Locutusque/function-calling-chatml
- HuggingFaceTB/smoltalk
base_model:
- HuggingFaceTB/SmolLM2-135M-Instruct
pipeline_tag: text-generation
---
# POC

# FORKED FROM
# 🧠 NanoAgent β€” 135M Parameter Agentic LLM

NanoAgent is a compact 135M parameter, 8k context-length language model trained to **perform tool calls** and **generate responses based on tool outputs**.  
Despite its small size (~135 MB in 8-bit precision), it’s optimized for agentic use cases and runs easily on personal devices.

**Github:** [NanoAgent](https://github.com/QuwsarOhi/NanoAgent)

**Inference resource:** [link](https://github.com/QuwsarOhi/NanoAgent/blob/main/notebooks/inference.ipynb)

---

## ✨ Features

- 🧰 **Tool Calling** β€” understands and responds with structured outputs from tool calls.  
- 🧭 **Instruction Following** β€” strong instruction following abilities.  
- 🧠 **Basic Reasoning** β€” handles lightweight reasoning and ReAct-style interactions.  
- ⚑ **Lightweight** β€” runs on local hardware with minimal resources.

---

## πŸ§ͺ Training Overview

**Base model:** [`SmolLM2-135M-Instruct`](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct)  
**Fine-tuning method:** [Dynamic Fine-Tuning (DFT)](https://github.com/yongliang-wu/DFT/tree/master)  
**Hardware:** Apple Mac M1 (16 GB Unified Memory) using MLX.

### πŸ“š Datasets Used
- `microsoft/orca-agentinstruct-1M-v1` β€” agentic tasks, RAG answers, classification  
- `microsoft/orca-math-word-problems-200k` β€” lightweight reasoning  
- `allenai/tulu-3-sft-personas-instruction-following` β€” instruction following  
- `xingyaoww/code-act` β€” ReAct style reasoning and action  
- `m-a-p/Code-Feedback` β€” alignment via feedback  
- `HuggingFaceTB/smoltalk` + `/apigen` β€” tool calling stabilization  
- `weijie210/gsm8k_decomposed` β€” question decomposition  
- `Locutusque/function-calling-chatml` β€” tool call response structure

---

## ⚠️ Disclaimer

This is a **beta model**.  
- It may produce **incorrect** or **incomplete** outputs.  
- Tool call execution is **basic** and can fail in some cases.  
- Intended for **research and experimentation** only β€” not production use.

---

## 🧭 Roadmap

- βœ… Initial release with DFT fine-tuning  
- πŸ§ͺ Benchmarking on agentic tasks  
- ~~πŸ”¬ Experimenting with GRPO for tool calling (failed)~~
- 🧠 Weight merging experiments for improved performance
- Add more tool calling dataset

---

## πŸ“₯ Model Size

- 135M parameters  
- ~135 MB in 8-bit precision  
- 8k context length

---

## ⚑ Example Usage

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "quwsarohi/NanoAgent-135M"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def inference(messages, max_new_tokens=256, temperature=0.3, min_p=0.15, **kwargs):
    input_text = tokenizer.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True
    )
    inputs = tokenizer.encode(input_text, return_tensors="pt")
    outputs = model.generate(
        inputs,
        max_new_tokens=max_new_tokens,
        do_sample=True,
        min_p=0.15,
        temperature=temperature,
        **kwargs
    )
    return tokenizer.decode(outputs[0][inputs.shape[1] :], skip_special_tokens=True)

messages = [{"role": "user", "content": "Hi! Do you have a name?"}]
print(inference(messages))
```

Use the following template for tool calling:
```python
TOOL_TEMPLATE = """You are a helpful AI assistant. You have a set of possible functions/tools inside <tools></tools> tags. 
Based on question, you may need to make one or more function/tool calls to answer user.

You have access to the following tools/functions:
<tools>{tools}</tools>

For each function call, return a JSON list object with function name and arguments within <tool_call></tool_call> tags."""
```

Sample tool call definition:
```json
{
  "name": "web_search",
  "description": "Performs a web search for a query and returns a string of the top search results formatted as markdown with titles, links, and descriptions.",
  "parameters": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "The search query to perform.",
      }
    },
    "required": ["query"],
  },
}
```