Instructions to use sarakhosravi/MedGuard-Qwen3-4B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sarakhosravi/MedGuard-Qwen3-4B-Instruct with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
MedGuard-Qwen3-4B-Instruct
LoRA adapters for patient-conditioned medication guarding, trained on MedGuardBench. Given a structured patient profile and a proposed prescription, the model returns a safe/unsafe verdict and the 17 risk categories that justify it.
These are the selected checkpoints for each training arm, one per subfolder.
| Subfolder | Training arm | Acc | Rec | FPR | Mic | Mac | EM |
|---|---|---|---|---|---|---|---|
sft/ |
SFT | 87.4 | 98.4 | 24.6 | 72.3 | 65.4 | 62.1 |
cu/ |
Patient Profile Unrolling (CU) | 90.3 | 97.1 | 17.1 | 75.5 | 70.0 | 67.5 |
grpo/ |
Guided GRPO | 91.4 | 95.3 | 12.9 | 75.2 | 69.1 | 67.1 |
Metrics (%) are on the 729-row drug-disjoint MedGuardBench test split. Acc is verdict accuracy, Rec is unsafe recall, FPR is the false-positive rate on safe prescriptions, and Mic / Mac / EM are the 17-category micro-F1, macro-F1 and exact match.
- SFT: schema-aligned supervised fine-tuning.
- CU: Patient Profile Unrolling. One extra epoch from the SFT checkpoint in which the model first checks each patient-chart field against the drug's safety rules, then gives its verdict.
- Guided GRPO: GRPO with a verifiable safety reward and teacher-guided rollouts, starting from the merged SFT model.
Base model each adapter was trained on:
sft/:unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bitcu/:unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bitgrpo/:merged unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit + sft/
Usage
The SFT and CU adapters apply directly to the base model they were trained on (unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit; the original model is Qwen/Qwen3-4B-Instruct-2507).
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit", device_map="auto")
tok = AutoTokenizer.from_pretrained("sarakhosravi/MedGuard-Qwen3-4B-Instruct", subfolder="cu")
model = PeftModel.from_pretrained(base, "sarakhosravi/MedGuard-Qwen3-4B-Instruct", subfolder="cu")
Guided GRPO
The grpo/ adapter was trained on top of the merged SFT model, so apply sft/ first:
base = AutoModelForCausalLM.from_pretrained("unsloth/qwen3-4b-instruct-2507-unsloth-bnb-4bit", device_map="auto")
model = PeftModel.from_pretrained(base, "sarakhosravi/MedGuard-Qwen3-4B-Instruct", subfolder="sft").merge_and_unload()
model = PeftModel.from_pretrained(model, "sarakhosravi/MedGuard-Qwen3-4B-Instruct", subfolder="grpo")
Decode greedily (temperature 0). The CU arm writes a verification trace before its verdict, so allow at least 2,048 new tokens.
Intended use
Research on medication-safety guardrails only. These models are not medical devices and must not be used for clinical decisions.
- Downloads last month
- -
Model tree for sarakhosravi/MedGuard-Qwen3-4B-Instruct
Base model
Qwen/Qwen3-4B-Instruct-2507