File size: 6,554 Bytes
07a1f16
 
e1bb4f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
07a1f16
5566d01
 
8d6e523
5566d01
 
 
 
 
 
 
 
 
 
 
 
 
 
e1bb4f2
 
 
5566d01
e1bb4f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e258ef
e1bb4f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
license: apache-2.0
language:
- code
- en
library_name: transformers
pipeline_tag: text-generation
tags:
- code
- c
- llama
- causal-lm
- anveshai
- ritchie
- edge
- on-device
- mobile
model-index:
- name: AnveshAI-Ritchie-0.1B
  results: []
---
<div align="center">
  <picture>
    <img src="logo.png" width="50%" alt="AnveshAI Ritchie 0.1B">
  </picture>
</div>
<hr>
<div align="center" style="line-height: 1;">
  <a href="https://huggingface.co/AnveshAI" target="_blank"><img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-AnveshAI-ffc107?color=ffc107&logoColor=white"/></a>
  <a href="https://www.apache.org/licenses/LICENSE-2.0" target="_blank"><img alt="License" src="https://img.shields.io/badge/License-Apache%202.0-blue?logoColor=white"/></a>
</div>
<div align="center" style="line-height: 1;">
  <a herf="#"><img src="https://img.shields.io/badge/Parameters-100.7M-blue" alt="Parameters"></a>
  <img src="https://img.shields.io/badge/Architecture-LLaMA-green" alt="Architecture">
  <img src="https://img.shields.io/badge/Language-C-orange" alt="Language">
  <img src="https://img.shields.io/badge/Context-2048_tokens-purple" alt="Context Length">
  <img src="https://img.shields.io/badge/Precision-FP16-red" alt="Precision">
</div>

**Ritchie** is a compact 100.7M-parameter language model purpose-built for **C programming** β€” named after [Dennis Ritchie](https://en.wikipedia.org/wiki/Dennis_Ritchie), the creator of the C language. Built on the LLaMA architecture, Ritchie is designed to generate C code from natural language task descriptions.

**Small enough to run on any device β€” including edge devices like smartphones, tablets, Raspberry Pi, and other embedded hardware.** At just ~200MB (FP16), Ritchie brings C code generation to devices where larger models simply can't run. No GPU required β€” it runs comfortably on CPU.

---

## Highlights

- **100.7M parameters** β€” one of the smallest dedicated C code generation models available
- **~200MB model size** (FP16) β€” fits in memory on virtually any device
- **Runs on CPU** β€” no GPU required, works on laptops, phones, edge devices, and embedded systems
- **LLaMA architecture** β€” well-supported by HuggingFace Transformers, llama.cpp, ONNX, and other runtimes
- **Task-oriented special tokens** β€” structured prompting with `<|task|>`, `<|code|>`, `<|plan|>`, `<|bug|>`, `<|fix|>` tokens
- **2048 token context window**

---

## Model Details

| Property | Value |
|----------|-------|
| **Model Name** | AnveshAI Ritchie 0.1B |
| **Parameters** | 100.7M |
| **Architecture** | LlamaForCausalLM |
| **Hidden Size** | 768 |
| **Intermediate Size** | 2048 |
| **Layers** | 12 |
| **Attention Heads** | 12 |
| **KV Heads** | 4 (Grouped Query Attention) |
| **Vocab Size** | 32,768 |
| **Max Context** | 2,048 tokens |
| **Precision** | FP16 |
| **Activation** | SiLU |
| **Position Encoding** | RoPE (ΞΈ=10000) |
| **Tied Embeddings** | Yes |
| **Training Step** | 3,200 |
| **Eval Loss** | 1.383 |
| **Model Size on Disk** | ~192 MB |

---

## Quick Start

### Installation

```bash
pip install transformers torch
```

### Basic Usage

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "AnveshAI/AnveshAI-Ritchie-0.1B"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto",
)
model.eval()

prompt = "<|task|>Write a C function to compute the nth Fibonacci number<|code|>"

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
    output = model.generate(
        **inputs,
        max_new_tokens=256,
        do_sample=True,
        temperature=0.4,
        top_p=0.95,
        repetition_penalty=1.15,
        pad_token_id=tokenizer.pad_token_id,
    )

generated = output[0][inputs["input_ids"].shape[1]:]
print(tokenizer.decode(generated, skip_special_tokens=True))
```

---

## Special Tokens

Ritchie uses structured special tokens for different stages of the code generation pipeline:

| Token | Purpose | Description |
|-------|---------|-------------|
| `<\|bos\|>` | Beginning of sequence | Start of input |
| `<\|end\|>` | End of turn | End of generation |
| `<\|eos\|>` | End of sequence | End of full sequence |
| `<\|pad\|>` | Padding | Padding token |
| `<\|task\|>` | Task description | Precedes the natural language instruction |
| `<\|code\|>` | Code generation | Signals the model to start generating code |
| `<\|plan\|>` | Planning | For step-by-step planning before coding |
| `<\|run\|>` | Execution | Marks expected execution output |
| `<\|bug\|>` | Bug identification | Marks compiler errors or bugs |
| `<\|fix\|>` | Bug fix | Signals corrected code |

### Prompt Format

```
<|task|>Your natural language description here<|code|>
```

---

## Tips for Best Results

1. **Use `repetition_penalty=1.15`** β€” helps prevent repetitive output patterns
2. **Keep `max_new_tokens` at 256** β€” the model works best with shorter outputs
3. **Use `temperature=0.4`** β€” lower temperature produces more focused code
4. **Use the `<|task|>...<|code|>` format** β€” this is the prompt format the model was trained on
5. **Simple, direct prompts work best** β€” e.g., "Write a C function to swap two integers using pointers"

---

## Limitations

- **100M scale** β€” this is a small model; expect imperfect outputs on complex tasks
- **C language only** β€” not trained for other programming languages
- **May produce repetitive output** β€” use `repetition_penalty` to mitigate
- **Not instruction-tuned** β€” this is a base code generation model, not a chatbot
- **May not always follow the task** β€” task adherence is limited at this model scale

---

## Training Details

- **Base Architecture**: LLaMA (custom configuration)
- **Training Data**: C language source code corpus
- **Optimizer**: AdamW
- **Precision**: FP16 mixed precision
- **Best Checkpoint**: Step 3,200 (selected by lowest eval loss)
- **Hardware**: Kaggle GPU environment

---

## Citation

```bibtex
@misc{anveshai-ritchie-2026,
  title={AnveshAI Ritchie 0.1B},
  author={AnveshAI},
  year={2026},
  url={https://huggingface.co/AnveshAI/Ritchie-0.1B}
}
```

---

## License

This model is released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).

---

<p align="center">
  <b>Built by <a href="https://huggingface.co/AnveshAI">AnveshAI</a></b><br>
  <i>Named after Dennis Ritchie β€” the father of C</i>
</p>