Instructions to use AyushPatel28/PyExplain-qwen-coder-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use AyushPatel28/PyExplain-qwen-coder-7b with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct") model = PeftModel.from_pretrained(base_model, "AyushPatel28/PyExplain-qwen-coder-7b") - Notebooks
- Google Colab
- Kaggle
PyExplain β Qwen2.5-Coder-7B (LoRA adapter)
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
How to use
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))
- Downloads last month
- 13