Text Generation
Transformers
GGUF
English
qwen2
code
programming
mathematics
reasoning
conversational
Instructions to use uaytug/ucoder-mini-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use uaytug/ucoder-mini-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="uaytug/ucoder-mini-GGUF", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("uaytug/ucoder-mini-GGUF") model = AutoModelForCausalLM.from_pretrained("uaytug/ucoder-mini-GGUF", device_map="auto") - llama-cpp-python
How to use uaytug/ucoder-mini-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="uaytug/ucoder-mini-GGUF", filename="uCoder-mini-IQ2_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use uaytug/ucoder-mini-GGUF 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 uaytug/ucoder-mini-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf uaytug/ucoder-mini-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf uaytug/ucoder-mini-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf uaytug/ucoder-mini-GGUF:Q4_K_M
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 uaytug/ucoder-mini-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf uaytug/ucoder-mini-GGUF:Q4_K_M
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 uaytug/ucoder-mini-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf uaytug/ucoder-mini-GGUF:Q4_K_M
Use Docker
docker model run hf.co/uaytug/ucoder-mini-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use uaytug/ucoder-mini-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "uaytug/ucoder-mini-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uaytug/ucoder-mini-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/uaytug/ucoder-mini-GGUF:Q4_K_M
- SGLang
How to use uaytug/ucoder-mini-GGUF with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "uaytug/ucoder-mini-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uaytug/ucoder-mini-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "uaytug/ucoder-mini-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uaytug/ucoder-mini-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use uaytug/ucoder-mini-GGUF with Ollama:
ollama run hf.co/uaytug/ucoder-mini-GGUF:Q4_K_M
- Unsloth Studio
How to use uaytug/ucoder-mini-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for uaytug/ucoder-mini-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for uaytug/ucoder-mini-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for uaytug/ucoder-mini-GGUF to start chatting
- Pi
How to use uaytug/ucoder-mini-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf uaytug/ucoder-mini-GGUF:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "uaytug/ucoder-mini-GGUF:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use uaytug/ucoder-mini-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf uaytug/ucoder-mini-GGUF:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default uaytug/ucoder-mini-GGUF:Q4_K_M
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use uaytug/ucoder-mini-GGUF with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf uaytug/ucoder-mini-GGUF:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "uaytug/ucoder-mini-GGUF:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use uaytug/ucoder-mini-GGUF with Docker Model Runner:
docker model run hf.co/uaytug/ucoder-mini-GGUF:Q4_K_M
- Lemonade
How to use uaytug/ucoder-mini-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull uaytug/ucoder-mini-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.ucoder-mini-GGUF-Q4_K_M
List all available models
lemonade list
Update README.md
Browse files
README.md
CHANGED
|
@@ -4,6 +4,284 @@ datasets:
|
|
| 4 |
- uaytug/UCDS
|
| 5 |
language:
|
| 6 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
base_model:
|
| 8 |
- uaytug/ucoder-mini
|
| 9 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- uaytug/UCDS
|
| 5 |
language:
|
| 6 |
- en
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
+
- programming
|
| 10 |
+
- mathematics
|
| 11 |
+
- reasoning
|
| 12 |
+
- text-generation
|
| 13 |
+
- conversational
|
| 14 |
+
- qwen2
|
| 15 |
+
pipeline_tag: text-generation
|
| 16 |
+
library_name: transformers
|
| 17 |
base_model:
|
| 18 |
- uaytug/ucoder-mini
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# uCoder Mini
|
| 22 |
+
|
| 23 |
+
> **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.).
|
| 24 |
+
|
| 25 |
+
    
