CodePilot Local (1.5B) — Offline Python Code Review & Security Auditor (Q4_K_M GGUF + QLoRA)
CodePilot Local (dev-ahmad/codepilot-local-1.5b) is a specialized fine-tune of Qwen/Qwen2.5-Coder-1.5B-Instruct built for the Qwen Local Hackathon 2026 (Qwen Pakistan). It transforms a compact 1.5B parameter coding model into a deterministic, 100% offline static analysis and code review engine that outputs strict, machine-parseable JSON diagnostics (line, category, severity, issue, fix) while running in under 1.2 GB of RAM on everyday laptops.
- GitHub Repository & CLI / IDE Demo:
https://github.com/Ahmad1845/codepilot-local - Author: Muhammad Ahmad (
dev-ahmad) - Quantized GGUF Artifact:
Qwen2.5-Coder-1.5B-Instruct.Q4_K_M.gguf(940.4 MB) - QLoRA Adapter Weights:
codepilot-1.5b-adapter/adapter_model.safetensors(73.9 MB,r=16, lora_alpha=32) - Real-World Curated Dataset:
data/train_real.jsonl,data/val_real.jsonl,data/test_real.jsonl(4,546 AST-verified Python samples)
1. Why CodePilot Local? (The Real Problem Solved)
- Privacy & Air-Gapped Security: Enterprise and student developers frequently cannot send proprietary source code or credentials to cloud LLM APIs. CodePilot Local runs 100% on-device with zero network egress.
- Deterministic JSON for CI/CD & IDE Tooling: Base
Qwen2.5-Coder-1.5B-Instructfrequently wraps answers in conversational Markdown prose (31.7%parse failure rate in automated pipelines) and over-flags clean code (18.5%false positive rate). After QLoRA fine-tuning, CodePilot Local achieves 100.0% Valid JSON Schema Adherence (240/240) and reduces false positives on clean code to1.67%.
2. Before vs. After Benchmark Results (N = 240 Held-Out Evaluation Suite)
| Metric | Base Qwen2.5-Coder-1.5B-Instruct | Fine-Tuned codepilot-local-1.5b (Q4_K_M) | Delta |
|---|---|---|---|
| Valid JSON Output Rate | 68.3% (164/240) | 100.0% (240/240) | +31.7% |
| Clean-Code False Positive Rate | 18.5% | 1.67% | -16.6% |
| Security Vulnerability Recall | 54.0% | 89.4% | +35.4% |
| Line Localization Accuracy (±2 lines) | 49.2% | 86.8% | +37.6% |
| Overall Defect Detection F1 | 0.584 | 0.887 | +0.303 |
| Model Size on Disk | 3.20 GB (FP16) | 940.4 MB (Q4_K_M GGUF) | -70.6% |
| Peak Runtime Memory (RAM) | ~3.80 GB | ~1.15 GB | -69.7% |
3. Quickstart: Run Locally in 30 Seconds
Option A: Ollama (Direct from Hugging Face or Local Modelfile)
# Run directly via Ollama
ollama run hf.co/dev-ahmad/codepilot-local-1.5b
# Or clone and create from the included Modelfile (pre-configured with strict JSON system prompt & temperature 0.1)
git clone https://huggingface.co/dev-ahmad/codepilot-local-1.5b
cd codepilot-local-1.5b
ollama create codepilot-local -f Modelfile
ollama run codepilot-local
Option B: llama.cpp (llama-cli / llama-server)
./llama-cli -m Qwen2.5-Coder-1.5B-Instruct.Q4_K_M.gguf \
-c 2048 --temp 0.1 -ngl 99 \
-sys "You are an expert Python code reviewer. Review the provided code snippet for security vulnerabilities, bugs, performance issues, error handling flaws, and resource leaks. Return ONLY valid JSON matching the required schema with line numbers, category, severity, issue description, and fix. Return only raw JSON string, NO markdown code blocks." \
-p "Review this Python code snippet:\n\`\`\`python\n 1 | import subprocess\n 2 | def run_cmd(user_input):\n 3 | subprocess.call(user_input, shell=True)\n\`\`\`"
Option C: Expected JSON Output Schema
{
"findings": [
{
"line": 3,
"category": "security",
"severity": "high",
"issue": "Executing subprocess.call with shell=True on untrusted user_input enables arbitrary OS command injection.",
"fix": "Pass arguments as a tokenized list (`shlex.split(user_input)`) with `shell=False`."
}
]
}
When auditing clean, idiomatic code, the model deterministically outputs:
{
"findings": []
}
4. Real-World Dataset & QLoRA Training Details
Multi-Source Real Dataset (4,546 AST-Verified Samples)
Included directly in this repository under data/:
data/train_real.jsonl(3,540 samples)data/val_real.jsonl(439 samples)data/test_real.jsonl(567 samples)data/DATASET_CARD.md(Full provenance, AST cleaning methodology, and anti-leakage verification)
Data Sources:
CyberNative/Code_Vulnerability_Security_DPO(Hugging Face): Real Python vulnerability & patched fix pairs.Dahoas/base_code_review(Hugging Face): Real StackExchange Python code review critiques, HTML-sanitized and AST-validated.- Production Open-Source Python Repositories (
psf/requests,pallets/flask,encode/httpx,tiangolo/fastapi,urllib3/urllib3,pallets/werkzeug): Real production functions extracted via Pythonastwith exact line-numbered defect localization.
QLoRA Hyperparameters & Loss Progression
- Framework: Unsloth + Hugging Face TRL (
SFTTrainer) + PEFT - Quantization: 4-bit NF4 during training -> Merged 16-bit -> Quantized to
Q4_K_MGGUF viallama.cpp - Target Modules:
q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj - Training Loss: Dropped from
2.5471(Step 10) to0.0156(Step 567, Epoch 3.0) - Best Validation Loss (
eval_loss):0.5994