Downloads · 30 days
13
24% of all-time downloads
nvhuynh16/gemma-2b-code-alpaca-best
gemma-2b-code-alpaca-best is a text generation model from nvhuynh16. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as gemma.
Fine-tuned Google Gemma 2B model for code generation using QLoRA on the CodeAlpaca dataset.
Downloads · 30 days
13
24% of all-time downloads
All-time downloads
54
Public
Repo size
77.4 MB
Likes
0
Public
Click a slice to open those files.
.json34.5 MB · 44%
From the Hugging Face model README
Fine-tuned Google Gemma 2B model for code generation using QLoRA on the CodeAlpaca dataset.
Evaluated on 100 test samples from CodeAlpaca (72 Python, 28 other languages):
| Metric | Baseline | Fine-tuned | Improvement |
|---|---|---|---|
| BLEU Score | 11.00 | 16.83 | +53% ✅ |
| Syntax Correctness | 81% | 76% | -5% |
Key Achievement: 53% improvement in code similarity (BLEU score), demonstrating the model learned to generate code closer to reference solutions.
Head-to-Head Comparison (Python tasks only):
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2-2b-it",
device_map="auto",
torch_dtype=torch.float16,
load_in_4bit=True
)
# Load fine-tuned adapter
model = PeftModel.from_pretrained(base_model, "nvhuynh16/gemma-2b-code-alpaca-best")
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b-it")
# Generate code
instruction = "Write a function to check if a number is prime"
prompt = f"""### Instruction:
{instruction}
### Input:
### Response:
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
top_p=0.9,
do_sample=True
)
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(code.split("### Response:")[-1].strip())
Instruction: Write a function to check if a number is prime
Generated Code:
def is_prime(num):
if num <= 1:
return False
for i in range(2, num):
if num % i == 0:
return False
return True
Primarily trained on:
The model was evaluated on a held-out test set of 100 examples from CodeAlpaca:
BLEU scores were calculated using SacreBLEU with smoothing to measure code similarity to reference implementations.
This model is based on Gemma 2B and follows the Gemma License.
@misc{gemma-2b-code-alpaca-best,
title={Gemma 2B Code Generation - Fine-tuned},
author={nvhuynh16},
year={2025},
publisher={HuggingFace},
howpublished={\url{https://huggingface.co/nvhuynh16/gemma-2b-code-alpaca-best}}
}