likithyadavv commited on
Commit
ffe1b4c
·
verified ·
1 Parent(s): 9247555

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -240
README.md CHANGED
@@ -1,286 +1,141 @@
1
  ---
2
  license: apache-2.0
3
- language:
4
- - en
5
- base_model:
6
- - likithyadavv/codementor-7b
7
- pipeline_tag: text-generation
8
- library_name: transformers
9
  tags:
10
- - code
11
- - code-generation
12
- - code-explanation
13
- - bug-detection
14
- - lora
15
- - peft
16
- - 4bit
17
- - qlora
18
- - fullstack
19
- - python
20
- - javascript
21
- - fastapi
22
- - codementor
23
- metrics:
24
- - accuracy
25
  ---
26
 
27
- # 🤖 CodeMentor V2 — Fullstack AI Code Assistant
28
 
29
- > **Code Smarter. Debug Faster. Learn Better.**
30
 
31
- CodeMentor V2 is a LoRA fine-tuned large language model specialized in **fullstack code explanation, bug detection, and improvement suggestions**. Built on top of CodeLlama-7B-Instruct, it is optimized for real-time developer assistance via a REST API.
32
 
33
- ---
34
 
35
- ## 📋 Model Details
 
 
 
 
 
 
36
 
37
- | Property | Value |
38
- |---|---|
39
- | **Model Type** | Causal Language Model (LoRA Adapter) |
40
- | **Base Model** | `codellama/CodeLlama-7b-Instruct-hf` |
41
- | **Fine-Tuning Method** | QLoRA (4-bit quantization + LoRA) |
42
- | **LoRA Rank** | 16 |
43
- | **Training Framework** | HuggingFace PEFT + TRL |
44
- | **Language** | English |
45
- | **License** | Apache 2.0 |
46
- | **Adapter Size** | ~162 MB |
47
 
48
- ---
 
 
 
 
49
 
50
- ## 🎯 Intended Use
51
 
52
- CodeMentor V2 is designed for:
53
 
54
- - **Code Explanation** Understand what a block of code does in plain English
55
- - **Bug Detection** — Identify logic errors, missing base cases, off-by-ones, etc.
56
- - **Code Improvement** — Suggest better patterns, optimizations, and best practices
57
- - **Fullstack Q&A** — Answer programming questions across Python, JavaScript, and more
58
- - **Developer Mentorship** — Act as an always-available senior developer
59
 
60
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- ## 🚀 Quick Start
 
 
 
63
 
64
- ### Load with PEFT (Recommended)
 
 
65
 
66
  ```python
67
- from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
68
  from peft import PeftModel
69
  import torch
70
 
71
- # 4-bit quantization config
72
  bnb = BitsAndBytesConfig(
73
  load_in_4bit=True,
74
- bnb_4bit_compute_dtype=torch.float16
 
75
  )
76
 
77
- BASE_MODEL = "codellama/CodeLlama-7b-Instruct-hf"
78
- ADAPTER = "likithyadavv/codementor-v2-fullstack"
79
-
80
- # Load base model
81
- base_model = AutoModelForCausalLM.from_pretrained(
82
- BASE_MODEL,
83
  quantization_config=bnb,
84
- device_map="auto"
85
  )
86
 
87
- # Load LoRA adapter
88
- model = PeftModel.from_pretrained(base_model, ADAPTER)
89
- tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
90
-
91
- print("✅ CodeMentor loaded!")
92
  ```
93
 
94
- ### Run Inference
95
 
96
- ```python
97
- def ask_codementor(instruction, code_input="", max_new_tokens=512):
98
- prompt = f"### Instruction:\n{instruction}\n\n### Input:\n{code_input}\n\n### Response:\n"
99
-
100
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
101
- with torch.no_grad():
102
- outputs = model.generate(
103
- **inputs,
104
- max_new_tokens=max_new_tokens,
105
- temperature=0.2,
106
- do_sample=True,
107
- pad_token_id=tokenizer.eos_token_id,
108
- )
109
- response = tokenizer.decode(
110
- outputs[0][inputs["input_ids"].shape[1]:],
111
- skip_special_tokens=True
112
- )
113
- return response.strip()
114
-
115
- # Example usage
116
- print(ask_codementor(
117
- instruction="Explain this code and identify any bugs.",
118
- code_input="def factorial(n): return n * factorial(n-1)"
119
- ))
120
  ```
 
 
 
 
 
 
121
 
122
- **Output:**
123
- ```
124
- This is a recursive factorial function. However, it has a critical bug —
125
- there is no base case, so it will recurse infinitely and raise a
126
- RecursionError. Fix:
127
-
128
- def factorial(n):
129
- if n == 0: # ← base case added
130
- return 1
131
- return n * factorial(n - 1)
132
- ```
133
 
134
- ---
 
135
 
136
- ## 💬 Interactive Chat Loop
137
-
138
- ```python
139
- chat_history = []
140
-
141
- while True:
142
- user_input = input("\n👤 You: ").strip()
143
- if user_input.lower() in ["exit", "quit"]:
144
- break
145
-
146
- # Build context from last 3 exchanges
147
- context = ""
148
- for u, b in chat_history[-3:]:
149
- context += f"User: {u}\nAssistant: {b}\n\n"
150
-
151
- is_code = any(x in user_input for x in ["def ", "class ", "import ", "return ", "=>"])
152
- instruction = (
153
- "Explain this code, identify any bugs, and suggest improvements."
154
- if is_code else
155
- "Answer this programming question clearly and concisely."
156
- )
157
-
158
- full_input = f"{context}User: {user_input}" if context else user_input
159
- response = ask_codementor(instruction, full_input)
160
-
161
- print(f"\n🤖 CodeMentor: {response}")
162
- chat_history.append((user_input, response))
163
  ```
164
 
165
- ---
166
 
167
- ## 🌐 Deploy as REST API (FastAPI + ngrok)
 
 
168
 
169
- ```python
170
- from fastapi import FastAPI
171
- from pydantic import BaseModel
172
- import uvicorn, nest_asyncio, threading
173
- from pyngrok import ngrok
174
-
175
- app = FastAPI(title="CodeMentor API")
176
-
177
- class AskRequest(BaseModel):
178
- instruction: str
179
- input: str = ""
180
-
181
- @app.get("/")
182
- def root():
183
- return {"status": "CodeMentor API is live 🚀"}
184
-
185
- @app.get("/health")
186
- def health():
187
- return {"status": "ok"}
188
-
189
- @app.post("/ask")
190
- def ask(req: AskRequest):
191
- response = ask_codementor(req.instruction, req.input)
192
- return {"response": response}
193
-
194
- # Launch
195
- nest_asyncio.apply()
196
- public_url = ngrok.connect(8000)
197
- print(f"🚀 Live at: {public_url}/docs")
198
-
199
- threading.Thread(
200
- target=lambda: uvicorn.run(app, host="0.0.0.0", port=8000, log_level="warning"),
201
- daemon=True
202
- ).start()
203
- ```
204
 
205
- **Example curl:**
206
- ```bash
207
- curl -X POST https://YOUR-NGROK-URL/ask \
208
- -H "Content-Type: application/json" \
209
- -d '{"instruction": "Explain and fix this code", "input": "def f(n): return n*f(n-1)"}'
210
- ```
211
-
212
- ---
213
-
214
- ## 📊 Evaluation
215
-
216
- | Metric | Score |
217
- |---|---|
218
- | Code Explanation Accuracy | **92.6%** |
219
- | Bug Detection Rate | **89.3%** |
220
- | Improvement Suggestion Quality | **4.1 / 5.0** |
221
- | Avg. Response Latency (T4 GPU) | **~3.2s** |
222
-
223
- > Evaluated on a held-out set of 500 fullstack coding tasks across Python, JavaScript, and SQL.
224
-
225
- ---
226
-
227
- ## 🗂️ Training Details
228
 
229
  ```
230
- Dataset: Custom fullstack coding instruction dataset
231
- (code explanations, bug fixes, Q&A pairs)
232
- Format: Alpaca-style (### Instruction / ### Input / ### Response)
233
- Base Model: codellama/CodeLlama-7b-Instruct-hf
234
- Method: QLoRA4-bit NF4 quantization + LoRA adapters
235
- LoRA Config: r=16, alpha=32, dropout=0.05
236
- target_modules: q_proj, v_proj, k_proj, o_proj
237
- Epochs: 3
238
- Batch Size: 4 (gradient accumulation: 4)
239
- Learning Rate: 2e-4 with cosine scheduler
240
- Hardware: Google Colab A100 (40GB)
241
- Training Time: ~4 hours
242
  ```
243
 
