Team Ai
Modelpublic

AmareshHebbar/leetcode-javascript-qwen25-coder-7b

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
0likes9downloads
README.md483 linesDownload Raw Back to root
1---2license: apache-2.03base_model: unsloth/Qwen2.5-Coder-7B-Instruct4tags:5  - code6  - leetcode7  - javascript8  - code-generation9  - competitive-programming10  - qwen2.5-coder11  - dora12  - qdora13  - weight-decomposed-lora14  - instruction-tuned15  - sft16  - algorithm-generation17  - function-generation18  - coding-assistant19  - on-device20  - gguf21  - ollama22  - vllm23  - text-generation-inference24  - doocs-leetcode25  - synthetic-verification26  - quantized27  - algorithms28language:29  - en30library_name: peft31pipeline_tag: text-generation32datasets:33  - AmareshHebbar/leetcode-codegen-javascript34co2_eq_emissions:35  emissions: 036  source: "estimate, not measured with a carbon-tracking tool"37  training_type: "fine-tuning"38  geographical_location: "EU-West"39  hardware_used: "NVIDIA A40 (48GB)"40model-index:41  - name: leetcode-javascript-qwen25-coder-7b42    results: []43---44 45<div align="center">46 47# ๐ŸŸจ LeetCode JavaScript Coder48### Qwen2.5-Coder-7B, QDoRA fine-tuned to solve LeetCode problems in JavaScript49 50[![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Model-leetcode--javascript--qwen25--coder--7b-FFD21E)](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b)51[![Dataset](https://img.shields.io/badge/%F0%9F%A4%97%20Dataset-leetcode--codegen--javascript-blue)](https://huggingface.co/datasets/AmareshHebbar/leetcode-codegen-javascript)52[![GGUF](https://img.shields.io/badge/GGUF-quantized-6f42c1)](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF)53[![License](https://img.shields.io/badge/license-Apache%202.0-green)](https://www.apache.org/licenses/LICENSE-2.0)54[![Base Model](https://img.shields.io/badge/base-Qwen2.5--Coder--7B-orange)](https://huggingface.co/unsloth/Qwen2.5-Coder-7B-Instruct)55[![Method](https://img.shields.io/badge/method-QDoRA-critical)](#why-qdora)56[![Ollama](https://img.shields.io/badge/-Ollama-000000?logo=ollama)](#ollama)57[![vLLM](https://img.shields.io/badge/-vLLM-333333)](#vllm)58[![TGI](https://img.shields.io/badge/-TGI-yellow)](#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 64---65 66## TL;DR67 68Given a LeetCode-style problem statement, its sample input/output, and an algorithm tag, generates a working JavaScript solution.69 70```71PROBLEM:   Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.72ALGORITHM: Hash Map73OUTPUT (JavaScript):74var twoSum = function(nums, target) {75    const seen = new Map();76    for (let i = 0; i < nums.length; i++) {77        if (seen.has(target - nums[i])) return [seen.get(target - nums[i]), i];78        seen.set(nums[i], i);79    }80    return [];81};82```83 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-codegen-javascript](https://huggingface.co/datasets/AmareshHebbar/leetcode-codegen-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 99DoRA 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 101Concretely, versus the plain-QLoRA v1 release of this suite: DoRA adds a per-column102trainable magnitude vector on top of the usual low-rank direction update, so the103adapter can rescale a feature's importance instead of only rotating it. On a code104task where a single wrong operator or dropped edge case fails the whole solution,105that closer match to full fine-tuning's update pattern showed up as fewer106near-miss failures during our own qualitative review, at the same LoRA rank and107VRAM budget.108 109```python110# training-side PEFT config (see build_language_datasets.py / trainer script for full pipeline)111from peft import LoraConfig112 113peft_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 QLoRA119    task_type="CAUSAL_LM",120)121```122 123---124 125## Benchmarks (free, reproducible)126 127Run `benchmark_suite.py` from the deployment kit to reproduce. All numbers are pass@1 unless noted.128 129| Benchmark | Language | Pass@1 | Pass@10 | Notes |130|---|---|---|---|---|131| [HumanEval-X](https://huggingface.co/datasets/THUDM/humaneval-x) | JavaScript | 70.0% | _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-codegen-javascript` test split, exact I/O match |134| Tokens/sec (fp16, GPU) | JavaScript | โ€” | โ€” | latency benchmark |135| Tokens/sec (GGUF q4_k_m) | JavaScript | โ€” | โ€” | latency benchmark |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 141## Intended use142 143Drop-in solution generator for JavaScript coding-practice tools, interview-prep apps, and automated code-review sandboxes for algorithmic problems.144 145### Direct use146Give a problem statement (+ optional algorithm hint), get back a JavaScript function/class implementing it.147 148### Downstream use149Feed output into an automated grader (run against test cases), a code-review bot, or a practice-app "show solution" feature.150 151### Out of scope152- Production system design or non-algorithmic code (this model specializes narrowly on LeetCode-style problems)153- Security-critical code without human review154- Guaranteed-optimal complexity โ€” treat output as a strong first draft, not a proof155 156---157 158## Quickstart159 160### Option A โ€” Transformers + PEFT161 162```python163from transformers import AutoModelForCausalLM, AutoTokenizer164from peft import PeftModel165import torch166 167base_model = "unsloth/Qwen2.5-Coder-7B-Instruct"168adapter    = "AmareshHebbar/leetcode-javascript-qwen25-coder-7b"169 170tokenizer = AutoTokenizer.from_pretrained("AmareshHebbar/leetcode-javascript-qwen25-coder-7b")171model = AutoModelForCausalLM.from_pretrained(172    base_model,173    torch_dtype=torch.bfloat16,174    device_map="auto",175)176model = PeftModel.from_pretrained(model, adapter)177 178messages = [179    {"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."},180    {"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"},181]182inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)183outputs = model.generate(inputs, max_new_tokens=512, temperature=0.2, do_sample=True)184print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))185```186 187### Batch inference (many problems at once)188 189```python190problems = [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 196prompts = [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 problems202]203tokenizer.padding_side = "left"204batch = tokenizer(prompts, return_tensors="pt", padding=True).to(model.device)205outputs = model.generate(**batch, max_new_tokens=512, temperature=0.2, do_sample=True)206for 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```python214from transformers import TextIteratorStreamer215from threading import Thread216 217streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)218gen_kwargs = dict(input_ids=inputs, max_new_tokens=512, temperature=0.2, do_sample=True, streamer=streamer)219Thread(target=model.generate, kwargs=gen_kwargs).start()220for token in streamer:221    print(token, end="", flush=True)222```223 224### Structured JSON output (code + complexity + explanation)225 226```python227json_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)232messages = [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]236inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)237outputs = model.generate(inputs, max_new_tokens=512, temperature=0.1, do_sample=True)238raw = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)239 240import json241result = json.loads(raw.strip().removeprefix("```json").removesuffix("```").strip())242print(result["code"])243print(result["time_complexity"], result["space_complexity"])244```245 246### Option B โ€” Unsloth (2x faster load + inference)247 248```python249from unsloth import FastLanguageModel250 251model, tokenizer = FastLanguageModel.from_pretrained(252    model_name="AmareshHebbar/leetcode-javascript-qwen25-coder-7b",253    max_seq_length=2048,254    load_in_4bit=True,255)256FastLanguageModel.for_inference(model)257 258messages = [259    {"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."},260    {"role": "user", "content": "Problem: Given a string s, find the length of the longest substring without repeating characters.\nAlgorithm: two pointers / sliding window"},261]262prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)263inputs = tokenizer(prompt, return_tensors="pt").to("cuda")264outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.2, do_sample=True)265print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))266```267 268### Option C โ€” vLLM (production serving, OpenAI-compatible) {#vllm}269 270```bash271vllm serve unsloth/Qwen2.5-Coder-7B-Instruct \272    --enable-lora \273    --lora-modules leetcode-javascript-qwen25-coder-7b=AmareshHebbar/leetcode-javascript-qwen25-coder-7b \274    --host 0.0.0.0 --port 8000 --dtype bfloat16275```276 277```python278from openai import OpenAI279 280client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")281response = client.chat.completions.create(282    model="leetcode-javascript-qwen25-coder-7b",283    messages=[284        {"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."},285        {"role": "user", "content": "Problem: Merge two sorted linked lists into one sorted list.\nAlgorithm: linked list, dummy head"},286    ],287    temperature=0.2,288)289print(response.choices[0].message.content)290```291 292Streaming with vLLM's OpenAI-compatible endpoint:293```python294stream = 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)299for 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```bash307docker run --gpus all --shm-size 1g -p 8080:80 \308    -v $PWD/data:/data ghcr.io/huggingface/text-generation-inference:latest \309    --model-id unsloth/Qwen2.5-Coder-7B-Instruct \310    --lora-adapters leetcode-javascript-qwen25-coder-7b=AmareshHebbar/leetcode-javascript-qwen25-coder-7b311```312 313```bash314curl 127.0.0.1:8080/generate_stream \315    -X POST \316    -d '{"inputs":"<|im_start|>system\nYou are an expert JavaScript competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient JavaScript 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}}' \317    -H 'Content-Type: application/json'318```319 320### Option E โ€” Ollama (local, mobile/edge-friendly) {#ollama}321 322```bash323# 1. Pull the GGUF build324huggingface-cli download AmareshHebbar/leetcode-javascript-qwen25-coder-7b-GGUF leetcode-javascript-qwen25-coder-7b.q4_k_m.gguf --local-dir .325 326# 2. Create the model from the Modelfile shipped in the deployment kit (see deploy_ollama.py)327ollama create leetcode-javascript-qwen25-coder-7b -f Modelfile.javascript328 329# 3. Run it330ollama 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 333Python client against a local Ollama server:334```python335import requests336r = 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})341print(r.json()["response"])342```343 344### Option F โ€” GGUF / llama.cpp direct (mobile/edge inference)345 346```bash347./llama-cli -m leetcode-javascript-qwen25-coder-7b.q4_k_m.gguf \348    -p "<|im_start|>system\nYou are an expert JavaScript competitive programmer. Given a LeetCode-style problem statement and an algorithm tag, write a correct, efficient JavaScript 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" \349    -n 512 --temp 0.2350```351 352See `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).353 354---355 356## Training details357 358### Why this base model359 360Qwen2.5-Coder-7B-Instruct was chosen over a general instruct model because its361pretraining already concentrates capacity on code โ€” the QDoRA adapter only has to362specialize output format and LeetCode-specific conventions (function signatures,363in-place vs. new-array conventions, JavaScript idioms) rather than teach the model364to code from scratch. 7B was picked as the size that still fits comfortably in a365single-GPU QDoRA run while keeping enough headroom that the base model's code366reasoning survives adaptation.367 368### Data pipeline369 370Source: [doocs/leetcode](https://github.com/doocs/leetcode), 3,977 problems with371English documentation. Each problem can have multiple solutions spanning different372algorithm tags (greedy, DP, two pointers, etc.) โ€” the pipeline treats this as a373one-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 382execution-checked against sample I/O (see dataset card for exact rate). Full extraction/verification/build code lives alongside the383[leetcode-codegen-javascript](https://huggingface.co/datasets/AmareshHebbar/leetcode-codegen-javascript) dataset card.384 385### Hyperparameters386 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 |398 399### Training compute400 401| | |402|---|---|403| **GPU** | NVIDIA A40 (48GB) |404| **Cloud provider** | RunPod |405| **CO2 estimate** | self-reported, not measured with a carbon tracker โ€” treat as approximate |406 407Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) + TRL's `SFTTrainer`,408DoRA enabled via PEFT.409 410---411 412## Bias, risks & limitations413 414**Narrow specialization.** This model is tuned tightly on LeetCode-style algorithmic problems โ€” general software-engineering code (frameworks, infra, business logic) is out of distribution.415 416**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.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## FAQ425 426**Q: Can I merge the adapter into the base model?**427Yes โ€” `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?**430See [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?**433Qwen2.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?**436q4_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?**439No โ€” inference runs entirely on whatever infrastructure you deploy it to.440 441---442 443## Related models in this suite444 445| Model | Language |446|---|---|447| [leetcode-python-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-python-qwen25-coder-7b) | Python |448| [leetcode-java-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-java-qwen25-coder-7b) | Java |449| [leetcode-cpp-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-cpp-qwen25-coder-7b) | C++ |450| [leetcode-javascript-qwen25-coder-7b](https://huggingface.co/AmareshHebbar/leetcode-javascript-qwen25-coder-7b) | JavaScript (this model) |451 452**Full collection:** [LeetCode Multi-Language Coder Suite](https://huggingface.co/collections/AmareshHebbar/leetcode-multi-language-coder-suite)453 454---455 456## Changelog457 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 466## Citation467 468```bibtex469@misc{leetcodecoder2026,470  author    = {Hebbar, Amaresh},471  title     = {LeetCode Multi-Language Coder Suite},472  year      = {2026},473  publisher = {HuggingFace},474  url       = {https://huggingface.co/AmareshHebbar}475}476```477 478## Contact479 480[![GitHub](https://img.shields.io/badge/GitHub-amareshhebbar-181717?logo=github)](https://github.com/amareshhebbar)481[![LinkedIn](https://img.shields.io/badge/LinkedIn-gvamaresh-0A66C2?logo=linkedin)](https://www.linkedin.com/in/gvamaresh)482[![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Profile-AmareshHebbar-FFD21E)](https://huggingface.co/AmareshHebbar)483