Skip to content

Latest commit

Β 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”¬ Code Autopsy

A QLoRA fine-tuned code review model based on Qwen2.5-Coder-7B-Instruct.
Paste buggy code β†’ get a structured analysis: bug ID, root cause, and auto-fix.

πŸ€— Model Β Β·Β  🧩 LoRA Adapter Β Β·Β  πŸš€ Live Demo Β Β·Β  πŸ“Š W&B Run


πŸ–₯️ Interactive Review Interface

Code Autopsy Diagnostic Report Interface
Code Autopsy Diagnostic Report: Automated bug identification (mutable default argument), root cause breakdown, 92.3% confidence score, and optimized code generation.

Code Autopsy Neural Inference State
Real-Time Inference State: Live neural diagnostics runner analyzing Python source code with animated status spinner.


Architecture

flowchart LR
    A["πŸ› Buggy Code\n(Python / JS)"] --> B["FastAPI\n/review"]
    B --> C["Qwen2.5-Coder-7B\n+ LoRA Adapter\n4-bit NF4"]
    C --> D["Structured Output"]
    D --> E1["πŸ› Bug Identified"]
    D --> E2["πŸ” Root Cause"]
    D --> E3["βœ… Fixed Code"]
    D --> E4["πŸ“Š Confidence"]

    F["Gradio UI\n(HF Spaces)"] -->|"POST /review\nvia API_URL"| B
    G["Ollama\n(local GGUF)"] -->|alternative| C
Loading

Results

Quantitative: sacreBLEU (n=20)

Model BLEU Score Ξ” vs Base
Base (Qwen2.5-Coder-7B) 10.63 β€”
Code Autopsy (fine-tuned) 70.03 +59.40 (+558%)

Fine-tuned in 1 epoch on an RTX 5060 (8 GB VRAM) using 4-bit NF4 QLoRA.

BLEU Comparison

Training Convergence

Metric Value
Final train loss 0.407
Final eval loss 0.297
Eval token accuracy 92.3%
Trainable params 5.05M / 4.36B (0.12%)

Before / After Examples

Python β€” ZeroDivisionError

Code
Buggy def avg(nums): return sum(nums) / len(nums)
Fixed def avg(nums): return sum(nums) / len(nums) if nums else 0.0

Bug Identified: ZeroDivisionError when nums is an empty list.
Root Cause: No guard clause for the empty input case. len([]) returns 0, causing division by zero.


Python β€” Mutable Default Argument

Code
Buggy def append(val, lst=[]): lst.append(val); return lst
Fixed def append(val, lst=None): if lst is None: lst = []; lst.append(val); return lst

Bug Identified: Mutable default argument lst=[] is shared across all calls.
Root Cause: Python evaluates default arguments once at function definition time, not per-call.


JavaScript β€” Missing await

Code
Buggy const data = response.json(); return data.name;
Fixed const data = await response.json(); return data.name;

Bug Identified: response.json() returns a Promise, not the parsed data.
Root Cause: Response.json() is asynchronous β€” without await, data holds the Promise object.


JavaScript β€” var Closure in Loop

Code
Buggy for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); }
Fixed for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 100); }

Bug Identified: Prints 3, 3, 3 instead of 0, 1, 2.
Root Cause: var is function-scoped; all closures share the same i. Replace with let (block-scoped).


Quick Start (Windows)

1. Double-click INSTALL.bat    ← sets up venv + installs everything
2. Fill in your keys in .env
3. Double-click Run_Project.bat ← starts API + UI, opens browser

Local Setup (Manual)

1. Clone & install

git clone https://github.com/Ares19v/Code-Autopsy.git
cd Code-Autopsy

python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate

# Install PyTorch first (match your CUDA version)
pip install torch --index-url https://download.pytorch.org/whl/cu124

pip install -r requirements.txt

2. Configure environment

cp .env.example .env
# Fill in: HF_TOKEN, WANDB_API_KEY, GEMINI_API_KEY

3. Prepare dataset

# Dry-run first (no downloads, validates formatting logic)
python data/prepare_dataset.py --dry-run

# Full run (~20k examples, downloads ~5GB)
python data/prepare_dataset.py --max-samples 20000

4. Train

# Debug: 1 step, no W&B (validates VRAM fits)
python training/train.py --debug