244
- ---
245
-
246
- ## ⚙️ Hardware Requirements
247
-
248
- | Setup | Minimum | Recommended |
249
- |---|---|---|
250
- | GPU VRAM | 8 GB (4-bit) | 16 GB+ |
251
- | RAM | 12 GB | 24 GB |
252
- | GPU | T4 | A100 / RTX 3090+ |
253
- | Storage | 15 GB | 20 GB |
254
-
255
- > ✅ Runs on **free Google Colab T4** with 4-bit quantization.
256
-
257
- ---
258
-
259
- ## ⚠️ Limitations
260
-
261
- - Responses may occasionally hallucinate for very niche or obscure APIs
262
- - Best results on Python and JavaScript; other languages have lower coverage
263
- - Long code blocks (>200 lines) may exceed context window — chunk inputs
264
- - Not suitable for security-critical code auditing without human review
265
-
266
- ---
267
-
268
- ## 📚 Citation
269
-
270
- ```bibtex
271
- @misc{codementor-v2-fullstack,
272
- author = {Likith Yadav},
273
- title = {CodeMentor V2: A LoRA Fine-Tuned Fullstack Code Assistant},
274
- year = {2025},
275
- publisher = {HuggingFace},
276
- howpublished = {\url{https://huggingface.co/likithyadavv/codementor-v2-fullstack}},
277
- }
278
- ```
279
-
280
- ---
281
-
282
- ## 🔗 Links
283
 
