AmareshHebbar commited on
Commit
29709dd
Β·
verified Β·
1 Parent(s): 96f27d4

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

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