|
| 26 |
+
|
| 27 |
+
## Overview
|
| 28 |
+
|
| 29 |
+
**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.
|
| 30 |
+
|
| 31 |
+
### Key Features
|
| 32 |
+
|
| 33 |
+
- **Specialized Focus**: Trained exclusively on coding and math data for maximum performance in these domains
|
| 34 |
+
- **Efficient Size**: 1.5B parameters — runs on consumer GPUs, fast inference
|
| 35 |
+
- **Extended Context**: Supports up to 4096 tokens for longer code generation
|
| 36 |
+
- **Multi-Language**: Handles Python, JavaScript, C++, Java, and more
|
| 37 |
+
- **Competitive Programming**: Strong on algorithmic problems (LeetCode, Codeforces-style)
|
| 38 |
+
|
| 39 |
+
## Model Details
|
| 40 |
+
|
| 41 |
+
| Attribute | Value |
|
| 42 |
+
|-----------|-------|
|
| 43 |
+
| **Architecture** | Qwen2 (Dense Transformer) |
|
| 44 |
+
| **Parameters** | ~1.5B |
|
| 45 |
+
| **Hidden Size** | 1536 |
|
| 46 |
+
| **Layers** | 28 |
|
| 47 |
+
| **Attention Heads** | 12 |
|
| 48 |
+
| **Context Length** | 4096 tokens |
|
| 49 |
+
| **Vocabulary Size** | 151,936 |
|
| 50 |
+
| **Training Precision** | bfloat16 |
|
| 51 |
+
| **Training Method** | Supervised Fine-Tuning (SFT) |
|
| 52 |
+
|
| 53 |
+
## Intended Use
|
| 54 |
+
|
| 55 |
+
**Recommended for:**
|
| 56 |
+
- Competitive programming (LeetCode, Codeforces, HackerRank)
|
| 57 |
+
- Algorithm implementation and optimization
|
| 58 |
+
- Mathematical problem solving with code
|
| 59 |
+
- Code debugging and explanation
|
| 60 |
+
- Learning programming concepts
|
| 61 |
+
|
| 62 |
+
**Not recommended for:**
|
| 63 |
+
- General conversation or chat
|
| 64 |
+
- Creative writing or storytelling
|
| 65 |
+
- Factual Q&A or knowledge retrieval
|
| 66 |
+
- Non-English tasks
|
| 67 |
+
- Production systems without human review
|
| 68 |
+
|
| 69 |
+
## Quick Start
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 73 |
+
|
| 74 |
+
model_id = "uaytug/ucoder-mini"
|
| 75 |
+
|
| 76 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 77 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 78 |
+
model_id,
|
| 79 |
+
torch_dtype="auto",
|
| 80 |
+
device_map="auto"
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
messages = [
|
| 84 |
+
{"role": "user", "content": "Write a Python function to find the longest palindromic substring."}
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 88 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 89 |
+
|
| 90 |
+
outputs = model.generate(
|
| 91 |
+
**inputs,
|
| 92 |
+
max_new_tokens=1024,
|
| 93 |
+
temperature=0.6,
|
| 94 |
+
top_p=0.95,
|
| 95 |
+
do_sample=True
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 99 |
+
print(response)
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
### Recommended Generation Parameters
|
| 103 |
+
|
| 104 |
+
For best results on coding tasks:
|
| 105 |
+
|
| 106 |
+
```python
|
| 107 |
+
generation_config = {
|
| 108 |
+
"max_new_tokens": 2048,
|
| 109 |
+
"temperature": 0.6, # Use 0.6 for focused output, 1.0 for more exploration
|
| 110 |
+
"top_p": 0.95,
|
| 111 |
+
"do_sample": True,
|
| 112 |
+
}
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Chat Template
|
| 116 |
+
|
| 117 |
+
uCoder Mini uses the ChatML format:
|
| 118 |
+
|
| 119 |
+
```
|
| 120 |
+
<|im_start|>user
|
| 121 |
+
Your coding question here<|im_end|>
|
| 122 |
+
<|im_start|>assistant
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Training Data
|
| 126 |
+
|
| 127 |
+
Trained on [UCDS (uCoder Dataset)](https://huggingface.co/datasets/uaytug/UCDS) — a curated collection of 420K+ high-quality samples:
|
| 128 |
+
|
| 129 |
+
| Source | Samples | Description |
|
| 130 |
+
|--------|---------|-------------|
|
| 131 |
+
| Codeforces | 47K+ | Competitive programming with solutions |
|
| 132 |
+
| Code-Contests-Plus | 10K+ | Algorithm challenges |
|
| 133 |
+
| CodeAlpaca | 15K+ | Instruction-following code |
|
| 134 |
+
| OpenMathInstruct | Various | Mathematical reasoning chains |
|
| 135 |
+
| Curated Sources | Various | Tool use, chain-of-thought, deduplication |
|
| 136 |
+
|
| 137 |
+
**Total**: 420,686 deduplicated samples covering Python, JavaScript, C++, Java, and more.
|
| 138 |
+
|
| 139 |
+
## Limitations
|
| 140 |
+
|
| 141 |
+
- **Domain-Specific**: This model is trained only on code/math — it will perform poorly on general tasks
|
| 142 |
+
- **English Only**: Best performance in English; other languages not supported
|
| 143 |
+
- **Knowledge Cutoff**: May not know about recent libraries, frameworks, or API changes
|
| 144 |
+
- **No Verification**: Always test generated code before use in production
|
| 145 |
+
- **Context Limit**: 4096 tokens may not be enough for very large codebases
|
| 146 |
+
- **No Web Access**: Cannot fetch documentation or search for solutions
|
| 147 |
+
|
| 148 |
+
## Example Outputs
|
| 149 |
+
|
| 150 |
+
<details>
|
| 151 |
+
<summary><b>Algorithm Problem</b></summary>
|
| 152 |
+
|
| 153 |
+
**Prompt:** Implement a function to find the kth largest element in an unsorted array.
|
| 154 |
+
|
| 155 |
+
```python
|
| 156 |
+
import heapq
|
| 157 |
+
|
| 158 |
+
def find_kth_largest(nums, k):
|
| 159 |
+
# Use a min-heap of size k
|
| 160 |
+
# Time: O(n log k), Space: O(k)
|
| 161 |
+
heap = []
|
| 162 |
+
for num in nums:
|
| 163 |
+
heapq.heappush(heap, num)
|
| 164 |
+
if len(heap) > k:
|
| 165 |
+
heapq.heappop(heap)
|
| 166 |
+
return heap[0]
|
| 167 |
+
|
| 168 |
+
# Alternative: QuickSelect for O(n) average
|
| 169 |
+
def quickselect(nums, k):
|
| 170 |
+
k = len(nums) - k # Convert to kth smallest
|
| 171 |
+
|
| 172 |
+
def partition(left, right, pivot_idx):
|
| 173 |
+
pivot = nums[pivot_idx]
|
| 174 |
+
nums[pivot_idx], nums[right] = nums[right], nums[pivot_idx]
|
| 175 |
+
store_idx = left
|
| 176 |
+
for i in range(left, right):
|
| 177 |
+
if nums[i] < pivot:
|
| 178 |
+
nums[store_idx], nums[i] = nums[i], nums[store_idx]
|
| 179 |
+
store_idx += 1
|
| 180 |
+
nums[right], nums[store_idx] = nums[store_idx], nums[right]
|
| 181 |
+
return store_idx
|
| 182 |
+
|
| 183 |
+
left, right = 0, len(nums) - 1
|
| 184 |
+
while True:
|
| 185 |
+
pivot_idx = partition(left, right, right)
|
| 186 |
+
if pivot_idx == k:
|
| 187 |
+
return nums[k]
|
| 188 |
+
elif pivot_idx < k:
|
| 189 |
+
left = pivot_idx + 1
|
| 190 |
+
else:
|
| 191 |
+
right = pivot_idx - 1
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
</details>
|
| 195 |
+
|
| 196 |
+
<details>
|
| 197 |
+
<summary><b>Mathematical Reasoning</b></summary>
|
| 198 |
+
|
| 199 |
+
**Prompt:** Prove that the sum of the first n odd numbers equals n².
|
| 200 |
+
|
| 201 |
+
**Response:**
|
| 202 |
+
|
| 203 |
+
Let's prove this by multiple methods:
|
| 204 |
+
|
| 205 |
+
**Method 1: Direct Calculation**
|
| 206 |
+
The first n odd numbers are: 1, 3, 5, ..., (2n-1)
|
| 207 |
+
|
| 208 |
+
Sum = 1 + 3 + 5 + ... + (2n-1)
|
| 209 |
+
|
| 210 |
+
This is an arithmetic sequence with:
|
| 211 |
+
- First term a₁ = 1
|
| 212 |
+
- Last term aₙ = 2n - 1
|
| 213 |
+
- Number of terms = n
|
| 214 |
+
|
| 215 |
+
Sum = n × (first + last) / 2 = n × (1 + 2n - 1) / 2 = n × 2n / 2 = n²
|
| 216 |
+
|
| 217 |
+
**Method 2: Induction**
|
| 218 |
+
- Base case: n=1 → Sum = 1 = 1² ✓
|
| 219 |
+
- Assume true for k: 1 + 3 + ... + (2k-1) = k²
|
| 220 |
+
- For k+1: k² + (2(k+1)-1) = k² + 2k + 1 = (k+1)² ✓
|
| 221 |
+
|
| 222 |
+
</details>
|
| 223 |
+
|
| 224 |
+
<details>
|
| 225 |
+
<summary><b>Debugging</b></summary>
|
| 226 |
+
|
| 227 |
+
**Prompt:** Why does this code give wrong results?
|
| 228 |
+
```python
|
| 229 |
+
def binary_search(arr, target):
|
| 230 |
+
left, right = 0, len(arr)
|
| 231 |
+
while left < right:
|
| 232 |
+
mid = (left + right) / 2
|
| 233 |
+
if arr[mid] == target:
|
| 234 |
+
return mid
|
| 235 |
+
elif arr[mid] < target:
|
| 236 |
+
left = mid
|
| 237 |
+
else:
|
| 238 |
+
right = mid
|
| 239 |
+
return -1
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
**Response:** There are several bugs:
|
| 243 |
+
|
| 244 |
+
1. **Integer division**: `mid = (left + right) / 2` returns a float. Use `//` for integer division.
|
| 245 |
+
|
| 246 |
+
2. **Infinite loop**: `left = mid` can cause infinite loop when `mid == left`. Should be `left = mid + 1`.
|
| 247 |
+
|
| 248 |
+
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`.
|
| 249 |
+
|
| 250 |
+
**Fixed version:**
|
| 251 |
+
```python
|
| 252 |
+
def binary_search(arr, target):
|
| 253 |
+
left, right = 0, len(arr) - 1
|
| 254 |
+
while left <= right:
|
| 255 |
+
mid = (left + right) // 2
|
| 256 |
+
if arr[mid] == target:
|
| 257 |
+
return mid
|
| 258 |
+
elif arr[mid] < target:
|
| 259 |
+
left = mid + 1
|
| 260 |
+
else:
|
| 261 |
+
right = mid - 1
|
| 262 |
+
return -1
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
</details>
|
| 266 |
+
|
| 267 |
+
## Hardware Requirements
|
| 268 |
+
|
| 269 |
+
| Setup | VRAM Required | Notes |
|
| 270 |
+
|-------|---------------|-------|
|
| 271 |
+
| FP16/BF16 | ~4 GB | Full precision inference |
|
| 272 |
+
|
| 273 |
+
## Citation
|
| 274 |
+
|
| 275 |
+
```bibtex
|
| 276 |
+
@misc{ucoder-mini,
|
| 277 |
+
author = {uaytug},
|
| 278 |
+
title = {uCoder Mini: A Compact Language Model for Code and Math},
|
| 279 |
+
year = {2026},
|
| 280 |
+
publisher = {Hugging Face},
|
| 281 |
+
url = {https://huggingface.co/uaytug/ucoder-mini}
|
| 282 |
+
}
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
## Acknowledgments
|
| 286 |
+
|
| 287 |
+
Thanks to the open-source community and creators of the datasets that made UCDS possible.
|