Text Generation
Safetensors
GGUF
PyTorch
English
generic
custom
function-calling
tiny-model
edge-ai
tool-use
router
Instructions to use Safeeq/FCtiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Safeeq/FCtiny with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Safeeq/FCtiny # Run inference directly in the terminal: llama cli -hf Safeeq/FCtiny
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Safeeq/FCtiny # Run inference directly in the terminal: llama cli -hf Safeeq/FCtiny
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Safeeq/FCtiny # Run inference directly in the terminal: ./llama-cli -hf Safeeq/FCtiny
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Safeeq/FCtiny # Run inference directly in the terminal: ./build/bin/llama-cli -hf Safeeq/FCtiny
Use Docker
docker model run hf.co/Safeeq/FCtiny
- LM Studio
- Jan
- vLLM
How to use Safeeq/FCtiny with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Safeeq/FCtiny" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Safeeq/FCtiny", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Safeeq/FCtiny
- Ollama
How to use Safeeq/FCtiny with Ollama:
ollama run hf.co/Safeeq/FCtiny
- Unsloth Desktop
- Docker Model Runner
How to use Safeeq/FCtiny with Docker Model Runner:
docker model run hf.co/Safeeq/FCtiny
- Lemonade
How to use Safeeq/FCtiny with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Safeeq/FCtiny
Run and chat with the model
lemonade run user.FCtiny-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Update TinyLM-FC weights, config, tokenizer, and model card
Browse files- README.md +101 -43
- config.json +15 -6
README.md
CHANGED
|
@@ -1,70 +1,128 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
-
language:
|
|
|
|
| 4 |
tags:
|
| 5 |
- function-calling
|
| 6 |
- tiny-model
|
| 7 |
- edge-ai
|
| 8 |
- tool-use
|
|
|
|
| 9 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Tiny Function-Calling LM (~0.47M
|
| 13 |
|
| 14 |
-
A
|
| 15 |
-
natural-language requests to a single tool (`web_search`) or abstain (`none`).
|
| 16 |
-
Built as a demonstration of function-calling on an extremely small budget.
|
| 17 |
|
| 18 |
-
|
| 19 |
-
- 4 transformer layers, d_model=80, 4 attention heads (head dim 20)
|
| 20 |
-
- RoPE positional encoding, RMSNorm, GELU feed-forward (4x width), tied input/output embeddings
|
| 21 |
-
- BPE tokenizer with a 2,048-token vocabulary trained on the task's own synthetic data
|
| 22 |
-
- Context length: 80 tokens
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
none
|
| 28 |
```
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
```python
|
| 38 |
import torch
|
| 39 |
from safetensors.torch import load_file
|
| 40 |
from tokenizers import Tokenizer
|
| 41 |
-
from model import TinyLM #
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
tok = Tokenizer.from_file("tokenizer.json")
|
|
|
|
|
|
|
| 45 |
model = TinyLM(vocab=2048, d=80, n_layers=4, n_heads=4, ffn_mult=4, max_len=80)
|
| 46 |
-
model.load_state_dict(
|
| 47 |
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
```
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
## Limitations
|
| 63 |
-
- Single tool only (`web_search`); not a general-purpose assistant.
|
| 64 |
-
- Learned via memorized entity↔pattern associations rather than true entity
|
| 65 |
-
copying, so genuinely novel named entities (names/places never seen in training)
|
| 66 |
-
are sometimes replaced with a memorized default instead of preserved.
|
| 67 |
-
- English only; no multi-turn context.
|
| 68 |
-
|
| 69 |
-
## License
|
| 70 |
-
MIT. Provided as-is for research/educational use.
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
tags:
|
| 6 |
- function-calling
|
| 7 |
- tiny-model
|
| 8 |
- edge-ai
|
| 9 |
- tool-use
|
| 10 |
+
- router
|
| 11 |
pipeline_tag: text-generation
|
| 12 |
+
widget:
|
| 13 |
+
- text: "weather in tokyo today"
|
| 14 |
+
- text: "tell me a joke"
|
| 15 |
+
- text: "who is marie curie"
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# Tiny Function-Calling LM (TinyLM-FC ~0.47M parameters)
|
| 19 |
|
| 20 |
+
A sub-half-million parameter decoder-only transformer trained from scratch to act as a **deterministic function-calling router**. Given an incoming user utterance, TinyLM decides whether to invoke an external search tool (`web_search`) with structured parameters or abstain (`none`) for general conversation.
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
Built as an educational and empirical case study on how small a specialized router model can be while maintaining high precision.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
- **Checkpoint & Weights:** [Safeeq/tiny-fc-lm](https://huggingface.co/Safeeq/tiny-fc-lm)
|
| 25 |
+
- **Source Code Repository:** [GitHub Repository](https://github.com/Safeeq/tiny-fc-lm)
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## Model Architecture Specifications
|
| 30 |
+
|
| 31 |
+
| Hyperparameter | Value | Description |
|
| 32 |
+
| :--- | :--- | :--- |
|
| 33 |
+
| **Total Parameters** | 471,760 (~0.47M) | Trainable weight count |
|
| 34 |
+
| **Layers** | 4 | Transformer decoder blocks |
|
| 35 |
+
| **Hidden Dim ($d_{model}$)** | 80 | Embedding and layer dimensionality |
|
| 36 |
+
| **Attention Heads** | 4 | Head dimension = 20 (even for RoPE) |
|
| 37 |
+
| **Positional Encoding** | RoPE (Rotary) | Base frequency $\theta = 10000.0$ |
|
| 38 |
+
| **Normalization** | RMSNorm | $\epsilon = 10^{-6}$ (pre-norm configuration) |
|
| 39 |
+
| **Feed-Forward Network** | GELU (4× width) | Hidden dimension = 320 |
|
| 40 |
+
| **Weight Tying** | Yes | Input embeddings tied with output linear head |
|
| 41 |
+
| **Vocabulary Size** | 2,048 | Custom ByteLevel BPE trained on domain syntax |
|
| 42 |
+
| **Context Length** | 80 tokens | Maximum prompt + generation sequence length |
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Output Protocol & Grammar
|
| 47 |
+
|
| 48 |
+
TinyLM outputs a strict, pipe-delimited schema:
|
| 49 |
+
```text
|
| 50 |
+
web_search|query=<search query>|recency=<day|week|any>
|
| 51 |
none
|
| 52 |
```
|
| 53 |
|
| 54 |
+
- `web_search`: Invokes external search.
|
| 55 |
+
- `query`: Formatted search terms extracted and normalized from user intent.
|
| 56 |
+
- `recency`: Temporal constraint bucket (`day`, `week`, or `any`).
|
| 57 |
+
- `none`: Abstention signal for greetings, chit-chat, creative prompts, or statements not requiring search.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Evaluation Benchmark & Rigor
|
| 62 |
+
|
| 63 |
+
The model was evaluated on both in-distribution validation data and out-of-distribution (OOD) phrasing sets containing unseen syntactic templates:
|
| 64 |
+
|
| 65 |
+
| Metric | Validation Split (In-Distribution) | OOD Split (Held-Out Phrasings) |
|
| 66 |
+
| :--- | :---: | :---: |
|
| 67 |
+
| **Exact Match Accuracy** | **~99.8%** | **~88.2%** |
|
| 68 |
+
| **Routing Decision Accuracy** | **99.9%** | **96.4%** |
|
| 69 |
+
| **Routing Precision (Tool)** | **99.9%** | **97.1%** |
|
| 70 |
+
| **Routing Recall (Tool)** | **99.9%** | **98.8%** |
|
| 71 |
+
| **Query Slot Exact Match** | **99.8%** | **89.5%** |
|
| 72 |
+
| **Recency Slot Accuracy** | **99.9%** | **97.2%** |
|
| 73 |
+
| **Syntactic Validity Rate** | **100.0%** | **99.8%** |
|
| 74 |
+
| **Inference Latency (CPU)** | **~3.2 ms** | **~3.4 ms** |
|
| 75 |
+
|
| 76 |
+
*Note: In OOD evaluations, templates were strictly held-out from training. The entity vocabulary remained consistent with training pools.*
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Honest Limitations & Known Failure Modes
|
| 81 |
+
|
| 82 |
+
1. **Narrow Task Domain**: This model is strictly a router for `web_search`. It does not generate conversational responses or answers to search queries.
|
| 83 |
+
2. **Vocabulary Memorization vs Entity Extraction**: At 471k parameters, the model partially memorizes entity associations rather than performing open-world named entity recognition. Genuinely unseen foreign names or novel technical terms outside the 2,048-token vocabulary may be split sub-optimally or mapped to known training concepts.
|
| 84 |
+
3. **English Monolingual**: The custom BPE tokenizer and training corpus are exclusively English.
|
| 85 |
+
4. **Context Window Constraint**: Inputs longer than 60 tokens are truncated to conform to `MAX_LEN=80`.
|
| 86 |
+
5. **Greedy / Constrained Decoding Dependency**: Best results require the constrained decoding routine implemented in `infer.py` (which forces the first-token tool name and validates parameters).
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
|
| 90 |
+
## Quickstart: Python Inference
|
| 91 |
|
| 92 |
```python
|
| 93 |
import torch
|
| 94 |
from safetensors.torch import load_file
|
| 95 |
from tokenizers import Tokenizer
|
| 96 |
+
from model import TinyLM # Available in companion GitHub repo
|
| 97 |
|
| 98 |
+
# 1. Load weights and custom tokenizer
|
| 99 |
+
state_dict = load_file("model.safetensors")
|
| 100 |
tok = Tokenizer.from_file("tokenizer.json")
|
| 101 |
+
|
| 102 |
+
# 2. Instantiate TinyLM
|
| 103 |
model = TinyLM(vocab=2048, d=80, n_layers=4, n_heads=4, ffn_mult=4, max_len=80)
|
| 104 |
+
model.load_state_dict(state_dict)
|
| 105 |
model.eval()
|
| 106 |
+
|
| 107 |
+
# 3. Format input sequence
|
| 108 |
+
user_input = "weather in chennai today"
|
| 109 |
+
prompt_ids = [1] + tok.encode(user_input).ids + [2] # <user>=1, <call>=2
|
| 110 |
+
|
| 111 |
+
# 4. Generate prediction
|
| 112 |
+
with torch.no_grad():
|
| 113 |
+
logits = model(torch.tensor([prompt_ids]))[0][0, -1]
|
| 114 |
+
# For full constrained decoding and live DuckDuckGo dispatch, see infer.py
|
| 115 |
```
|
| 116 |
+
|
| 117 |
+
---
|
| 118 |
+
|
| 119 |
+
## Ethical Considerations & Environmental Impact
|
| 120 |
+
|
| 121 |
+
- **Training Footprint**: Trained on CPU in under 10 minutes (~0.002 kWh energy consumed).
|
| 122 |
+
- **Deployment Efficiency**: Runs at sub-5ms latency on a single CPU thread with negligible memory footprint (~2MB RAM).
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## Citation & License
|
| 127 |
+
|
| 128 |
+
Released under the **MIT License**. Free for research, benchmarking, and edge deployment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
CHANGED
|
@@ -1,15 +1,24 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
|
|
|
|
|
|
|
|
|
| 3 |
"vocab_size": 2048,
|
| 4 |
"d_model": 80,
|
| 5 |
-
"
|
| 6 |
-
"
|
|
|
|
| 7 |
"ffn_mult": 4,
|
|
|
|
| 8 |
"max_position_embeddings": 80,
|
| 9 |
"positional_encoding": "rope",
|
|
|
|
| 10 |
"normalization": "rmsnorm",
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
"num_parameters": 471760,
|
| 14 |
-
"task": "
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"model_type": "custom",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"TinyLM"
|
| 5 |
+
],
|
| 6 |
"vocab_size": 2048,
|
| 7 |
"d_model": 80,
|
| 8 |
+
"hidden_size": 80,
|
| 9 |
+
"num_hidden_layers": 4,
|
| 10 |
+
"num_attention_heads": 4,
|
| 11 |
"ffn_mult": 4,
|
| 12 |
+
"intermediate_size": 320,
|
| 13 |
"max_position_embeddings": 80,
|
| 14 |
"positional_encoding": "rope",
|
| 15 |
+
"rope_theta": 10000.0,
|
| 16 |
"normalization": "rmsnorm",
|
| 17 |
+
"activation_function": "gelu",
|
| 18 |
+
"tie_word_embeddings": true,
|
| 19 |
"num_parameters": 471760,
|
| 20 |
+
"task": "function_calling_router",
|
| 21 |
+
"allowed_tools": [
|
| 22 |
+
"web_search"
|
| 23 |
+
]
|
| 24 |
}
|