Views
No views yet
| Dimension | Score / 5 |
|---|---|
| Analogy quality | 4.67 |
| Clarity | 5.00 |
| Encouraging tone | 5.00 |
| Practice question | 5.00 |
| Conciseness | 4.33 |
| Average total | 24.0 / 25 |
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "Qwen/Qwen2.5-7B-Instruct"
6LORA_PATH = "lifatsastain/teach_lora1"
7
8quant_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_use_double_quant=True,
12 bnb_4bit_compute_dtype=torch.bfloat16,
13)
14
15model = AutoModelForCausalLM.from_pretrained(
16 BASE_MODEL, quantization_config=quant_config, device_map="auto"
17)
18model = PeftModel.from_pretrained(model, LORA_PATH)
19model.eval()
20
21tokenizer = AutoTokenizer.from_pretrained(LORA_PATH)
22
23SYSTEM = (
24 "You are an ML tutor teaching CS students who know coding but not ML. "
25 "Always start with an intuitive analogy, build up to the concept, "
26 "and end with a practice question. Be encouraging and patient."
27)
28
29messages = [
30 {"role": "system", "content": SYSTEM},
31 {"role": "user", "content": "What is gradient descent?"},
32]
33text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
34inputs = tokenizer(text, return_tensors="pt").to(model.device)
35
36with torch.no_grad():
37 output_ids = model.generate(**inputs, max_new_tokens=512, temperature=0.7, top_p=0.9,
38 do_sample=True, pad_token_id=tokenizer.eos_token_id)
39
40new_tokens = output_ids[0][inputs["input_ids"].shape[-1]:]
41print(tokenizer.decode(new_tokens, skip_special_tokens=True))1from peft import PeftModel
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
4import bitsandbytes
5BASE_MODEL = "Qwen/Qwen2.5-7B-Instruct"
6LORA_PATH = "lifatsastain/teach_lora1"
7
8bnb_config = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.float16,
12)
13
14tokenizer = AutoTokenizer.from_pretrained(LORA_PATH)
15
16base_model = AutoModelForCausalLM.from_pretrained(
17 BASE_MODEL,
18 quantization_config=bnb_config,
19 device_map="auto",
20)
21model = PeftModel.from_pretrained(base_model, LORA_PATH)
22model.eval()
23
24SYSTEM = (
25 "You are an ML tutor teaching CS students who know coding but not ML. "
26 "Always start with an intuitive analogy, build up to the concept, "
27 "and end with a practice question. Be encouraging and patient."
28)
29
30conversation_history = []
31
32def chat(user_message):
33 conversation_history.append({"role": "user", "content": user_message})
34
35 messages = [{"role": "system", "content": SYSTEM}] + conversation_history
36
37 text = tokenizer.apply_chat_template(
38 messages, tokenize=False, add_generation_prompt=True
39 )
40 inputs = tokenizer(text, return_tensors="pt").to(model.device)
41
42 with torch.no_grad():
43 output_ids = model.generate(
44 **inputs,
45 max_new_tokens=1024,
46 temperature=0.7,
47 top_p=0.9,
48 do_sample=True,
49 pad_token_id=tokenizer.eos_token_id
50 )
51
52 new_tokens = output_ids[0][inputs["input_ids"].shape[-1]:]
53 response = tokenizer.decode(new_tokens, skip_special_tokens=True)
54
55 conversation_history.append({"role": "assistant", "content": response})
56 return response
57
58print("ML Tutor ready! Type 'quit' to exit, 'reset' to clear history.\n")
59
60while True:
61 user_input = input("You: ").strip()
62 if not user_input:
63 continue
64 if user_input.lower() == "quit":
65 print("Bye!")
66 break
67 if user_input.lower() == "reset":
68 conversation_history.clear()
69 print("Conversation history cleared.\n")
70 continue
71 response = chat(user_input)
72 print(f"\nTutor: {response}\n")
73
74'''
75
76
77
78## Training Details
79
80| Parameter | Value |
81|------------------------|-------------------------------|
82| Base model | Qwen2.5-7B-Instruct |
83| LoRA rank (r) | 16 |
84| LoRA alpha | 32 |
85| LoRA dropout | 0.05 |
86| Target modules | q_proj, k_proj, v_proj, o_proj |
87| Training epochs | 1 |
88| Learning rate | 2e-4 |
89| Batch size | 1 (grad accum 16) |
90| Max sequence length | 512 |
91| Quantization | 4-bit NF4 |
92| Optimizer | paged_adamw_8bit |
93|----------------------------------------------------------
94
95### Framework Versions
96- transformers: 5.3.0
97- bitsandbytes: 0.49.2
98- peft: 0.18.1
99- torch: 2.10.0+cu126
100- trl: 0.29.0
101- datasets: 4.7.0