Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load base model and tokenizer
5base_model = AutoModelForCausalLM.from_pretrained(
6 "Qwen/Qwen1.5-1.8B",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B")
10
11# Load LoRA adapter
12model = PeftModel.from_pretrained(base_model, "[YOUR_MODEL_PATH]")
13
14# Generate code with reasoning
15prompt = "Write a Python function to find the longest common prefix in a list of strings."
16inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
17outputs = model.generate(**inputs, max_new_tokens=512)
18print(tokenizer.decode(outputs[0], skip_special_tokens=True))| Metric | Base Model (Qwen 1.5 1.8B) | Fine-tuned Model |
|---|---|---|
| Pass@1 | 75% | 100% |
| Reasoning Structure | Inconsistent | 100% |
1@misc{qwen15-code-reasoning,
2 author = {[Rachit Verma]},
3 title = {Qwen 1.5 1.8B Fine-tuned for Python Code Generation with Reasoning},
4 year = {2025},
5 publisher = {HuggingFace},
6}