Upload test_iep_model.py with huggingface_hub
Browse files- test_iep_model.py +65 -0
test_iep_model.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# requires-python = ">=3.10"
|
| 3 |
+
# dependencies = [
|
| 4 |
+
# "transformers>=4.45.0",
|
| 5 |
+
# "peft>=0.7.0",
|
| 6 |
+
# "accelerate>=0.24.0",
|
| 7 |
+
# "torch",
|
| 8 |
+
# ]
|
| 9 |
+
# ///
|
| 10 |
+
|
| 11 |
+
from peft import PeftModel
|
| 12 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 13 |
+
|
| 14 |
+
print("Loading base model and LoRA adapter...")
|
| 15 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
+
"Qwen/Qwen3-4B",
|
| 17 |
+
torch_dtype="auto",
|
| 18 |
+
device_map="auto",
|
| 19 |
+
)
|
| 20 |
+
model = PeftModel.from_pretrained(base_model, "jeremierostan/iep-udl-qwen3-4b")
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained("jeremierostan/iep-udl-qwen3-4b")
|
| 22 |
+
|
| 23 |
+
system_prompt = (
|
| 24 |
+
"You are an IEP specialist at ISP (International School of Panama). "
|
| 25 |
+
"You help teachers understand student accommodations, design inclusive instruction "
|
| 26 |
+
"using Universal Design for Learning (UDL) principles, and align teaching practices "
|
| 27 |
+
"with the ISP Way — the school's teaching and learning philosophy. The ISP Way "
|
| 28 |
+
"emphasizes learning as a journey of authentic discovery that is meaningful, exciting, "
|
| 29 |
+
"social, and iterative, with UDL as the framework for equity to remove barriers and "
|
| 30 |
+
"maintain high expectations for all learners."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
test_questions = [
|
| 34 |
+
"What accommodations does student 2025-0347 receive for assessments?",
|
| 35 |
+
"How can I use UDL to support a student with dyslexia during a science lesson?",
|
| 36 |
+
"Which students are allowed breaks outside the classroom, and why?",
|
| 37 |
+
"I have a student with anxiety in my class. How can I design group activities that benefit all learners?",
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
for i, question in enumerate(test_questions, 1):
|
| 41 |
+
print(f"\n{'='*80}")
|
| 42 |
+
print(f"QUESTION {i}: {question}")
|
| 43 |
+
print(f"{'='*80}")
|
| 44 |
+
|
| 45 |
+
messages = [
|
| 46 |
+
{"role": "system", "content": system_prompt},
|
| 47 |
+
{"role": "user", "content": question},
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
|
| 51 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 52 |
+
|
| 53 |
+
output = model.generate(
|
| 54 |
+
**inputs,
|
| 55 |
+
max_new_tokens=512,
|
| 56 |
+
temperature=0.7,
|
| 57 |
+
top_p=0.9,
|
| 58 |
+
do_sample=True,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 62 |
+
print(f"\nRESPONSE:\n{response}")
|
| 63 |
+
|
| 64 |
+
print(f"\n{'='*80}")
|
| 65 |
+
print("Testing complete!")
|