Downloads · 30 days
5
11% of all-time downloads
AyushPatel28/PyExplain-qwen-coder-7b
PyExplain-qwen-coder-7b is a text generation model from AyushPatel28. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as mit.
A LoRA adapter that fine-tunes Qwen/Qwen2.5-Coder-7B-Instruct to explain Python code in plain, beginner-friendly English — it gives the overall purpose, then walks through the code part by part, explaining each progra…
Downloads · 30 days
5
11% of all-time downloads
All-time downloads
45
Public
Repo size
31.6 MB
Likes
0
Public
Click a slice to open those files.
.safetensors20.2 MB · 64%
From the Hugging Face model README
A LoRA adapter that fine-tunes
Qwen/Qwen2.5-Coder-7B-Instruct
to explain Python code in plain, beginner-friendly English — it gives the
overall purpose, then walks through the code part by part, explaining each
programming term as it goes (for someone with zero Python knowledge).
Part of the PyExplain project. 👉 Code & full pipeline: https://github.com/AyushPatel2803/PyExplain
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
BASE = "Qwen/Qwen2.5-Coder-7B-Instruct"
ADAPTER = "AyushPatel28/PyExplain-qwen-coder-7b"
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16)
tok = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(BASE, quantization_config=bnb, device_map="auto")
model = PeftModel.from_pretrained(model, ADAPTER)
code = "def reverse(s):\n return s[::-1]"
msgs = [{"role": "system", "content": "Explain Python code simply and accurately."},
{"role": "user", "content": f"Explain this code:\n```python\n{code}\n```"}]
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
inputs = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
out = model.generate(**inputs, max_new_tokens=300, do_sample=False)
print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))