Views
No views yet
A fine-tuned Qwen2.5-Coder-7B-Instruct model trained to guide students through programming problems — never giving away answers, always teaching.
| Field | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-Coder-7B-Instruct |
| Fine-tuning Method | LoRA (r=16, alpha=32) |
| Training | 3 epochs, 1585 examples |
| Languages Supported | Python, Java, C, C++ |
| Task | Socratic code mentoring / tutoring |
| License | MIT |
Python >= 3.9
RAM >= 8GB
Storage >= 5GB (model download, cached after first run)
GPU: Optional (runs on CPU too, slower)pip install transformers bitsandbytes accelerate torch1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2import torch
3
4HF_MODEL = "likithyadavv/codementor-7b"
5HF_TOKEN = "your_hf_read_token" # from huggingface.co/settings/tokens
6
7bnb_config = BitsAndBytesConfig(
8 load_in_4bit=True,
9 bnb_4bit_quant_type="nf4",
10 bnb_4bit_compute_dtype=torch.float16,
11)
12
13print("Loading CodeMentor... (first run downloads ~4GB, cached after)")
14tokenizer = AutoTokenizer.from_pretrained(HF_MODEL, token=HF_TOKEN)
15model = AutoModelForCausalLM.from_pretrained(
16 HF_MODEL,
17 quantization_config=bnb_config,
18 device_map="auto",
19 token=HF_TOKEN
20)
21print("Ready!\n")
22
23def ask(instruction, code, language="Python"):
24 prompt = f"""### System:
25You are CodeMentor — a sharp, patient programming tutor for Python, Java, C, and C++.
26You NEVER give away full solutions. Guide step by step.
27
28### Instruction:
29{instruction}
30
31### Input:
32[Language: {language}]
33{code}
34
35### Response:
36"""
37 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
38 with torch.no_grad():
39 outputs = model.generate(
40 **inputs,
41 max_new_tokens=300,
42 do_sample=True,
43 temperature=0.7,
44 top_p=0.9,
45 repetition_penalty=1.2,
46 )
47 full = tokenizer.decode(outputs[0], skip_special_tokens=True)
48 return full.split("### Response:")[-1].strip()
49
50while True:
51 print("\n" + "="*40)
52 lang = input("Language (Python/Java/C/C++): ").strip() or "Python"
53 question = input("Your question: ").strip()
54 code = input("Your code (press Enter to skip): ").strip()
55 print(f"\n🤖 CodeMentor:\n{ask(question, code or 'None', lang)}")