A QLoRA-fine-tuned LoRA adapter for CodeLlama-7B-Instruct, trained to generate inline code review comments on Python pull requests. This is the v1 prototype from a larger project that ships the model behind a FastAPI + GitHub App + Kubernetes deployment.
⚠️ This is a v1 prototype. It catches some code review patterns (e.g., missing context managers) but misses others (e.g., SQL injection). See the Evaluation section for honest failure modes. Not production-ready. A v2 trained with Unsloth on more data is planned — see the project repo.
Both positive examples (real reviews) and negative examples (is_negative=True, "No issues found") were kept so the model learns when code is fine and doesn't need a comment.
### Instruction:
You are a senior code reviewer. Compare the before and after versions of the code below. Identify potential issues and provide improvement suggestions.
### File: {file_path}
### Before:
{before_code}
### After:
{after_code}
### Review:
{reviewer_comment}
At inference, everything after ### Review: is generated.
How to Use
python
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
45BASE_MODEL ="codellama/CodeLlama-7b-Instruct-hf"6ADAPTER_REPO ="zenlyst/codellama-7b-pr-review-lora-v1"# replace after upload78# 4-bit load (matches training-time quantization)9bnb_config = BitsAndBytesConfig(10 load_in_4bit=True,11 bnb_4bit_quant_type="nf4",12 bnb_4bit_compute_dtype=torch.float16,13 bnb_4bit_use_double_quant=True,14)1516tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)17base = AutoModelForCausalLM.from_pretrained(18 BASE_MODEL,19 quantization_config=bnb_config,20 device_map="auto",21)22model = PeftModel.from_pretrained(base, ADAPTER_REPO)23model.eval()2425PROMPT ="""### Instruction:
26You are a senior code reviewer. Compare the before and after versions of the code below. Identify potential issues and provide improvement suggestions.
2728### File: {file_path}
2930### Before:
31{before_code}
3233### After:
34{after_code}
3536### Review:
37"""3839before ="""def parse_config(path):
40 with open(path) as f:
41 data = json.load(f)
42 return data"""4344after ="""def parse_config(path):
45 with open(path) as f:
46 data = yaml.safe_load(f)
47 return data"""4849prompt = PROMPT.format(file_path="utils/parser.py", before_code=before, after_code=after)50inputs = tokenizer(prompt, return_tensors="pt").to(model.device)5152with torch.no_grad():53 out = model.generate(54**inputs,55 max_new_tokens=512,56 temperature=0.7,57 top_p=0.9,58 do_sample=True,59 repetition_penalty=1.1,60)6162review = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)63print(review.strip())
Requirements:transformers, peft, bitsandbytes, accelerate, torch. Requires a CUDA GPU for 4-bit loading (bitsandbytes does not support macOS).
Evaluation
Evaluated on 3 hand-crafted Python code review cases covering error handling, security, and resource management. Scoring is qualitative (Good / Shallow / Failed) — this is a prototype eval, not a benchmark.
Summary
Test
Category
Verdict
JSON → YAML migration (no error handling)
Imports / error handling
❌ Shallow
SQL query without parameterization
🔐 Security
❌ Failed
Missing resource cleanup (open() without with)
Resource management
✅ Good
Overall: 1 / 3 useful reviews.
Case 1 — JSON to YAML migration (❌ Shallow)
Code switches json.load to yaml.safe_load without adding import yaml or yaml.YAMLError handling.
Model output:
import yaml
Analysis: Caught the missing import but missed the more important issues — no error handling for malformed YAML and no consideration of the silent format migration impact on callers.
Case 2 — SQL injection via f-string (❌ Failed)
Code uses cursor.execute(f'SELECT * FROM users WHERE id = {user_id}') — a textbook SQL injection vulnerability.
Model output:
cursor.execute(f'SELECT * FROM users WHERE id = {user_id} AND active = 1')
Analysis: The model echoed the code back without identifying the SQL injection vulnerability. This is the most critical failure — security issues should be high-priority review items. Likely root causes: (1) SQL injection patterns are under-represented in 10K random samples, (2) one epoch may be insufficient for the model to consolidate rare security patterns.
Case 3 — Missing context manager on file handle (✅ Good)
Code replaces with open(dest, 'wb') as f: with a bare f = open(dest, 'wb'), losing automatic close on exception.
Model output:
The requests module allows streaming of responses using the stream parameter. This means that we can read the content in chunks without loading it all into memory at once. In this case, we could use a context manager to ensure the file is properly closed after writing. Here's an example of how to implement this:
python
1withopen(dest,'wb')as f:2for chunk in response.iter_content(8192):3 f.write(chunk)
Analysis: Correctly identified the missing context manager, explained why it matters, and provided the fix. This is the quality level the model aims for across all reviews.
Limitations and Biases
Python only. The model has not been trained on or evaluated against any other language.
Misses security issues. v1 failed to identify SQL injection in evaluation. Do not rely on this model for security review.
Shallow on multi-issue diffs. The model tends to surface one issue per review even when multiple exist.
Small eval set. Three hand-crafted cases is not a benchmark. Real-world performance will vary.
Training data bias. Inherits biases of the ronantakizawa/github-codereview dataset — mostly open-source Python projects on GitHub. Code styles and review conventions from other ecosystems (enterprise, other languages, non-English projects) are underrepresented.
Prototype only. Not validated at scale, not safety-reviewed, not aligned for adversarial inputs.
Known Failure Modes (short list)
SQL injection via f-string interpolation — missed entirely in eval
Silent API migrations (e.g., JSON→YAML) — flags imports but misses behavioral implications
Echoes code back as "suggestion" without explaining issues
Single-line suggestions even when multi-line refactors are needed
Roadmap
A v2 adapter is in progress, targeting the v1 failure modes with:
Training stack migration to Unsloth for ~2× speedup at identical accuracy
15K samples × 2 epochs (up from 10K × 1) within the same compute budget
Expanded 10-case eval set including security, error handling, mutability, and performance cases
If you use this adapter, please cite the underlying dataset and base model:
bibtex
1@misc{codellama-7b-pr-review-lora-v1,
2 title = {CodeLlama-7B PR Review LoRA Adapter (v1)},
3 author = {Sherry Liu},
4 year = {2026},
5 howpublished = {\url{https://huggingface.co/zenlyst/codellama-7b-pr-review-lora-v1}},
6 note = {LoRA adapter fine-tuned via QLoRA on ronantakizawa/github-codereview}
7}
Base model:
bibtex
1@misc{roziere2023code,
2 title = {Code Llama: Open Foundation Models for Code},
3 author = {Baptiste Rozière and Jonas Gehring and Fabian Gloeckle and others},
4 year = {2023},
5 eprint = {2308.12950},
6 archivePrefix= {arXiv}
7}