Naholav/CodeGen-Deep-5K
Viewer • Updated • 5k • 97
How to use zeynepelif/Qwen2.5-Coder-1.5B-LORA-DEEP with PEFT:
Task type is invalid.
This model is a fine-tuned version of Qwen/Qwen2.5-Coder-1.5B-Instruct on the Deep dataset using LoRA (Low-Rank Adaptation). It was developed as a NLP Lecture project to evaluate the capabilities Small Language Models on specific coding tasks.
peft, trl, transformers, torchThe model was fine-tuned on the [Naholav/CodeGen-Deep-5K] dataset.
The following hyperparameters were used during training (as per project requirements):
The model achieved the following loss values during training, showing no signs of overfitting:
| Metric | Value |
|---|---|
| Final Training Loss | 0.139 |
| Final Validation Loss | 0.183 |
You can load this model using peft and transformers. Ensure you use device_map="cuda" for GPU usage.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# 1. Load Base Model
base_model_name = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
adapter_model_name = "zeynepelif/Qwen2.5-Coder-1.5B-LORA-DEEP"
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype=torch.float16,
device_map="cuda"
)
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
# 2. Load LoRA Adapter
model = PeftModel.from_pretrained(base_model, adapter_model_name)
model.to("cuda")
model.eval()
# 3. Generate Code
def ask_model(question):
messages = [
{"role": "system", "content": "You are an expert Python programmer."},
{"role": "user", "content": question}
]
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(inputs, max_new_tokens=512, temperature=0.2, do_sample=True)
print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
ask_model("Write a Python function to check if a number is palindrome.")
Base model
Qwen/Qwen2.5-1.5B