File size: 2,162 Bytes
085688f
 
65762fa
 
 
 
085688f
 
 
65762fa
085688f
65762fa
085688f
65762fa
 
 
085688f
65762fa
 
085688f
 
 
 
65762fa
085688f
65762fa
085688f
65762fa
085688f
 
 
 
 
 
 
65762fa
085688f
65762fa
085688f
65762fa
 
 
 
 
085688f
65762fa
 
085688f
 
65762fa
085688f
 
65762fa
085688f
 
 
65762fa
085688f
 
65762fa
 
085688f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SafeMed-R1: A Trustworthy Medical Reasoning Model

<div align="center">
  <a href="https://github.com/OpenMedZoo/SafeMed-R1" target="_blank">GitHub</a> |
  <a href="#" target="_blank">Paper (coming soon)</a>
</div>



## 1 Introduction

SafeMed-R1 is a medical LLM designed for trustworthy medical reasoning. It thinks before answering, resists jailbreaks, and returns safe, auditable outputs aligned with medical ethics and regulations.

- Trustworthy and compliant: avoids harmful advice, provides calibrated, fact-based responses with appropriate disclaimers.  
- Attack resistance: trained with healthcare-specific red teaming and multi-dimensional reward optimization to safely refuse risky requests.  
- Explainable reasoning: can provide structured, step-by-step clinical reasoning when prompted.

For more information, visit our GitHub repository:  
      https://github.com/OpenMedZoo/SafeMed-R1

---


## Usage

You can use SafeMed-R1 in the same way as an instruction-tuned Qwen-style model. It can be deployed with vLLM or run via Transformers.

Transformers (direct inference):

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "OpenMedZoo/SafeMed-R1"
model = AutoModelForCausalLM.from_pretrained(
    model_id, torch_dtype="auto", device_map="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)

messages = [{"role": "user", "content": "How to relieve a mild cough safely?"}]
inputs = tokenizer(
    tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True),
    return_tensors="pt"
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=1024)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

vLLM (OpenAI-compatible serving):

```bash
MODEL_PATH="OpenMedZoo/SafeMed-R1"
PORT=50050
vllm serve "$MODEL_PATH" \
  --host 0.0.0.0 \
  --port $PORT \
  --trust-remote-code \
  --served-model-name "safemed-r1" \
  --tensor-parallel-size 4 \
  --pipeline-parallel-size 1 \
  --gpu-memory-utilization 0.9 \
  --disable-sliding-window \
  --max-model-len 4096 \
  --enable-prefix-caching
```