AmareshHebbar commited on
Commit
06bd032
Β·
verified Β·
1 Parent(s): 44e6bc4

docs: v2 model card - GGUF/Ollama/vLLM/TGI, benchmark table, collection link

Browse files
Files changed (1) hide show
  1. README.md +316 -14
README.md CHANGED
@@ -1,22 +1,324 @@
1
  ---
2
- base_model: unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit
3
- tags:
4
- - text-generation-inference
5
- - transformers
6
- - unsloth
7
- - qwen2
8
- - trl
9
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
10
  language:
11
- - en
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- # Uploaded model
15
 
16
- - **Developed by:** AmareshHebbar
17
- - **License:** apache-2.0
18
- - **Finetuned from model :** unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit
 
 
 
 
 
 
19
 
20
- This qwen2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
1
  ---
 
 
 
 
 
 
 
2
  license: apache-2.0
3
+ base_model: unsloth/Qwen2.5-Coder-7B-Instruct
4
+ tags:
5
+ - code
6
+ - leetcode
7
+ - cpp
8
+ - code-generation
9
+ - competitive-programming
10
+ - qwen2.5-coder
11
+ - qlora
12
+ - unsloth
13
+ - algorithms
14
  language:
15
+ - en
16
+ library_name: peft
17
+ pipeline_tag: text-generation
18
+ datasets:
19
+ - AmareshHebbar/leetcode-cpp-sft
20
+ co2_eq_emissions:
21
+ emissions: 0
22
+ source: "estimate, not measured with a carbon-tracking tool"
23
+ training_type: "fine-tuning"
24
+ geographical_location: "EU-West"
25
+ hardware_used: "NVIDIA A40 (48GB)"
26
+ model-index:
27
+ - name: leetcode-cpp-qwen25-coder-7b
28
+ results: []
29
+ ---
30
+
31
+ <div align="center">
32
+
33
+ # βš™οΈ LeetCode C++ Coder
34
+ ### Qwen2.5-Coder-7B fine-tuned to solve LeetCode problems in C++
35
+
36
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Model-leetcode--cpp--qwen25--coder--7b-FFD21E)](https://huggingface.co/AmareshHebbar/leetcode-cpp-qwen25-coder-7b)
37
+ [![Dataset](https://img.shields.io/badge/%F0%9F%A4%97%20Dataset-leetcode--cpp--sft-blue)](https://huggingface.co/datasets/AmareshHebbar/leetcode-cpp-sft)
38
+ [![GGUF](https://img.shields.io/badge/GGUF-quantized-6f42c1)](https://huggingface.co/AmareshHebbar/leetcode-cpp-qwen25-coder-7b-GGUF)
39
+ [![License](https://img.shields.io/badge/license-Apache%202.0-green)](https://www.apache.org/licenses/LICENSE-2.0)
40
+ [![Base Model](https://img.shields.io/badge/base-Qwen2.5--Coder--7B-orange)](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct)
41
+ [![Ollama](https://img.shields.io/badge/-Ollama-000000?logo=ollama)](#ollama)
42
+ [![vLLM](https://img.shields.io/badge/-vLLM-333333)](#vllm)
43
+ [![TGI](https://img.shields.io/badge/-TGI-yellow)](#tgi)
44
+
45
+ *Part of the [LeetCode Multi-Language Coder Suite](https://huggingface.co/collections/AmareshHebbar/leetcode-multi-language-coder-suite) β€” 4 language specialists, one base model*
46
+
47
+ </div>
48
+
49
+ ---
50
+
51
+ ## TL;DR
52
+
53
+ Given a LeetCode-style problem statement and an algorithm tag, generates a working C++ solution.
54
+
55
+ ```
56
+ PROBLEM: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
57
+ ALGORITHM: Hash Map
58
+ OUTPUT (C++):
59
+ class Solution {
60
+ public:
61
+ vector<int> twoSum(vector<int>& nums, int target) {
62
+ unordered_map<int,int> seen;
63
+ for (int i = 0; i < nums.size(); i++) {
64
+ if (seen.count(target - nums[i])) return {seen[target - nums[i]], i};
65
+ seen[nums[i]] = i;
66
+ }
67
+ return {};
68
+ }
69
+ };
70
+ ```
71
+
72
+ | | |
73
+ |---|---|
74
+ | **Base model** | [unsloth/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct) |
75
+ | **Method** | QLoRA, 4-bit NF4, rank 16 |
76
+ | **Training data** | [leetcode-cpp-sft](https://huggingface.co/datasets/AmareshHebbar/leetcode-cpp-sft) |
77
+ | **Weights here** | LoRA adapter only (~160MB) β€” load on top of the base model |
78
+ | **GGUF build** | [leetcode-cpp-qwen25-coder-7b-GGUF](https://huggingface.co/AmareshHebbar/leetcode-cpp-qwen25-coder-7b-GGUF) β€” q4_k_m / q5_k_m / q8_0 |
79
+ | **License** | Apache 2.0 |
80
+
81
+ ---
82
+
83
+ ## Benchmarks (free, reproducible)
84
+
85
+ Run `benchmark_suite.py` from the deployment kit to reproduce. All numbers are pass@1 unless noted.
86
+
87
+ | Benchmark | Language | Pass@1 | Pass@10 | Notes |
88
+ |---|---|---|---|---|
89
+ | [HumanEval-X](https://huggingface.co/datasets/THUDM/humaneval-x) | C++ | _run benchmark_suite.py_ | _run benchmark_suite.py_ | 164 problems, execution-verified |
90
+ | [MultiPL-E](https://huggingface.co/datasets/nuprl/MultiPL-E) (HumanEval subset) | C++ | _run benchmark_suite.py_ | β€” | cross-check vs HumanEval-X |
91
+ | Held-out LeetCode test split | C++ | _run benchmark_suite.py_ | β€” | from `leetcode-cpp-sft` test split, exact I/O match |
92
+ | Tokens/sec (fp16, A40) | C++ | β€” | β€” | latency benchmark, see script |
93
+ | Tokens/sec (GGUF q4_k_m, CPU) | C++ | β€” | β€” | latency benchmark, see script |
94
+
95
+ > Numbers are intentionally left blank in this template β€” `benchmark_suite.py` fills a `results/leetcode-cpp-qwen25-coder-7b.json` file and this table should be regenerated from it (see deployment kit README).
96
+
97
+ ---
98
+
99
+ ## Intended use
100
+
101
+ Drop-in solution generator for C++ coding-practice tools, interview-prep apps, and automated code-review sandboxes for algorithmic problems.
102
+
103
+ ### Direct use
104
+ Give a problem statement (+ optional algorithm hint), get back a C++ function/class implementing it.
105
+
106
+ ### Downstream use
107
+ Feed output into an automated grader (run against test cases), a code-review bot, or a practice-app "show solution" feature.
108
+
109
+ ### Out of scope
110
+ - Production system design or non-algorithmic code (this model specializes narrowly on LeetCode-style problems)
111
+ - Security-critical code without human review
112
+ - Guaranteed-optimal complexity β€” treat output as a strong first draft, not a proof
113
+
114
+ ---
115
+
116
+ ## Quickstart
117
+
118
+ ### Option A β€” Transformers + PEFT
119
+
120
+ ```python
121
+ from transformers import AutoModelForCausalLM, AutoTokenizer
122
+ from peft import PeftModel
123
+ import torch
124
+
125
+ base_model = "unsloth/Qwen2.5-Coder-7B-Instruct"
126
+ adapter = "AmareshHebbar/leetcode-cpp-qwen25-coder-7b"
127
+
128
+ tokenizer = AutoTokenizer.from_pretrained("AmareshHebbar/leetcode-cpp-qwen25-coder-7b")
129
+ model = AutoModelForCausalLM.from_pretrained(
130
+ base_model,
131
+ torch_dtype=torch.bfloat16,
132
+ device_map="auto",
133
+ )
134
+ model = PeftModel.from_pretrained(model, adapter)
135
+
136
+ messages = [
137
+ {"role": "system", "content": "You are an expert C++ competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient C++ solution."},
138
+ {"role": "user", "content": "Problem: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.\nAlgorithm: Hash Map"},
139
+ ]
140
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
141
+ outputs = model.generate(inputs, max_new_tokens=512, temperature=0.2, do_sample=True)
142
+ print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
143
+ ```
144
+
145
+ ### Option B β€” Unsloth (2x faster load + inference)
146
+
147
+ ```python
148
+ from unsloth import FastLanguageModel
149
+
150
+ model, tokenizer = FastLanguageModel.from_pretrained(
151
+ model_name="AmareshHebbar/leetcode-cpp-qwen25-coder-7b",
152
+ max_seq_length=2048,
153
+ load_in_4bit=True,
154
+ )
155
+ FastLanguageModel.for_inference(model)
156
+
157
+ messages = [
158
+ {"role": "system", "content": "You are an expert C++ competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient C++ solution."},
159
+ {"role": "user", "content": "Problem: Given a string s, find the length of the longest substring without repeating characters.\nAlgorithm: two pointers / sliding window"},
160
+ ]
161
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
162
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
163
+ outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.2, do_sample=True)
164
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
165
+ ```
166
+
167
+ ### Option C β€” vLLM (production serving, OpenAI-compatible) {#vllm}
168
+
169
+ ```bash
170
+ vllm serve unsloth/Qwen2.5-Coder-7B-Instruct \
171
+ --enable-lora \
172
+ --lora-modules leetcode-cpp-qwen25-coder-7b=AmareshHebbar/leetcode-cpp-qwen25-coder-7b \
173
+ --host 0.0.0.0 --port 8000 --dtype bfloat16
174
+ ```
175
+
176
+ ```python
177
+ from openai import OpenAI
178
+
179
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
180
+ response = client.chat.completions.create(
181
+ model="leetcode-cpp-qwen25-coder-7b",
182
+ messages=[
183
+ {"role": "system", "content": "You are an expert C++ competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient C++ solution."},
184
+ {"role": "user", "content": "Problem: Merge two sorted linked lists into one sorted list.\nAlgorithm: linked list, dummy head"},
185
+ ],
186
+ temperature=0.2,
187
+ )
188
+ print(response.choices[0].message.content)
189
+ ```
190
+
191
+ ### Option D β€” TGI (Text Generation Inference) {#tgi}
192
+
193
+ ```bash
194
+ docker run --gpus all --shm-size 1g -p 8080:80 \
195
+ -v $PWD/data:/data ghcr.io/huggingface/text-generation-inference:latest \
196
+ --model-id unsloth/Qwen2.5-Coder-7B-Instruct \
197
+ --lora-adapters leetcode-cpp-qwen25-coder-7b=AmareshHebbar/leetcode-cpp-qwen25-coder-7b
198
+ ```
199
+
200
+ ```bash
201
+ curl 127.0.0.1:8080/generate_stream \
202
+ -X POST \
203
+ -d '{"inputs":"<|im_start|>system\nYou are an expert C++ competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient C++ solution.<|im_end|>\n<|im_start|>user\nProblem: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.\nAlgorithm: Hash Map<|im_end|>\n<|im_start|>assistant\n","parameters":{"max_new_tokens":512}}' \
204
+ -H 'Content-Type: application/json'
205
+ ```
206
+
207
+ ### Option E β€” Ollama (local, mobile/edge-friendly) {#ollama}
208
+
209
+ ```bash
210
+ # 1. Pull the GGUF build
211
+ huggingface-cli download AmareshHebbar/leetcode-cpp-qwen25-coder-7b-GGUF leetcode-cpp-qwen25-coder-7b.q4_k_m.gguf --local-dir .
212
+
213
+ # 2. Create the model from the Modelfile shipped in the deployment kit (see deploy_ollama.py)
214
+ ollama create leetcode-cpp-qwen25-coder-7b -f Modelfile.cpp
215
+
216
+ # 3. Run it
217
+ ollama run leetcode-cpp-qwen25-coder-7b "Problem: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.\nAlgorithm: Hash Map"
218
+ ```
219
+
220
+ ### Option F β€” GGUF / llama.cpp direct (mobile/edge inference)
221
+
222
+ ```bash
223
+ ./llama-cli -m leetcode-cpp-qwen25-coder-7b.q4_k_m.gguf \
224
+ -p "<|im_start|>system\nYou are an expert C++ competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient C++ solution.<|im_end|>\n<|im_start|>user\nProblem: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.<|im_end|>\n<|im_start|>assistant\n" \
225
+ -n 512 --temp 0.2
226
+ ```
227
+
228
+ See `export_gguf.py` in the deployment kit for building q4_k_m / q5_k_m / q8_0 variants, and the mobile integration notes there for Android (llama.cpp JNI) and iOS (llama.cpp via Swift bindings).
229
+
230
+ ---
231
+
232
+ ## Training details
233
+
234
+ ### Data
235
+
236
+ Trained on [leetcode-cpp-sft](https://huggingface.co/datasets/AmareshHebbar/leetcode-cpp-sft), built from the `doocs/leetcode` corpus: problem statement + input/output examples + algorithm tag β†’ verified C++ solution, one-to-many (problem β†’ multiple algorithm-tagged solutions).
237
+
238
+ ### Hyperparameters
239
+
240
+ | Parameter | Value |
241
+ |---|---|
242
+ | LoRA rank (r) | 16 |
243
+ | LoRA alpha | 32 |
244
+ | LoRA dropout | 0 |
245
+ | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
246
+ | Quantization | 4-bit NF4 (QLoRA) |
247
+ | Max sequence length | 2048 |
248
+ | Optimizer | paged_adamw_8bit |
249
+ | LR schedule | 2e-4, cosine |
250
+
251
+ ### Training compute
252
+
253
+ | | |
254
+ |---|---|
255
+ | **GPU** | NVIDIA A40 (48GB) |
256
+ | **Cloud provider** | RunPod |
257
+ | **CO2 estimate** | self-reported, not measured with a carbon tracker β€” treat as approximate |
258
+
259
+ Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) + TRL's `SFTTrainer`.
260
+
261
+ ---
262
+
263
+ ## Bias, risks & limitations
264
+
265
+ **Narrow specialization.** This model is tuned tightly on LeetCode-style algorithmic problems β€” general software-engineering code (frameworks, infra, business logic) is out of distribution.
266
+
267
+ **Verify before trusting.** Like any LLM, generated solutions can look plausible and still fail an edge case (empty input, integer overflow, off-by-one). Always run against test cases before use.
268
+
269
+ **Not exhaustive on complexity.** The model doesn't guarantee asymptotically optimal solutions β€” check the complexity claims yourself for performance-sensitive use.
270
+
271
+ ---
272
+
273
+ ## FAQ
274
+
275
+ **Q: Can I merge the adapter into the base model?**
276
+ Yes β€” `model.merge_and_unload()` after loading with PEFT, or Unsloth's `save_pretrained_merged()`.
277
+
278
+ **Q: Why QLoRA instead of full fine-tuning?**
279
+ Qwen2.5-Coder-7B already has strong code priors from pretraining; QLoRA specializes the output format and LeetCode-specific patterns without the cost of full fine-tuning.
280
+
281
+ **Q: Which quantization should I use on mobile?**
282
+ q4_k_m is the best size/quality tradeoff for phones; q5_k_m if you have RAM headroom; avoid q2/q3 for code generation β€” correctness drops sharply below 4-bit.
283
+
284
+ ---
285
+
286
+ ## Related models in this suite
287
+
288
+ | Model | Language |
289
+ |---|---|
290
+ | [leetcode-python-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-python-qwen25-coder-7b) | Python |
291
+ | [leetcode-java-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-java-qwen25-coder-7b) | Java |
292
+ | [leetcode-cpp-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-cpp-qwen25-coder-7b) | C++ (this model) |
293
+ | [leetcode-javascript-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b) | JavaScript |
294
+
295
+ **Full collection:** [LeetCode Multi-Language Coder Suite](https://huggingface.co/collections/AmareshHebbar/leetcode-multi-language-coder-suite)
296
+
297
+ ---
298
+
299
+ ## Changelog
300
+
301
+ | Version | Notes |
302
+ |---|---|
303
+ | v2.0 | Added GGUF builds, Ollama/vLLM/TGI deployment, benchmark harness (HumanEval-X, MultiPL-E, held-out test split) |
304
+ | v1.0 | Initial release β€” QLoRA fine-tune on leetcode-cpp-sft |
305
+
306
  ---
307
 
308
+ ## Citation
309
 
310
+ ```bibtex
311
+ @misc{leetcodecoder2026,
312
+ author = {Hebbar, Amaresh},
313
+ title = {LeetCode Multi-Language Coder Suite},
314
+ year = {2026},
315
+ publisher = {HuggingFace},
316
+ url = {https://huggingface.co/AmareshHebbar}
317
+ }
318
+ ```
319
 
320
+ ## Contact
321
 
322
+ [![GitHub](https://img.shields.io/badge/GitHub-amareshhebbar-181717?logo=github)](https://github.com/amareshhebbar)
323
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-gvamaresh-0A66C2?logo=linkedin)](https://www.linkedin.com/in/gvamaresh)
324
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Profile-AmareshHebbar-FFD21E)](https://huggingface.co/AmareshHebbar)