Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3# Load model and tokenizer
4model = AutoModelForCausalLM.from_pretrained(
5 "AndreiSobo/pact-qwen-tutor",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("AndreiSobo/pact-qwen-tutor")
10
11# Example conversation (matching training format)
12messages = [
13 {
14 "role": "system",
15 "content": "You are PACT, a Socratic Python coding tutor. Help students learn through guided questions and hints, not direct answers."
16 },
17 {
18 "role": "user",
19 "content": """Problem: Two Sum
20
21Given an array of integers nums and an integer target, return indices of the two numbers that add up to target.
22
23Example 1:
24
25Input: nums = [2,7,11,15], target = 9
26Output: [0,1]
27Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
28
29Example 2:
30
31Input: nums = [3,2,4], target = 6
32Output: [2,1]
33
34Constraints:
35- 2 <= nums.length <= 104
36- -109 <= nums[i] <= 109
37- Only one valid answer exists.
38
39My code:
40```python
41def twoSum(nums, target):
42 for i in range(len(nums)):
43 for j in range(len(nums)):
44 if nums[i] + nums[j] == target:
45 return [i, j]
46```
47
48It runs but gives wrong output for some test cases.
49
50Can you give me a hint?"""
51 }
52]
53
54# Generate response
55text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
56inputs = tokenizer(text, return_tensors="pt").to(model.device)
57
58outputs = model.generate(
59 **inputs,
60 max_new_tokens=200,
61 temperature=0.7,
62 do_sample=True,
63 top_p=0.9
64)
65
66response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
67print(response)1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2import torch
3
4quant_config = BitsAndBytesConfig(
5 load_in_4bit=True,
6 bnb_4bit_quant_type="nf4",
7 bnb_4bit_compute_dtype=torch.float16,
8 bnb_4bit_use_double_quant=True
9)
10
11model = AutoModelForCausalLM.from_pretrained(
12 "AndreiSobo/pact-qwen-tutor",
13 quantization_config=quant_config,
14 device_map="auto"
15)
16tokenizer = AutoTokenizer.from_pretrained("AndreiSobo/pact-qwen-tutor")1# Importantly, messages must have the same structure as the JSONL object the model was trained on
2messages = [
3 {
4 "role": "system",
5 "content": "You are PACT, a Socratic Python coding tutor. Help students learn through guided questions and hints, not direct answers."
6 },
7 {
8 "role": "user",
9 "content": """Problem: Two Sum
10
11Given an array of integers nums and an integer target, return indices of the two numbers that add up to target.
12
13Example 1:
14
15Input: nums = [2,7,11,15], target = 9
16Output: [0,1]
17Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
18
19Example 2:
20
21Input: nums = [3,2,4], target = 6
22Output: [2,1]
23
24Constraints:
25- 2 <= nums.length <= 104
26- -109 <= nums[i] <= 109
27- Only one valid answer exists.
28
29My code:
30```python
31def twoSum(nums, target):
32 for i in range(len(nums)):
33 for j in range(len(nums)):
34 if nums[i] + nums[j] == target:
35 return [i, j]
36```
37
38It runs but gives wrong output for some test cases.
39
40Can you give me a hint?"""
41 }
42]
43text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
44inputs = tokenizer(text, return_tensors="pt").to(model.device)
45
46outputs = model.generate(**inputs, max_new_tokens=200)
47response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
48print(response)Problem: [Name]1@misc{pact2026,
2 author = {Sobo, Andrei},
3 title = {PACT: Personalised AI Coding Tutor - A Socratic Fine-Tuned Qwen 2.5 Model},
4 year = {2026},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/AndreiSobo/pact-qwen-tutor}
7}