quwsarohi commited on
Commit
6b58bfb
·
verified ·
1 Parent(s): a7b481b

Merged model

Browse files
Files changed (6) hide show
  1. README.md +30 -145
  2. chat_template.jinja +1 -1
  3. config.json +37 -36
  4. special_tokens_map.json +29 -20
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +4 -20
README.md CHANGED
@@ -1,160 +1,45 @@
1
  ---
2
- language:
3
- - en
4
- license: apache-2.0
5
- tags:
6
- - llm
7
- - tool-calling
8
- - lightweight
9
- - agentic-tasks
10
- - react
11
- - mlx
12
- - dft
13
- model-index:
14
- - name: NanoAgent
15
- results: []
16
- datasets:
17
- - microsoft/orca-agentinstruct-1M-v1
18
- - microsoft/orca-math-word-problems-200k
19
- - allenai/tulu-3-sft-personas-instruction-following
20
- - xingyaoww/code-act
21
- - m-a-p/Code-Feedback
22
- - weijie210/gsm8k_decomposed
23
- - Locutusque/function-calling-chatml
24
- - HuggingFaceTB/smoltalk
25
  base_model:
26
  - HuggingFaceTB/SmolLM2-135M-Instruct
27
- pipeline_tag: text-generation
28
- ---
29
-
30
- # 🧠 NanoAgent — 135M Parameter Agentic LLM
31
-
32
- NanoAgent is a compact 135M parameter, 8k context-length language model trained to **perform tool calls** and **generate responses based on tool outputs**.
33
- Despite its small size (~135 MB in 8-bit precision), it’s optimized for agentic use cases and runs easily on personal devices.
34
-
35
- ---
36
-
37
- ## ✨ Features
38
-
39
- - 🧰 **Tool Calling** — understands and responds with structured outputs from tool calls.
40
- - 🧭 **Instruction Following** — strong instruction following abilities.
41
- - 🧠 **Basic Reasoning** — handles lightweight reasoning and ReAct-style interactions.
42
- - ⚡ **Lightweight** — runs on local hardware with minimal resources.
43
-
44
- ---
45
-
46
- ## 🧪 Training Overview
47
-
48
- **Base model:** [`SmolLM2-135M-Instruct`](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct)
49
- **Fine-tuning method:** [Dynamic Fine-Tuning (DFT)](https://github.com/yongliang-wu/DFT/tree/master)
50
- **Hardware:** Apple Mac M1 (16 GB Unified Memory) using MLX.
51
-
52
- ### 📚 Datasets Used
53
- - `microsoft/orca-agentinstruct-1M-v1` — agentic tasks, RAG answers, classification
54
- - `microsoft/orca-math-word-problems-200k` — lightweight reasoning
55
- - `allenai/tulu-3-sft-personas-instruction-following` — instruction following
56
- - `xingyaoww/code-act` — ReAct style reasoning and action
57
- - `m-a-p/Code-Feedback` — alignment via feedback
58
- - `HuggingFaceTB/smoltalk` + `/apigen` — tool calling stabilization
59
- - `weijie210/gsm8k_decomposed` — question decomposition
60
- - `Locutusque/function-calling-chatml` — tool call response structure
61
-
62
- ---
63
-
64
- ## ⚠️ Disclaimer
65
-
66
- This is a **beta model**.
67
- - It may produce **incorrect** or **incomplete** outputs.
68
- - Tool call execution is **basic** and can fail in some cases.
69
- - Intended for **research and experimentation** only — not production use.
70
-
71
- ---
72
-
73
- ## 🧭 Roadmap
74
-
75
- - ✅ Initial release with DFT fine-tuning
76
- - 🧪 Benchmarking on agentic tasks
77
- - ~~🔬 Experimenting with GRPO for tool calling (failed)~~
78
- - 🧠 Weight merging experiments for improved performance
79
- - Add more tool calling dataset
80
-
81
- ---
82
-
83
- ## 📥 Model Size
84
-
85
- - 135M parameters
86
- - ~135 MB in 8-bit precision
87
- - 8k context length
88
 
89
  ---
 
90
 
91
- ## 🧪 Benchmarks
92
-
93
- Benchmarks are conducted with `temperature=0` and without sampling for fair evaluation using [llm_eval](https://github.com/EleutherAI/lm-evaluation-harness).
94
-
95
- | Metric / Task | SmolLM2-135M-Instruct | NanoAgent |
96
- | ----------------------------- | ---------------------------- | -------------------------------------------- |
97
- | **Parameters** | 135M | 135M |
98
- | **Context Length** | 8k | 8k |
99
- | **IFEval Score (Overall)** | 5.69 | **9.46** |
100
- | **MMLU** | 22.96 | **23.07** |
101
- | **Commonsense QA** | **19.66** | 19.57 |
102
 
103
- ---
104
-
105
- ## ⚡ Example Usage
106
 
107
- ```python
108
- from transformers import AutoModelForCausalLM, AutoTokenizer
109
 
110
- model_name = "quwsarohi/NanoAgent-135M"
111
- tokenizer = AutoTokenizer.from_pretrained(model_name)
112
- model = AutoModelForCausalLM.from_pretrained(model_name)
113
 
114
- def inference(messages, max_new_tokens=256, temperature=0.3, min_p=0.15, **kwargs):
115
- input_text = tokenizer.apply_chat_template(
116
- messages, tokenize=False, add_generation_prompt=True
117
- )
118
- inputs = tokenizer.encode(input_text, return_tensors="pt")
119
- outputs = model.generate(
120
- inputs,
121
- max_new_tokens=max_new_tokens,
122
- do_sample=True,
123
- min_p=0.15,
124
- temperature=temperature,
125
- **kwargs
126
- )
127
- return tokenizer.decode(outputs[0][inputs.shape[1] :], skip_special_tokens=True)
128
 
129
- messages = [{"role": "user", "content": "Hi! Do you have a name?"}]
130
- print(inference(messages))
131
- ```
132
 
133
- Use the following template for tool calling:
134
- ```python
135
- TOOL_TEMPLATE = """You are a helpful AI assistant. You have a set of possible functions/tools inside <tools></tools> tags.
136
- Based on question, you may need to make one or more function/tool calls to answer user.
137
 
138
- You have access to the following tools/functions:
139
- <tools>{tools}</tools>
 
 
 
 
 
 
 
 
 
140
 
141
- For each function call, return a JSON list object with function name and arguments within <tool_call></tool_call> tags."""
 
142
  ```
143
-
144
- Sample tool call definition:
145
- ```json
146
- {
147
- "name": "web_search",
148
- "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.",
149
- "parameters": {
150
- "type": "object",
151
- "properties": {
152
- "query": {
153
- "type": "string",
154
- "description": "The search query to perform.",
155
- }
156
- },
157
- "required": ["query"],
158
- },
159
- }
160
- ```
 
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  base_model:
3
  - HuggingFaceTB/SmolLM2-135M-Instruct
4
+ - quwsarohi/NanoAgent-135M
5
+ library_name: transformers
6
+ tags:
7
+ - mergekit
8
+ - merge
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  ---
11
+ # test_model
12
 
13
+ This is a merge of pre-trained language models created using [mergekit](https://github.com/cg123/mergekit).
 
 
 
 
 
 
 
 
 
 
14
 
15
+ ## Merge Details
16
+ ### Merge Method
 
17
 
18
+ This model was merged using the [Linear](https://arxiv.org/abs/2203.05482) merge method.
 
19
 
20
+ ### Models Merged
 
 
21
 
22
+ The following models were included in the merge:
23
+ * [HuggingFaceTB/SmolLM2-135M-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct)
24
+ * [quwsarohi/NanoAgent-135M](https://huggingface.co/quwsarohi/NanoAgent-135M)
25
+ * /Users/ohi/Documents/GitHub/EdgeAgent/weights/SmolLM2-135M-mlx-csft-v12-tc
 
 
 
 
 
 
 
 
 
 
26
 
27
+ ### Configuration
 
 
28
 
29
+ The following YAML configuration was used to produce this model:
 
 
 
30
 
31
+ ```yaml
32
+ models:
33
+ - model: quwsarohi/NanoAgent-135M
34
+ parameters:
35
+ weight: 0.7
36
+ - model: HuggingFaceTB/SmolLM2-135M-Instruct
37
+ parameters:
38
+ weight: 0.15
39
+ - model: /Users/ohi/Documents/GitHub/EdgeAgent/weights/SmolLM2-135M-mlx-csft-v12-tc
40
+ parameters:
41
+ weight: 0.15
42
 
43
+ merge_method: linear
44
+ dtype: bfloat16
45
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
chat_template.jinja CHANGED
@@ -1,7 +1,7 @@
1
  {% for message in messages %}
2
  {% if loop.first and messages[0]['role'] != 'system' %}
3
  {{ '<|im_start|>system
4
- You are a helpful AI assistant. Always provide concise answers.<|im_end|>' }}
5
  {% endif %}
6
  {{'<|im_start|>' + message['role'] + '
7
  ' + message['content'] + '<|im_end|>'}}
 
1
  {% for message in messages %}
2
  {% if loop.first and messages[0]['role'] != 'system' %}
3
  {{ '<|im_start|>system
4
+ You are a helpful AI assistant. <|im_end|>' }}
5
  {% endif %}
6
  {{'<|im_start|>' + message['role'] + '
7
  ' + message['content'] + '<|im_end|>'}}
config.json CHANGED
@@ -1,37 +1,38 @@
1
  {
2
- "architectures": [
3
- "LlamaForCausalLM"
4
- ],
5
- "attention_bias": false,
6
- "attention_dropout": 0.0,
7
- "bos_token_id": 1,
8
- "eos_token_id": 2,
9
- "hidden_act": "silu",
10
- "hidden_size": 576,
11
- "initializer_range": 0.041666666666666664,
12
- "intermediate_size": 1536,
13
- "is_llama_config": true,
14
- "max_position_embeddings": 8192,
15
- "mlp_bias": false,
16
- "model_type": "llama",
17
- "num_attention_heads": 9,
18
- "num_hidden_layers": 30,
19
- "num_key_value_heads": 3,
20
- "pad_token_id": 2,
21
- "pretraining_tp": 1,
22
- "rms_norm_eps": 1e-05,
23
- "rope_interleaved": false,
24
- "rope_scaling": null,
25
- "rope_theta": 100000,
26
- "tie_word_embeddings": true,
27
- "torch_dtype": "bfloat16",
28
- "transformers.js_config": {
29
- "kv_cache_dtype": {
30
- "q4f16": "float16",
31
- "fp16": "float16"
32
- }
33
- },
34
- "transformers_version": "4.42.3",
35
- "use_cache": true,
36
- "vocab_size": 49152
37
- }
 
 
1
  {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 2,
9
+ "head_dim": 64,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 576,
12
+ "initializer_range": 0.041666666666666664,
13
+ "intermediate_size": 1536,
14
+ "is_llama_config": true,
15
+ "max_position_embeddings": 8192,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 9,
19
+ "num_hidden_layers": 30,
20
+ "num_key_value_heads": 3,
21
+ "pad_token_id": 2,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-05,
24
+ "rope_interleaved": false,
25
+ "rope_scaling": null,
26
+ "rope_theta": 100000,
27
+ "tie_word_embeddings": true,
28
+ "torch_dtype": "bfloat16",
29
+ "transformers.js_config": {
30
+ "kv_cache_dtype": {
31
+ "fp16": "float16",
32
+ "q4f16": "float16"
33
+ }
34
+ },
35
+ "transformers_version": "4.55.4",
36
+ "use_cache": true,
37
+ "vocab_size": 49152
38
+ }
special_tokens_map.json CHANGED
@@ -1,25 +1,34 @@
1
  {
2
  "additional_special_tokens": [
3
- "<|endoftext|>",
4
  "<|im_start|>",
5
- "<|im_end|>",
6
- "<repo_name>",
7
- "<reponame>",
8
- "<file_sep>",
9
- "<filename>",
10
- "<gh_stars>",
11
- "<issue_start>",
12
- "<issue_comment>",
13
- "<issue_closed>",
14
- "<jupyter_start>",
15
- "<jupyter_text>",
16
- "<jupyter_code>",
17
- "<jupyter_output>",
18
- "<jupyter_script>",
19
- "<empty_output>"
20
  ],
21
- "bos_token": "<empty_output>",
22
- "eos_token": "<|im_end|>",
23
- "pad_token": "<|endoftext|>",
24
- "unk_token": "<|endoftext|>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
 
1
  {
2
  "additional_special_tokens": [
 
3
  "<|im_start|>",
4
+ "<|im_end|>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ],
6
+ "bos_token": {
7
+ "content": "<|im_start|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "eos_token": {
14
+ "content": "<|im_end|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "pad_token": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false
26
+ },
27
+ "unk_token": {
28
+ "content": "<|endoftext|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
  }
tokenizer.json CHANGED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json CHANGED
@@ -1,5 +1,4 @@
1
  {
2
- "add_bos_token": false,
3
  "add_prefix_space": false,
4
  "added_tokens_decoder": {
5
  "0": {
@@ -140,30 +139,15 @@
140
  }
141
  },
142
  "additional_special_tokens": [
143
- "<|endoftext|>",
144
  "<|im_start|>",
145
- "<|im_end|>",
146
- "<repo_name>",
147
- "<reponame>",
148
- "<file_sep>",
149
- "<filename>",
150
- "<gh_stars>",
151
- "<issue_start>",
152
- "<issue_comment>",
153
- "<issue_closed>",
154
- "<jupyter_start>",
155
- "<jupyter_text>",
156
- "<jupyter_code>",
157
- "<jupyter_output>",
158
- "<jupyter_script>",
159
- "<empty_output>"
160
  ],
161
- "bos_token": "<empty_output>",
 
162
  "clean_up_tokenization_spaces": false,
163
  "eos_token": "<|im_end|>",
164
- "extra_special_tokens": {},
165
  "model_max_length": 8192,
166
- "pad_token": "<|endoftext|>",
167
  "tokenizer_class": "GPT2Tokenizer",
168
  "unk_token": "<|endoftext|>",
169
  "vocab_size": 49152
 
1
  {
 
2
  "add_prefix_space": false,
3
  "added_tokens_decoder": {
4
  "0": {
 
139
  }
140
  },
141
  "additional_special_tokens": [
 
142
  "<|im_start|>",
143
+ "<|im_end|>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  ],
145
+ "bos_token": "<|im_start|>",
146
+ "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful AI assistant named SmolLM, trained by Hugging Face<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
147
  "clean_up_tokenization_spaces": false,
148
  "eos_token": "<|im_end|>",
 
149
  "model_max_length": 8192,
150
+ "pad_token": "<|im_end|>",
151
  "tokenizer_class": "GPT2Tokenizer",
152
  "unk_token": "<|endoftext|>",
153
  "vocab_size": 49152