FreedomIntelligence/medical-o1-reasoning-SFT
Viewer • Updated • 90.1k • 8.83k • 1.12k
QwenMedic-v1 is a medical-specialty adaptation of the Qwen3-1.7B causal language model, fine-tuned for clinical reasoning and instruction-following tasks. It was trained for 1 epoch on two curated medical datasets to improve diagnostic Q&A and clinical summarization.
Medical Reasoning SFT (FreedomIntelligence/medical-o1-reasoning-SFT)
trainGeneral Medical Instruction (jtatman/medical-sci-instruct-1m-sharegpt)
train[:100000]| Metric | Step | Smoothed | Raw Value |
|---|---|---|---|
| Epoch | 1539 | 0.9979 | 0.9997 |
| Gradient Norm | 1539 | 0.3882 | 0.3974 |
| Learning Rate | 1539 | — | 0 |
| Training Loss | 1539 | 1.5216 | 1.4703 |
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/QwenMedic-v1"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
# prepare the model input
prompt = "A 55-year-old male with Type 2 diabetes presents with sudden chest pain "
"and diaphoresis. What are the top differential diagnoses?"
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# parsing thinking content
try:
# rindex finding 151668 (</think>)
index = len(output_ids) - output_ids[::-1].index(151668)
except ValueError:
index = 0
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
print("thinking content:", thinking_content)
print("content:", content)