Text Generation
PEFT
Safetensors
GGUF
English
code
leetcode
javascript
code-generation
competitive-programming
qwen2.5-coder
dora
qdora
weight-decomposed-lora
instruction-tuned
sft
algorithm-generation
function-generation
coding-assistant
on-device
ollama
vllm
text-generation-inference
doocs-leetcode
synthetic-verification
quantized
algorithms
conversational
Instructions to use AmareshHebbar/leetcode-javascript-qwen25-coder-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use AmareshHebbar/leetcode-javascript-qwen25-coder-7b with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit") model = PeftModel.from_pretrained(base_model, "AmareshHebbar/leetcode-javascript-qwen25-coder-7b") - Notebooks
- Google Colab
- Kaggle
docs: v3 model card - QDoRA rationale, richer inference samples, expanded tags
Browse files
README.md
CHANGED
|
@@ -8,15 +8,29 @@ tags:
|
|
| 8 |
- code-generation
|
| 9 |
- competitive-programming
|
| 10 |
- qwen2.5-coder
|
| 11 |
-
-
|
| 12 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
- algorithms
|
| 14 |
language:
|
| 15 |
- en
|
| 16 |
library_name: peft
|
| 17 |
pipeline_tag: text-generation
|
| 18 |
datasets:
|
| 19 |
-
- AmareshHebbar/leetcode-
|
| 20 |
co2_eq_emissions:
|
| 21 |
emissions: 0
|
| 22 |
source: "estimate, not measured with a carbon-tracking tool"
|
|
@@ -31,18 +45,19 @@ model-index:
|
|
| 31 |
<div align="center">
|
| 32 |
|
| 33 |
# π¨ LeetCode JavaScript Coder
|
| 34 |
-
### Qwen2.5-Coder-7B fine-tuned to solve LeetCode problems in JavaScript
|
| 35 |
|
| 36 |
[](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b)
|
| 37 |
-
[](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF)
|
| 39 |
[](https://www.apache.org/licenses/LICENSE-2.0)
|
| 40 |
[](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct)
|
|
|
|
| 41 |
[](#ollama)
|
| 42 |
[](#vllm)
|
| 43 |
[](#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 |
|
|
@@ -50,7 +65,7 @@ model-index:
|
|
| 50 |
|
| 51 |
## TL;DR
|
| 52 |
|
| 53 |
-
Given a LeetCode-style problem statement and an algorithm tag, generates a working JavaScript 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.
|
|
@@ -69,14 +84,44 @@ var twoSum = function(nums, target) {
|
|
| 69 |
| | |
|
| 70 |
|---|---|
|
| 71 |
| **Base model** | [unsloth/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct) |
|
| 72 |
-
| **Method** |
|
| 73 |
-
| **Training data** | [leetcode-
|
| 74 |
-
| **
|
|
|
|
|
|
|
| 75 |
| **GGUF build** | [leetcode-javascript-qwen25-coder-7b-GGUF](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF) β q4_k_m / q5_k_m / q8_0 |
|
| 76 |
| **License** | Apache 2.0 |
|
| 77 |
|
| 78 |
---
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
## Benchmarks (free, reproducible)
|
| 81 |
|
| 82 |
Run `benchmark_suite.py` from the deployment kit to reproduce. All numbers are pass@1 unless noted.
|
|
@@ -85,11 +130,11 @@ Run `benchmark_suite.py` from the deployment kit to reproduce. All numbers are p
|
|
| 85 |
|---|---|---|---|---|
|
| 86 |
| [HumanEval-X](https://huggingface.co/datasets/THUDM/humaneval-x) | JavaScript | _run benchmark_suite.py_ | _run benchmark_suite.py_ | 164 problems, execution-verified |
|
| 87 |
| [MultiPL-E](https://huggingface.co/datasets/nuprl/MultiPL-E) (HumanEval subset) | JavaScript | _run benchmark_suite.py_ | β | cross-check vs HumanEval-X |
|
| 88 |
-
| Held-out LeetCode test split | JavaScript | _run benchmark_suite.py_ | β | from `leetcode-
|
| 89 |
| Tokens/sec (fp16, A40) | JavaScript | β | β | latency benchmark, see script |
|
| 90 |
| Tokens/sec (GGUF q4_k_m, CPU) | JavaScript | β | β | latency benchmark, see script |
|
| 91 |
|
| 92 |
-
> Numbers are intentionally left blank in this template β `benchmark_suite.py` fills a `results/leetcode-javascript-qwen25-coder-7b.json` file and this table should be regenerated from it
|
| 93 |
|
| 94 |
---
|
| 95 |
|
|
@@ -139,6 +184,65 @@ outputs = model.generate(inputs, max_new_tokens=512, temperature=0.2, do_sample=
|
|
| 139 |
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
|
| 140 |
```
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
### Option B β Unsloth (2x faster load + inference)
|
| 143 |
|
| 144 |
```python
|
|
@@ -185,6 +289,18 @@ response = client.chat.completions.create(
|
|
| 185 |
print(response.choices[0].message.content)
|
| 186 |
```
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
### Option D β TGI (Text Generation Inference) {#tgi}
|
| 189 |
|
| 190 |
```bash
|
|
@@ -214,6 +330,17 @@ ollama create leetcode-javascript-qwen25-coder-7b -f Modelfile.javascript
|
|
| 214 |
ollama run leetcode-javascript-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"
|
| 215 |
```
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
### Option F β GGUF / llama.cpp direct (mobile/edge inference)
|
| 218 |
|
| 219 |
```bash
|
|
@@ -228,19 +355,43 @@ See `export_gguf.py` in the deployment kit for building q4_k_m / q5_k_m / q8_0 v
|
|
| 228 |
|
| 229 |
## Training details
|
| 230 |
|
| 231 |
-
###
|
| 232 |
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
### Hyperparameters
|
| 236 |
|
| 237 |
| Parameter | Value |
|
| 238 |
|---|---|
|
|
|
|
| 239 |
| LoRA rank (r) | 16 |
|
| 240 |
| LoRA alpha | 32 |
|
| 241 |
| LoRA dropout | 0 |
|
| 242 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 243 |
-
|
|
| 244 |
| Max sequence length | 2048 |
|
| 245 |
| Optimizer | paged_adamw_8bit |
|
| 246 |
| LR schedule | 2e-4, cosine |
|
|
@@ -253,7 +404,8 @@ Trained on [leetcode-javascript-sft](https://huggingface.co/datasets/AmareshHebb
|
|
| 253 |
| **Cloud provider** | RunPod |
|
| 254 |
| **CO2 estimate** | self-reported, not measured with a carbon tracker β treat as approximate |
|
| 255 |
|
| 256 |
-
Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) + TRL's `SFTTrainer`
|
|
|
|
| 257 |
|
| 258 |
---
|
| 259 |
|
|
@@ -265,19 +417,27 @@ Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) + TRL's `SFTTrai
|
|
| 265 |
|
| 266 |
**Not exhaustive on complexity.** The model doesn't guarantee asymptotically optimal solutions β check the complexity claims yourself for performance-sensitive use.
|
| 267 |
|
|
|
|
|
|
|
| 268 |
---
|
| 269 |
|
| 270 |
## FAQ
|
| 271 |
|
| 272 |
**Q: Can I merge the adapter into the base model?**
|
| 273 |
-
Yes β `model.merge_and_unload()` after loading with PEFT, or Unsloth's `save_pretrained_merged()`.
|
| 274 |
|
| 275 |
-
**Q: Why
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
**Q: Which quantization should I use on mobile?**
|
| 279 |
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.
|
| 280 |
|
|
|
|
|
|
|
|
|
|
| 281 |
---
|
| 282 |
|
| 283 |
## Related models in this suite
|
|
@@ -297,8 +457,9 @@ q4_k_m is the best size/quality tradeoff for phones; q5_k_m if you have RAM head
|
|
| 297 |
|
| 298 |
| Version | Notes |
|
| 299 |
|---|---|
|
|
|
|
| 300 |
| v2.0 | Added GGUF builds, Ollama/vLLM/TGI deployment, benchmark harness (HumanEval-X, MultiPL-E, held-out test split) |
|
| 301 |
-
| v1.0 | Initial release β QLoRA fine-tune
|
| 302 |
|
| 303 |
---
|
| 304 |
|
|
|
|
| 8 |
- code-generation
|
| 9 |
- competitive-programming
|
| 10 |
- qwen2.5-coder
|
| 11 |
+
- dora
|
| 12 |
+
- qdora
|
| 13 |
+
- weight-decomposed-lora
|
| 14 |
+
- instruction-tuned
|
| 15 |
+
- sft
|
| 16 |
+
- algorithm-generation
|
| 17 |
+
- function-generation
|
| 18 |
+
- coding-assistant
|
| 19 |
+
- on-device
|
| 20 |
+
- gguf
|
| 21 |
+
- ollama
|
| 22 |
+
- vllm
|
| 23 |
+
- text-generation-inference
|
| 24 |
+
- doocs-leetcode
|
| 25 |
+
- synthetic-verification
|
| 26 |
+
- quantized
|
| 27 |
- algorithms
|
| 28 |
language:
|
| 29 |
- en
|
| 30 |
library_name: peft
|
| 31 |
pipeline_tag: text-generation
|
| 32 |
datasets:
|
| 33 |
+
- AmareshHebbar/leetcode-code-gen-datasets
|
| 34 |
co2_eq_emissions:
|
| 35 |
emissions: 0
|
| 36 |
source: "estimate, not measured with a carbon-tracking tool"
|
|
|
|
| 45 |
<div align="center">
|
| 46 |
|
| 47 |
# π¨ LeetCode JavaScript Coder
|
| 48 |
+
### Qwen2.5-Coder-7B, QDoRA fine-tuned to solve LeetCode problems in JavaScript
|
| 49 |
|
| 50 |
[](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b)
|
| 51 |
+
[](https://huggingface.co/datasets/AmareshHebbar/leetcode-code-gen-datasets)
|
| 52 |
[](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF)
|
| 53 |
[](https://www.apache.org/licenses/LICENSE-2.0)
|
| 54 |
[](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct)
|
| 55 |
+
[](#why-qdora)
|
| 56 |
[](#ollama)
|
| 57 |
[](#vllm)
|
| 58 |
[](#tgi)
|
| 59 |
|
| 60 |
+
*Part of the [LeetCode Multi-Language Coder Suite](https://huggingface.co/collections/AmareshHebbar/leetcode-multi-language-coder-suite) β 4 language specialists, one base model, one pipeline*
|
| 61 |
|
| 62 |
</div>
|
| 63 |
|
|
|
|
| 65 |
|
| 66 |
## TL;DR
|
| 67 |
|
| 68 |
+
Given a LeetCode-style problem statement, its sample input/output, and an algorithm tag, generates a working JavaScript solution.
|
| 69 |
|
| 70 |
```
|
| 71 |
PROBLEM: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
|
|
|
|
| 84 |
| | |
|
| 85 |
|---|---|
|
| 86 |
| **Base model** | [unsloth/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct) |
|
| 87 |
+
| **Method** | QDoRA (quantized DoRA, not plain LoRA) |
|
| 88 |
+
| **Training data** | [leetcode-code-gen-datasets](https://huggingface.co/datasets/AmareshHebbar/leetcode-code-gen-datasets) config `javascript` |
|
| 89 |
+
| **Data provenance** | scraped from [doocs/leetcode](https://github.com/doocs/leetcode) (3,977 problems), execution-verified, no synthetic/LLM-generated solutions |
|
| 90 |
+
| **Data quality** | execution-checked against sample I/O (see dataset card for exact rate) |
|
| 91 |
+
| **Weights here** | QDoRA adapter only (~160MB) β load on top of the base model |
|
| 92 |
| **GGUF build** | [leetcode-javascript-qwen25-coder-7b-GGUF](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF) β q4_k_m / q5_k_m / q8_0 |
|
| 93 |
| **License** | Apache 2.0 |
|
| 94 |
|
| 95 |
---
|
| 96 |
|
| 97 |
+
## Why QDoRA {#why-qdora}
|
| 98 |
+
|
| 99 |
+
DoRA splits each adapted weight into magnitude + direction and trains both, which follows full fine-tuning's behavior more closely than plain LoRA β important for code where small precision errors break correctness outright. 4-bit NF4 quantization of the frozen base keeps this affordable on a single 48GB GPU.
|
| 100 |
+
|
| 101 |
+
Concretely, versus the plain-QLoRA v1 release of this suite: DoRA adds a per-column
|
| 102 |
+
trainable magnitude vector on top of the usual low-rank direction update, so the
|
| 103 |
+
adapter can rescale a feature's importance instead of only rotating it. On a code
|
| 104 |
+
task where a single wrong operator or dropped edge case fails the whole solution,
|
| 105 |
+
that closer match to full fine-tuning's update pattern showed up as fewer
|
| 106 |
+
near-miss failures during our own qualitative review, at the same LoRA rank and
|
| 107 |
+
VRAM budget.
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
# training-side PEFT config (see build_language_datasets.py / trainer script for full pipeline)
|
| 111 |
+
from peft import LoraConfig
|
| 112 |
+
|
| 113 |
+
peft_config = LoraConfig(
|
| 114 |
+
r=16,
|
| 115 |
+
lora_alpha=32,
|
| 116 |
+
lora_dropout=0.0,
|
| 117 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
|
| 118 |
+
use_dora=True, # <- this is what makes it QDoRA, not QLoRA
|
| 119 |
+
task_type="CAUSAL_LM",
|
| 120 |
+
)
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
## Benchmarks (free, reproducible)
|
| 126 |
|
| 127 |
Run `benchmark_suite.py` from the deployment kit to reproduce. All numbers are pass@1 unless noted.
|
|
|
|
| 130 |
|---|---|---|---|---|
|
| 131 |
| [HumanEval-X](https://huggingface.co/datasets/THUDM/humaneval-x) | JavaScript | _run benchmark_suite.py_ | _run benchmark_suite.py_ | 164 problems, execution-verified |
|
| 132 |
| [MultiPL-E](https://huggingface.co/datasets/nuprl/MultiPL-E) (HumanEval subset) | JavaScript | _run benchmark_suite.py_ | β | cross-check vs HumanEval-X |
|
| 133 |
+
| Held-out LeetCode test split | JavaScript | _run benchmark_suite.py_ | β | from `leetcode-code-gen-datasets` (`javascript`) test split, exact I/O match |
|
| 134 |
| Tokens/sec (fp16, A40) | JavaScript | β | β | latency benchmark, see script |
|
| 135 |
| Tokens/sec (GGUF q4_k_m, CPU) | JavaScript | β | β | latency benchmark, see script |
|
| 136 |
|
| 137 |
+
> Numbers are intentionally left blank in this template β `benchmark_suite.py` fills a `results/leetcode-javascript-qwen25-coder-7b.json` file and this table should be regenerated from it.
|
| 138 |
|
| 139 |
---
|
| 140 |
|
|
|
|
| 184 |
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))
|
| 185 |
```
|
| 186 |
|
| 187 |
+
### Batch inference (many problems at once)
|
| 188 |
+
|
| 189 |
+
```python
|
| 190 |
+
problems = [
|
| 191 |
+
"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",
|
| 192 |
+
"Problem: Given a string s, find the length of the longest substring without repeating characters.\nAlgorithm: two pointers / sliding window",
|
| 193 |
+
"Problem: Merge two sorted linked lists into one sorted list.\nAlgorithm: linked list, dummy head",
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
prompts = [
|
| 197 |
+
tokenizer.apply_chat_template(
|
| 198 |
+
[{"role": "system", "content": "You are an expert JavaScript competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient JavaScript solution."}, {"role": "user", "content": p}],
|
| 199 |
+
tokenize=False, add_generation_prompt=True,
|
| 200 |
+
)
|
| 201 |
+
for p in problems
|
| 202 |
+
]
|
| 203 |
+
tokenizer.padding_side = "left"
|
| 204 |
+
batch = tokenizer(prompts, return_tensors="pt", padding=True).to(model.device)
|
| 205 |
+
outputs = model.generate(**batch, max_new_tokens=512, temperature=0.2, do_sample=True)
|
| 206 |
+
for i, o in enumerate(outputs):
|
| 207 |
+
print(f"--- solution {i} ---")
|
| 208 |
+
print(tokenizer.decode(o[batch['input_ids'].shape[1]:], skip_special_tokens=True))
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
### Streaming output (token-by-token)
|
| 212 |
+
|
| 213 |
+
```python
|
| 214 |
+
from transformers import TextIteratorStreamer
|
| 215 |
+
from threading import Thread
|
| 216 |
+
|
| 217 |
+
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
| 218 |
+
gen_kwargs = dict(input_ids=inputs, max_new_tokens=512, temperature=0.2, do_sample=True, streamer=streamer)
|
| 219 |
+
Thread(target=model.generate, kwargs=gen_kwargs).start()
|
| 220 |
+
for token in streamer:
|
| 221 |
+
print(token, end="", flush=True)
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
### Structured JSON output (code + complexity + explanation)
|
| 225 |
+
|
| 226 |
+
```python
|
| 227 |
+
json_system_prompt = (
|
| 228 |
+
"You are an expert JavaScript competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient JavaScript solution. "
|
| 229 |
+
'Respond ONLY with JSON: {"code": "...", "time_complexity": "...", '
|
| 230 |
+
'"space_complexity": "...", "explanation": "..."}'
|
| 231 |
+
)
|
| 232 |
+
messages = [
|
| 233 |
+
{"role": "system", "content": json_system_prompt},
|
| 234 |
+
{"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"},
|
| 235 |
+
]
|
| 236 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
|
| 237 |
+
outputs = model.generate(inputs, max_new_tokens=512, temperature=0.1, do_sample=True)
|
| 238 |
+
raw = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
|
| 239 |
+
|
| 240 |
+
import json
|
| 241 |
+
result = json.loads(raw.strip().removeprefix("```json").removesuffix("```").strip())
|
| 242 |
+
print(result["code"])
|
| 243 |
+
print(result["time_complexity"], result["space_complexity"])
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
### Option B β Unsloth (2x faster load + inference)
|
| 247 |
|
| 248 |
```python
|
|
|
|
| 289 |
print(response.choices[0].message.content)
|
| 290 |
```
|
| 291 |
|
| 292 |
+
Streaming with vLLM's OpenAI-compatible endpoint:
|
| 293 |
+
```python
|
| 294 |
+
stream = client.chat.completions.create(
|
| 295 |
+
model="leetcode-javascript-qwen25-coder-7b",
|
| 296 |
+
messages=[{"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"}],
|
| 297 |
+
stream=True,
|
| 298 |
+
)
|
| 299 |
+
for chunk in stream:
|
| 300 |
+
if chunk.choices[0].delta.content:
|
| 301 |
+
print(chunk.choices[0].delta.content, end="", flush=True)
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
### Option D β TGI (Text Generation Inference) {#tgi}
|
| 305 |
|
| 306 |
```bash
|
|
|
|
| 330 |
ollama run leetcode-javascript-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"
|
| 331 |
```
|
| 332 |
|
| 333 |
+
Python client against a local Ollama server:
|
| 334 |
+
```python
|
| 335 |
+
import requests
|
| 336 |
+
r = requests.post("http://localhost:11434/api/generate", json={
|
| 337 |
+
"model": "leetcode-javascript-qwen25-coder-7b",
|
| 338 |
+
"prompt": "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",
|
| 339 |
+
"stream": False,
|
| 340 |
+
})
|
| 341 |
+
print(r.json()["response"])
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
### Option F β GGUF / llama.cpp direct (mobile/edge inference)
|
| 345 |
|
| 346 |
```bash
|
|
|
|
| 355 |
|
| 356 |
## Training details
|
| 357 |
|
| 358 |
+
### Why this base model
|
| 359 |
|
| 360 |
+
Qwen2.5-Coder-7B-Instruct was chosen over a general instruct model because its
|
| 361 |
+
pretraining already concentrates capacity on code β the QDoRA adapter only has to
|
| 362 |
+
specialize output format and LeetCode-specific conventions (function signatures,
|
| 363 |
+
in-place vs. new-array conventions, JavaScript idioms) rather than teach the model
|
| 364 |
+
to code from scratch. 7B was picked as the size that still fits comfortably in a
|
| 365 |
+
single-GPU QDoRA run while keeping enough headroom that the base model's code
|
| 366 |
+
reasoning survives adaptation.
|
| 367 |
+
|
| 368 |
+
### Data pipeline
|
| 369 |
+
|
| 370 |
+
Source: [doocs/leetcode](https://github.com/doocs/leetcode), 3,977 problems with
|
| 371 |
+
English documentation. Each problem can have multiple solutions spanning different
|
| 372 |
+
algorithm tags (greedy, DP, two pointers, etc.) β the pipeline treats this as a
|
| 373 |
+
one-to-many problem-to-solution structure rather than picking a single "canonical" answer.
|
| 374 |
+
|
| 375 |
+
| Stage | What it does |
|
| 376 |
+
|---|---|
|
| 377 |
+
| `extract_doocs.py` | pulls problem statement + I/O examples + per-solution algorithm tag from doocs/leetcode |
|
| 378 |
+
| `verify.py` | executes each extracted solution against its sample I/O, drops anything that fails |
|
| 379 |
+
| `normalize.py` | standardizes formatting/whitespace and problem/solution schema across all 4 languages |
|
| 380 |
+
| `build_language_datasets.py` | splits into per-language configs and writes the final train/val/test SFT rows |
|
| 381 |
+
|
| 382 |
+
execution-checked against sample I/O (see dataset card for exact rate). Full extraction/verification/build code lives alongside the
|
| 383 |
+
[leetcode-code-gen-datasets](https://huggingface.co/datasets/AmareshHebbar/leetcode-code-gen-datasets) dataset card.
|
| 384 |
|
| 385 |
### Hyperparameters
|
| 386 |
|
| 387 |
| Parameter | Value |
|
| 388 |
|---|---|
|
| 389 |
+
| Method | QDoRA (`use_dora=True` in PEFT's `LoraConfig`) |
|
| 390 |
| LoRA rank (r) | 16 |
|
| 391 |
| LoRA alpha | 32 |
|
| 392 |
| LoRA dropout | 0 |
|
| 393 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 394 |
+
| Base quantization | 4-bit NF4 |
|
| 395 |
| Max sequence length | 2048 |
|
| 396 |
| Optimizer | paged_adamw_8bit |
|
| 397 |
| LR schedule | 2e-4, cosine |
|
|
|
|
| 404 |
| **Cloud provider** | RunPod |
|
| 405 |
| **CO2 estimate** | self-reported, not measured with a carbon tracker β treat as approximate |
|
| 406 |
|
| 407 |
+
Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) + TRL's `SFTTrainer`,
|
| 408 |
+
DoRA enabled via PEFT.
|
| 409 |
|
| 410 |
---
|
| 411 |
|
|
|
|
| 417 |
|
| 418 |
**Not exhaustive on complexity.** The model doesn't guarantee asymptotically optimal solutions β check the complexity claims yourself for performance-sensitive use.
|
| 419 |
|
| 420 |
+
**Data recency.** Reflects the state of `doocs/leetcode` at the time of extraction β newer problems added to LeetCode after that snapshot won't be covered.
|
| 421 |
+
|
| 422 |
---
|
| 423 |
|
| 424 |
## FAQ
|
| 425 |
|
| 426 |
**Q: Can I merge the adapter into the base model?**
|
| 427 |
+
Yes β `model.merge_and_unload()` after loading with PEFT, or Unsloth's `save_pretrained_merged()`. DoRA adapters merge the same way LoRA adapters do.
|
| 428 |
|
| 429 |
+
**Q: Why QDoRA instead of plain QLoRA?**
|
| 430 |
+
See [Why QDoRA](#why-qdora) above β short version: DoRA's magnitude/direction split tracks full fine-tuning more closely, which matters for code correctness.
|
| 431 |
+
|
| 432 |
+
**Q: Why QDoRA instead of full fine-tuning?**
|
| 433 |
+
Qwen2.5-Coder-7B already has strong code priors from pretraining; QDoRA gets most of full fine-tuning's adaptation quality at a fraction of the compute and without the overfitting risk of updating every parameter on a comparatively small SFT set.
|
| 434 |
|
| 435 |
**Q: Which quantization should I use on mobile?**
|
| 436 |
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.
|
| 437 |
|
| 438 |
+
**Q: Does this model store or transmit my input?**
|
| 439 |
+
No β inference runs entirely on whatever infrastructure you deploy it to.
|
| 440 |
+
|
| 441 |
---
|
| 442 |
|
| 443 |
## Related models in this suite
|
|
|
|
| 457 |
|
| 458 |
| Version | Notes |
|
| 459 |
|---|---|
|
| 460 |
+
| v3.0 | Switched to QDoRA, added rationale + PEFT config, batch/streaming/JSON inference samples, expanded tags |
|
| 461 |
| v2.0 | Added GGUF builds, Ollama/vLLM/TGI deployment, benchmark harness (HumanEval-X, MultiPL-E, held-out test split) |
|
| 462 |
+
| v1.0 | Initial release β QLoRA fine-tune |
|
| 463 |
|
| 464 |
---
|
| 465 |
|