Views
No views yet
<reasoning> ... </reasoning>) followed by a concise answer (<answer> ... </answer>).1from unsloth import FastLanguageModel, is_bfloat16_supported
2from vllm import SamplingParams
3from huggingface_hub import snapshot_download
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="iimran/Qwen2.5-3B-R1-MedicalReasoner",
6 load_in_4bit=True,
7 fast_inference=True,
8 gpu_memory_utilization=0.5
9)
10lora_rank = 64
11model = FastLanguageModel.get_peft_model(
12 model,
13 r=lora_rank,
14 target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
15 "gate_proj", "up_proj", "down_proj"],
16 lora_alpha=lora_rank,
17 use_gradient_checkpointing="unsloth",
18 random_state=3407,
19)
20lora_path = snapshot_download("iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter")
21print("LoRA adapter downloaded to:", lora_path)
22model.load_lora(lora_path)
23SYSTEM_PROMPT = (
24 "Respond in the following format:\n"
25 "<reasoning>\n"
26 "...\n"
27 "</reasoning>\n"
28 "<answer>\n"
29 "...\n"
30 "</answer>"
31)
32USER_PROMPT = (
33 "In the context of disseminated intravascular coagulation (DIC), "
34 "which blood component is expected to show an increase due to the excessive breakdown of fibrin?"
35)
36text = tokenizer.apply_chat_template(
37 [
38 {"role": "system", "content": SYSTEM_PROMPT},
39 {"role": "user", "content": USER_PROMPT},
40 ],
41 tokenize=False,
42 add_generation_prompt=True
43)
44sampling_params = SamplingParams(
45 temperature=0.1,
46 top_p=0.95,
47 max_tokens=4096,
48)
49outputs = model.fast_generate(
50 text,
51 sampling_params=sampling_params,
52 lora_request=None
53)
54print(outputs[0].outputs[0].text)1from huggingface_hub import snapshot_download
2
3# Download the LoRA adapter repository:
4lora_path = snapshot_download("iimran/Qwen2.5-3B-R1-MedicalReasoner-lora-adapter")
5print("LoRA adapter downloaded to:", lora_path)
6
7# Load the adapter into the model:
8model.load_lora(lora_path)pip install unsloth vllm trl datasets huggingface-hub1@misc{sarwar2025reinforcement,
2 author = {Imran Sarwar and Muhammad Rouf Mustafa},
3 title = {Reinforcement Learning Elevates Qwen2.5-3B Medical Reasoning Performance},
4 year = {2025},
5 month = {Apr},
6 day = {10},
7 publisher = {Imran Sarwar's Blog},
8 howpublished = {\url{https://www.imransarwar.com/blog-posts/Reinforcement-Learning-Elevates-Qwen2.5-Medical-Reasoning-Performance.html}},
9 note = {Accessed: 2025-04-09}
10}1@misc{Qwen2.5-3B-R1-MedicalReasoner,
2 authors = {Imran Sarwar, Muhammad Rouf Mustafa},
3 title = {Qwen 2.5-3B Meets Deepseek R1: A Fine-Tuned Medical Reasoning Model for Enhanced Diagnostics},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/iimran/Qwen2.5-3B-R1-MedicalReasoner}
7}