Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load base model and tokenizer
5base_model_id = "Qwen/Qwen3-32B"
6adapter_id = "TachyHealth/Gazal-R1-32B-sft-merged"
7
8# Load the tokenizer and base model
9tokenizer = AutoTokenizer.from_pretrained(base_model_id)
10model = AutoModelForCausalLM.from_pretrained(
11 base_model_id,
12 torch_dtype="auto",
13 device_map="auto",
14)
15
16# Load the LoRA adapter
17model = PeftModel.from_pretrained(model, adapter_id)
18
19# Prepare a prompt following the format during training
20query = """[MEDICAL QUESTION]"""
21
22messages = [
23 {"role": "system", "content": "When solving complex medical problems, follow this specific format..."},
24 {"role": "user", "content": query}
25]
26
27input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
28inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
29
30# Generate response
31outputs = model.generate(
32 input_ids=inputs.input_ids,
33 max_new_tokens=2048,
34 temperature=0.6,
35 do_sample=True,
36)
37
38response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
39print(response)| Model | Size | MMLU Pro (Medical) | MedMCQA | MedQA | PubMedQA |
|---|---|---|---|---|---|
| Gazal-R1 (Final) | 32B | 81.6 | 71.9 | 87.1 | 79.6 |
| Gazal-R1 (SFT-only) | 32B | 79.3 | 72.3 | 86.9 | 77.6 |
| Llama 3.1 405B Instruct | 405B | 70.2 | 75.8 | 81.9 | 74.6 |
| Qwen 2.5 72B Instruct | 72B | 72.1 | 66.2 | 72.7 | 71.7 |
| Med42-Llama3.1-70B | 70B | 66.1 | 72.4 | 80.4 | 77.6 |
| Llama 3.1 70B Instruct | 70B | 74.5 | 72.5 | 78.4 | 78.5 |
| QwQ 32B | 32B | 70.1 | 65.6 | 72.3 | 73.7 |
| Qwen 3 32B | 32B | 78.4 | 71.6 | 84.4 | 76.7 |