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)
- Chain-of-thought reasoning examples on verifiable medical problems
- Language: English
- Split used:
train
-
General Medical Instruction (jtatman/medical-sci-instruct-1m-sharegpt)
- Conversational Q&A prompts across medical topics
- Sampled first 100 000 examples via
train[:100000]
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "Qwen/QwenMedic-v1"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14prompt = "A 55-year-old male with Type 2 diabetes presents with sudden chest pain "
15 "and diaphoresis. What are the top differential diagnoses?"
16messages = [
17 {"role": "user", "content": prompt}
18]
19text = tokenizer.apply_chat_template(
20 messages,
21 tokenize=False,
22 add_generation_prompt=True,
23 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# conduct text completion
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=32768
31)
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
33
34# parsing thinking content
35try:
36 # rindex finding 151668 (</think>)
37 index = len(output_ids) - output_ids[::-1].index(151668)
38except ValueError:
39 index = 0
40
41thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
42content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
43
44print("thinking content:", thinking_content)
45print("content:", content)