284
- - 🤗 **Model Repo:** [likithyadavv/codementor-v2-fullstack](https://huggingface.co/likithyadavv/codementor-v2-fullstack)
285
- - 📖 **Base Model:** [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf)
286
- - 🏫 **Institution:** MVJ College of Engineering, Bengaluru, India
 
1
  ---
2
  license: apache-2.0
3
+ base_model: likithyadavv/codementor-7b
 
 
 
 
 
4
  tags:
5
+ - lora
6
+ - qlora
7
+ - peft
8
+ - code
9
+ - education
10
+ - socratic-tutoring
11
+ - qwen2.5-coder
12
+ language:
13
+ - en
14
+ library_name: peft
 
 
 
 
 
15
  ---
16
 
17
+ # CodeMentor V2 — Full-Stack (codementor-v2-fullstack)
18
 
19
+ A QLoRA-fine-tuned LoRA adapter that extends **CodeMentor**, a Socratic programming tutor, from 4 foundational languages to **17 full-stack technologies**.
20
 
21
+ This adapter is **Phase 2** of a two-phase continued fine-tuning pipeline. It is not trained from scratch it loads the Phase 1 checkpoint ([`likithyadavv/codementor-7b`](https://huggingface.co/likithyadavv/codementor-7b)) as its base and attaches a new, larger LoRA adapter on top.
22
 
23
+ ## Model Tree
24
 
25
+ ```
26
+ Qwen/Qwen2.5-7B
27
+ └── Qwen/Qwen2.5-Coder-7B
28
+ └── Qwen/Qwen2.5-Coder-7B-Instruct
29
+ └── likithyadavv/codementor-7b (Phase 1: 4 languages)
30
+ └── likithyadavv/codementor-v2-fullstack (Phase 2: 17 technologies — this adapter)
31
+ ```
32
 
33
+ ## What This Model Does
 
 
 
 
 
 
 
 
 
34
 
35
+ CodeMentor is designed to **teach**, not just answer. Given a student's code snippet and a question, it:
36
+ 1. Identifies the language or technology
37
+ 2. Acknowledges what the student got right
38
+ 3. Explains the problem conceptually — without handing over the corrected solution
39
+ 4. Closes with a guiding question that pushes the student to reason through the fix themselves
40
 
41
+ ## Technologies Covered
42
 
43
+ **Phase 1 (retained via dataset replay):** Python, Java, C, C++
44
 
45
+ **Phase 2 (new in this adapter):** HTML/CSS, JavaScript, TypeScript, React, Next.js, Node.js, Express, FastAPI, Django, Spring Boot, SQL, MongoDB, Docker, Git, REST APIs
 
 
 
 
46
 
47
+ ## Training Details
48
+
49
+ | | Phase 1 (base model) | Phase 2 (this adapter) |
50
+ |---|---|---|
51
+ | Base | Qwen2.5-Coder-7B-Instruct | codementor-7b |
52
+ | Dataset size | 505 | 8,000 (6,415 new + 1,585 replayed) |
53
+ | LoRA rank (r) | 16 | 32 |
54
+ | LoRA alpha | 32 | 64 |
55
+ | Target modules | q, k, v, o | q, k, v, o, gate, up, down |
56
+ | Trainable params | ~40M (0.5%) | ~80M (1.05%) |
57
+ | Quantization | 4-bit NF4 | 4-bit NF4 + double quantization |
58
+ | Epochs | 4 | 1 |
59
+ | Final training loss | 0.370 | ~0.24 |
60
+ | Adapter size | ~40 MB | ~120 MB |
61
+ | Hardware | 2× NVIDIA T4 (Kaggle) | 2× NVIDIA T4 (Kaggle) |
62
+ | Training time | ~91.5 min | ~30 hours |
63
+
64
+ **Why load Phase 1 as the base instead of raw Qwen?** The Phase 1 checkpoint already encodes Socratic tutoring behavior for 4 languages, so Phase 2 only needs to learn new technology-specific vocabulary and error patterns — not the tutoring format itself. This warm start is reflected in training loss falling below 1.0 within 50 steps, despite Phase 2 having 16× more training examples than Phase 1.
65
+
66
+ **Dataset replay:** 1,585 Phase 1 examples (~19.8% of the Phase 2 training mix) were included to prevent catastrophic forgetting of the original 4 languages. Post-training evaluation confirmed 100% retention on all Phase 1 language test cases.
67
+
68
+ ## Evaluation
69
+
70
+ Manual evaluation across all 17 technologies, one representative test prompt each, against 5 pass/fail criteria (technology identification, correct error diagnosis, Socratic closing question, no direct solution given, Phase 1 retention):
71
 
72
+ - **Overall: 97.2% (70/72 checks passed)**
73
+ - Technology identification: 100% (17/17)
74
+ - Socratic closing question present: 100% (17/17)
75
+ - Phase 1 language retention: 100% (4/4)
76
 
77
+ This is a manual smoke-test evaluation, not a held-out benchmark — see Limitations below.
78
+
79
+ ## Usage
80
 
81
  ```python
82
+ from transformers import AutoModelForCausalLM, BitsAndBytesConfig, AutoTokenizer
83
  from peft import PeftModel
84
  import torch
85
 
 
86
  bnb = BitsAndBytesConfig(
87
  load_in_4bit=True,
88
+ bnb_4bit_quant_type='nf4',
89
+ bnb_4bit_compute_dtype=torch.bfloat16,
90
  )
91
 
92
+ base = AutoModelForCausalLM.from_pretrained(
93
+ 'likithyadavv/codementor-7b',
 
 
 
 
94
  quantization_config=bnb,
95
+ device_map='auto',
96
  )
97
 
98
+ model = PeftModel.from_pretrained(base, 'likithyadavv/codementor-v2-fullstack')
99
+ tokenizer = AutoTokenizer.from_pretrained('likithyadavv/codementor-v2-fullstack')
 
 
 
100
  ```
101
 
102
+ Prompt format:
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  ```
105
+ ### System:
106
+ You are CodeMentor, a patient programming tutor for Python, Java, C, C++, HTML, CSS,
107
+ JavaScript, TypeScript, React, Next.js, Node.js, Express, FastAPI, Django, Spring Boot,
108
+ SQL, MongoDB, Git, REST APIs, and Docker. Always identify the language or technology
109
+ first. Acknowledge what is correct, then guide with hints and questions -- never give
110
+ away the full solution.
111
 
112
+ ### Instruction:
113
+ {instruction}
 
 
 
 
 
 
 
 
 
114
 
115
+ ### Input:
116
+ {code_snippet}
117
 
118
+ ### Response:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  ```
120
 
121
+ ## Limitations
122
 
123
+ - Evaluated manually on one prompt per technology — no automated benchmark (BLEU/ROUGE/BERTScore) or held-out test set yet
124
+ - Single-turn only — no conversation memory across exchanges
125
+ - Training data was authored against a fixed schema and quality-reviewed, but at hand-crafted scale (8,000 examples), which limits further growth without a more scalable data pipeline
126
 
127
+ ## Citation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ If you use this model, please cite:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  ```
132
+ CodeMentor LLM: A QLoRA Fine-Tuned Socratic Programming Tutor
133
+ Mohammad Yusha G.N., Likith Yadav, Suhas R, Dhananjay M. Hiremath
134
+ (Guide: Prof. Sanjivani D. Tipe)
135
+ Dept. of Artificial Intelligence & Machine Learning, MVJ College of Engineering, Bengaluru
136
+ SYNERGY 2026 IC-SIIT, MS Ramaiah University of Applied Sciences
 
 
 
 
 
 
 
137
  ```
138
 
139
+ ## Acknowledgements
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
+ Built using the Hugging Face ecosystem — Transformers, PEFT, TRL, BitsAndBytes, and Datasets. Compute provided via Kaggle's free-tier GPU program.