seanpoyner commited on
Commit
31022c6
·
verified ·
1 Parent(s): 266e3e3

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
4
+ tags:
5
+ - code
6
+ - function-calling
7
+ - tool-use
8
+ - agent
9
+ - small-language-model
10
+ datasets:
11
+ - NousResearch/hermes-function-calling-v1
12
+ language:
13
+ - en
14
+ pipeline_tag: text-generation
15
+ ---
16
+
17
+ # smolcode-coder-1.5b-tools
18
+
19
+ A LoRA fine-tune of **Qwen2.5-Coder-1.5B-Instruct** that teaches the model to emit
20
+ **native `<tool_call>` function calls**, so a 1.5B *coder* model can actually drive an
21
+ agentic write → run → fix → verify loop.
22
+
23
+ Built for [**smolcode**](https://gitea.poyner.ai/sean/smolcode) — an SLM-optimized
24
+ agentic coding assistant — for the Hugging Face **Build Small** hackathon.
25
+
26
+ ## Why
27
+ Out of the box, small Qwen-Coder models describe tool calls as plain-text/```json
28
+ instead of emitting the native `<tool_call>` token (id 151657) that runtimes (Ollama,
29
+ llama.cpp) parse into OpenAI-style `tool_calls` — which breaks agentic loops. This
30
+ fine-tune closes that gap on a tiny (1.5B) model: **100% native `<tool_call>` emission**
31
+ in free generation on held-out prompts (base model: 0%).
32
+
33
+ ## Results
34
+ - **Native tool-call rate:** 100% (16/16 held-out prompts) — the release gate.
35
+ - **Agentic bench (smolcode pass@1, 10 tasks):** 9/10 as the entry tier of a
36
+ 1.5B→8B→30B ladder, solving **7/10 entirely on its own** (2–16s each). For
37
+ comparison the all-Granite ladder (3B entry) scores 10/10 — the 1.5B carries the
38
+ same standalone load as a 2×-larger 3B.
39
+ - **Train loss:** 0.138 (3 epochs, assistant-only loss).
40
+
41
+ ## Training
42
+ - **Base:** Qwen/Qwen2.5-Coder-1.5B-Instruct
43
+ - **Method:** bf16 LoRA (r=16, α=32) on attention + MLP projections, **plus full
44
+ training of `embed_tokens` + `lm_head`** (`modules_to_save`) — required so the model
45
+ can *output* the `<tool_call>` special token, which LoRA on attention/MLP alone
46
+ cannot. **Assistant-only loss** (loss on tool calls + final answers only).
47
+ - **Data:** NousResearch/hermes-function-calling-v1 (breadth) + synthetic smolcode
48
+ tool-use trajectories (sharpness), all rendered through the *same*
49
+ `apply_chat_template(tools=...)` used at inference — training target is byte-identical
50
+ to the served prompt (fixes the v1 train/inference template mismatch).
51
+ - **Schedule:** 3 epochs, full 2048 sequence length. Trained on Modal (A100).
52
+
53
+ ## Serving — read this, two non-obvious requirements
54
+ 1. **Serve via the GGUF, not the safetensors directly.** Ollama's bf16-safetensors
55
+ auto-import produces garbage (`??????`) for this model. Use the included
56
+ `smolcode-1.5b-q4_k_m.gguf` (converted with llama.cpp `convert_hf_to_gguf.py`):
57
+ ```bash
58
+ ollama create smolcode-coder-1.5b:tools -f Modelfile # Modelfile is in this repo
59
+ ```
60
+ 2. **`repeat_penalty` / `repetition_penalty` MUST be 1.0.** The tool system prompt
61
+ literally contains the `<tool_call>` token, so any penalty > 1 suppresses the model
62
+ from emitting it (you'll see a stray token + bare JSON instead). The included
63
+ `Modelfile` sets `PARAMETER repeat_penalty 1.0`. For raw `transformers.generate`,
64
+ pass `repetition_penalty=1.0`.
65
+
66
+ With those, Ollama's `/v1/chat/completions` returns proper native `tool_calls`.
67
+
68
+ ## Use (transformers)
69
+ Standard Qwen2.5 chat template with `tools=`; greedy, `repetition_penalty=1.0`. The
70
+ model responds with `<tool_call>{"name": ..., "arguments": ...}</tool_call>`.
71
+
72
+ ## Files
73
+ - `model.safetensors` + tokenizer/config — the merged model (lm_head untied).
74
+ - `smolcode-1.5b-q4_k_m.gguf` — quantized GGUF for serving.
75
+ - `Modelfile` — Ollama import recipe (template + `repeat_penalty 1.0`).
76
+
77
+ ## License
78
+ Apache-2.0 (inherits from the base model).
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 3584,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 18944,
13
+ "layer_types": [
14
+ "full_attention",
15
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention"
42
+ ],
43
+ "max_position_embeddings": 32768,
44
+ "max_window_layers": 28,
45
+ "model_type": "qwen2",
46
+ "num_attention_heads": 28,
47
+ "num_hidden_layers": 28,
48
+ "num_key_value_heads": 4,
49
+ "pad_token_id": null,
50
+ "rms_norm_eps": 1e-06,
51
+ "rope_parameters": {
52
+ "rope_theta": 1000000.0,
53
+ "rope_type": "default"
54
+ },
55
+ "sliding_window": null,
56
+ "tie_word_embeddings": false,
57
+ "transformers_version": "5.12.0",
58
+ "use_cache": true,
59
+ "use_sliding_window": false,
60
+ "vocab_size": 152064
61
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.1,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "5.12.0"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0c37b4f9684d919279ebb7647f43e3efdc71bb5710dba065186a53091515b84
3
+ size 15231272152
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 32768,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }