Views
No views yet
GRPO to excel at medical domain reasoning while maintaining strong mathematical problem-solving capabilities. The model demonstrates enhanced reasoning abilities and can express uncertainty when appropriate.ollama, llama-cpp, vllm or any other inference iengine, you need to set the system prompt as below as the model performs best with the following prompt:'\nRespond in the following format:\n<reasoning>\n...\n</reasoning>\n<answer>\n...\n</answer>\n'1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "hashamulhaq/MedQwen2.5-3B-Improved"
4
5# Initialize model and tokenizer
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype="auto",
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_name)
12
13# Prepare prompt
14prompt = "What is the relationship between BMI and cardiovascular disease risk?"
15messages = [
16 {"role": "system", "content": "\nRespond in the following format:\n<reasoning>\n...\n</reasoning>\n<answer>\n...\n</answer>\n"},
17 {"role": "user", "content": prompt}
18]
19text = tokenizer.apply_chat_template(
20 messages,
21 tokenize=False,
22 add_generation_prompt=True
23)
24
25# Generate response
26model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
27generated_ids = model.generate(
28 **model_inputs,
29 max_new_tokens=512
30)
31generated_ids = [
32 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
33]
34response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]