# Full training run (1 epoch, logs to W&B)
python training/train.py

5. Evaluate

# sacreBLEU: base vs fine-tuned
python eval/eval_codebleu.py --adapter ./adapter --max-samples 20

# LLM-as-judge (100 examples, calls Gemini API)
python eval/eval_llm_judge.py --adapter ./adapter

6. Serve (FastAPI)

uvicorn serve.api:app --host 0.0.0.0 --port 8000

# Test it:
curl -X POST http://localhost:8000/review \
  -H "Content-Type: application/json" \
  -d '{"code": "def avg(x): return sum(x)/len(x)", "language": "python"}'

7. Launch Gradio demo

python demo/app.py
# Opens at http://localhost:7860

Docker

# Build and run everything (API + Demo)
docker compose up --build

# API only
docker build -f serve/Dockerfile -t code-autopsy-serve .
docker run -p 8000:8000 \
  -v $(pwd)/adapter:/app/adapter:ro \
  --env-file .env \
  --gpus all \
  code-autopsy-serve

Ollama (local GGUF)

# 1. Merge adapter + convert to GGUF
python publish.py --skip-merge=false   # creates ./merged_model/
bash convert_to_gguf.sh               # requires llama.cpp

# 2. Create & run
ollama create code-autopsy -f Modelfile
ollama run code-autopsy

Publish to HuggingFace

# Push both merged model + raw adapter
python publish.py

# Adapter only (faster, no merge step)
python publish.py --skip-merge

Project Structure

code-autopsy/
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ raw/                    # gitignored
β”‚   β”œβ”€β”€ processed/              # gitignored
β”‚   └── prepare_dataset.py
β”œβ”€β”€ training/
β”‚   β”œβ”€β”€ train.py                # SFTTrainer + QLoRA main script
β”‚   β”œβ”€β”€ config.yaml             # All hyperparameters
β”‚   └── utils.py                # Shared helpers
β”œβ”€β”€ eval/
β”‚   β”œβ”€β”€ eval_codebleu.py        # Quantitative BLEU eval
β”‚   β”œβ”€β”€ eval_llm_judge.py       # Gemini LLM-as-judge
β”‚   β”œβ”€β”€ plot_results.py         # Results chart generator
β”‚   └── results/                # Saved evaluation outputs
β”œβ”€β”€ serve/
β”‚   β”œβ”€β”€ api.py                  # FastAPI /review endpoint
β”‚   └── Dockerfile
β”œβ”€β”€ demo/
β”‚   β”œβ”€β”€ app.py                  # Gradio UI
β”‚   └── Dockerfile
β”œβ”€β”€ tests/
β”‚   └── test_utils.py           # CI unit tests (no GPU required)
β”œβ”€β”€ .github/
β”‚   └── workflows/ci.yml        # GitHub Actions CI
β”œβ”€β”€ publish.py                  # Merge + push to HF Hub
β”œβ”€β”€ Modelfile                   # Ollama config
β”œβ”€β”€ convert_to_gguf.sh          # GGUF conversion
β”œβ”€β”€ docker-compose.yml          # Full stack orchestration
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example
β”œβ”€β”€ INSTALL.bat                 # Windows one-click setup
β”œβ”€β”€ Run_Project.bat             # Windows one-click launcher
└── README.md

Hardware

Trained on an HP Omen with RTX 5060 using 4-bit NF4 quantization via BitsAndBytes.

Setting Value
GPU NVIDIA RTX 5060 (8 GB VRAM)
Quantization NF4 4-bit (BitsAndBytes)
Precision bfloat16 compute
Effective batch 16 (4 Γ— 4 grad accum)
Max seq length 512 tokens
Optimizer adamw_8bit
Epochs 1

Devansh Tyagi @ 2026

πŸ€— Model on Hugging Face

The trained model is available on Hugging Face: devanshty/Code-Autopsy

Download

from huggingface_hub import hf_hub_download
model_path = hf_hub_download(repo_id='devanshty/Code-Autopsy', filename='adapter_model.safetensors')

Β© 2026 Devansh Tyagi (Ares19v). All Rights Reserved.

About

Full-stack code review tool powered by a fine-tuned Qwen2.5 7B model. Automatically analyzes buggy code, identifies root causes, and generates syntax-accurate fixes with a Gradio interface.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages