File size: 8,549 Bytes
e0ec8ee
 
 
a7fc280
e0ec8ee
a7fc280
 
 
 
 
 
 
e0ec8ee
 
 
a7fc280
e0ec8ee
a7fc280
 
e0ec8ee
 
 
 
47e99e0
 
 
e0ec8ee
 
 
47e99e0
 
 
 
 
 
 
 
 
e0ec8ee
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
e0ec8ee
 
 
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
e0ec8ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47e99e0
 
 
e0ec8ee
 
 
 
 
 
 
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
e0ec8ee
 
 
 
 
 
47e99e0
e0ec8ee
 
 
47e99e0
e0ec8ee
47e99e0
e0ec8ee
47e99e0
 
 
 
 
 
 
e0ec8ee
47e99e0
e0ec8ee
 
 
47e99e0
 
 
 
 
 
e0ec8ee
 
 
 
47e99e0
e0ec8ee
47e99e0
e0ec8ee
 
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0ec8ee
 
 
 
 
e6b9ffd
e0ec8ee
47e99e0
 
 
e0ec8ee
47e99e0
e0ec8ee
47e99e0
 
e0ec8ee
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6b9ffd
47e99e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e0ec8ee
 
 
47e99e0
 
 
 
 
 
e0ec8ee
 
 
b117e73
e0ec8ee
47e99e0
b117e73
e0ec8ee
 
 
47e99e0
 
 
 
 
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
---
license: apache-2.0
language:
- en
tags:
- code
- programming
- mathematics
- reasoning
- text-generation
- conversational
- qwen2
pipeline_tag: text-generation
library_name: transformers
datasets:
- uaytug/UCDS
model-index:
- name: ucoder-mini
  results: []
---

# uCoder Mini

> **Important:** The model is unable to produce accurate and high-quality answers to general knowledge, creative writing, or non-coding tasks, and to questions asked in languages other than English. The answers to your questions in these areas may not be satisfactory because this model was specifically trained for **coding and mathematical reasoning tasks** (competitive programming, LeetCode, algorithm problems, etc.).

![Parameters](https://img.shields.io/badge/Parameters-1.5B-blue) ![Architecture](https://img.shields.io/badge/Architecture-Qwen2-purple) ![Context](https://img.shields.io/badge/Context-4096-green) ![Precision](https://img.shields.io/badge/Precision-bfloat16-red) ![License](https://img.shields.io/badge/License-Apache%202.0-orange)

## Overview

**uCoder Mini** is a 1.5B parameter dense language model fine-tuned specifically for code generation and mathematical reasoning. Built on the Qwen2 architecture, this model demonstrates that small, focused models can achieve strong performance on programming tasks when trained on high-quality, curated data.

### Key Features

- **Specialized Focus**: Trained exclusively on coding and math data for maximum performance in these domains
- **Efficient Size**: 1.5B parameters — runs on consumer GPUs, fast inference
- **Extended Context**: Supports up to 4096 tokens for longer code generation
- **Multi-Language**: Handles Python, JavaScript, C++, Java, and more
- **Competitive Programming**: Strong on algorithmic problems (LeetCode, Codeforces-style)

## Model Details

| Attribute | Value |
|-----------|-------|
| **Architecture** | Qwen2 (Dense Transformer) |
| **Parameters** | ~1.5B |
| **Hidden Size** | 1536 |
| **Layers** | 28 |
| **Attention Heads** | 12 |
| **Context Length** | 4096 tokens |
| **Vocabulary Size** | 151,936 |
| **Training Precision** | bfloat16 |
| **Training Method** | Supervised Fine-Tuning (SFT) |

## Intended Use

**Recommended for:**
- Competitive programming (LeetCode, Codeforces, HackerRank)
- Algorithm implementation and optimization
- Mathematical problem solving with code
- Code debugging and explanation
- Learning programming concepts

**Not recommended for:**
- General conversation or chat
- Creative writing or storytelling
- Factual Q&A or knowledge retrieval
- Non-English tasks
- Production systems without human review

## Quick Start

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "uaytug/ucoder-mini"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype="auto",
    device_map="auto"
)

messages = [
    {"role": "user", "content": "Write a Python function to find the longest palindromic substring."}
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

outputs = model.generate(
    **inputs,
    max_new_tokens=1024,
    temperature=0.6,
    top_p=0.95,
    do_sample=True
)

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

### Recommended Generation Parameters

For best results on coding tasks:

```python
generation_config = {
    "max_new_tokens": 2048,
    "temperature": 0.6,      # Use 0.6 for focused output, 1.0 for more exploration
    "top_p": 0.95,
    "do_sample": True,
}
```

## Chat Template

uCoder Mini uses the ChatML format:

```
<|im_start|>user
Your coding question here<|im_end|>
<|im_start|>assistant
```

## Training Data

Trained on [UCDS (uCoder Dataset)](https://huggingface.co/datasets/uaytug/UCDS) — a curated collection of 420K+ high-quality samples:

| Source | Samples | Description |
|--------|---------|-------------|
| Codeforces | 47K+ | Competitive programming with solutions |
| Code-Contests-Plus | 10K+ | Algorithm challenges |
| CodeAlpaca | 15K+ | Instruction-following code |
| OpenMathInstruct | Various | Mathematical reasoning chains |
| Curated Sources | Various | Tool use, chain-of-thought, deduplication |

**Total**: 420,686 deduplicated samples covering Python, JavaScript, C++, Java, and more.

## Limitations

- **Domain-Specific**: This model is trained only on code/math — it will perform poorly on general tasks
- **English Only**: Best performance in English; other languages not supported
- **Knowledge Cutoff**: May not know about recent libraries, frameworks, or API changes
- **No Verification**: Always test generated code before use in production
- **Context Limit**: 4096 tokens may not be enough for very large codebases
- **No Web Access**: Cannot fetch documentation or search for solutions

## Example Outputs

<details>
<summary><b>Algorithm Problem</b></summary>

**Prompt:** Implement a function to find the kth largest element in an unsorted array.

```python
import heapq

def find_kth_largest(nums, k):
    # Use a min-heap of size k
    # Time: O(n log k), Space: O(k)
    heap = []
    for num in nums:
        heapq.heappush(heap, num)
        if len(heap) > k:
            heapq.heappop(heap)
    return heap[0]

# Alternative: QuickSelect for O(n) average
def quickselect(nums, k):
    k = len(nums) - k  # Convert to kth smallest
    
    def partition(left, right, pivot_idx):
        pivot = nums[pivot_idx]
        nums[pivot_idx], nums[right] = nums[right], nums[pivot_idx]
        store_idx = left
        for i in range(left, right):
            if nums[i] < pivot:
                nums[store_idx], nums[i] = nums[i], nums[store_idx]
                store_idx += 1
        nums[right], nums[store_idx] = nums[store_idx], nums[right]
        return store_idx
    
    left, right = 0, len(nums) - 1
    while True:
        pivot_idx = partition(left, right, right)
        if pivot_idx == k:
            return nums[k]
        elif pivot_idx < k:
            left = pivot_idx + 1
        else:
            right = pivot_idx - 1
```

</details>

<details>
<summary><b>Mathematical Reasoning</b></summary>

**Prompt:** Prove that the sum of the first n odd numbers equals n².

**Response:** 

Let's prove this by multiple methods:

**Method 1: Direct Calculation**
The first n odd numbers are: 1, 3, 5, ..., (2n-1)

Sum = 1 + 3 + 5 + ... + (2n-1)

This is an arithmetic sequence with:
- First term a₁ = 1
- Last term aₙ = 2n - 1  
- Number of terms = n

Sum = n × (first + last) / 2 = n × (1 + 2n - 1) / 2 = n × 2n / 2 = n²

**Method 2: Induction**
- Base case: n=1 → Sum = 1 = 1² ✓
- Assume true for k: 1 + 3 + ... + (2k-1) = k²
- For k+1: k² + (2(k+1)-1) = k² + 2k + 1 = (k+1)² ✓

</details>

<details>
<summary><b>Debugging</b></summary>

**Prompt:** Why does this code give wrong results?
```python
def binary_search(arr, target):
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) / 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid
        else:
            right = mid
    return -1
```

**Response:** There are several bugs:

1. **Integer division**: `mid = (left + right) / 2` returns a float. Use `//` for integer division.

2. **Infinite loop**: `left = mid` can cause infinite loop when `mid == left`. Should be `left = mid + 1`.

3. **Off-by-one**: With `right = len(arr)`, using `right = mid` is correct, but the initial range setup suggests you want `right = len(arr) - 1` with `left <= right`.

**Fixed version:**
```python
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1
```

</details>

## Hardware Requirements

| Setup | VRAM Required | Notes |
|-------|---------------|-------|
| FP16/BF16 | ~4 GB | Full precision inference |

## Citation

```bibtex
@misc{ucoder-mini,
  author = {uaytug},
  title = {uCoder Mini: A Compact Language Model for Code and Math},
  year = {2026},
  publisher = {Hugging Face},
  url = {https://huggingface.co/uaytug/ucoder-mini}
}
```

## Acknowledgments

Thanks to the open-source community and creators of the datasets that made UCDS possible.