CoolFace
Modelpublic

xjh666/medical-o1-qwen2.5-0.5b

sourceHugging Facemitupdated 3mo agoView on Hugging Face
1likes6downloads
Model Card

🏥 Medical Qwen2.5-0.5B — 医疗问答 LoRA

基于 Qwen2.5-0.5B-Instruct 使用 Unsloth + QLoRA 微调的医疗推理问答模型。

在 RTX 3050 (4GB VRAM) 上训练完成。模型学会了先进行 <think> 推理链思考,再给出最终答案。

📊 训练结果

指标1 epoch2 epoch
训练 Loss1.70—
验证 Loss1.692—
答案关键词重叠 (50条)41%48%
训练耗时~6h~12h

🚀 使用方法

python
from unsloth import FastLanguageModel
import torch

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="xjh666/medical-o1-qwen2.5-0.5b",  # 本 LoRA 适配器
    max_seq_length=1024,
    dtype=None,
    load_in_4bit=True,
)
FastLanguageModel.for_inference(model)

messages = [
    {"role": "user", "content": "A 45-year-old man presents with chest pain and shortness of breath. What is the most likely diagnosis?"},
]
inputs = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_tensors="pt",
).to("cuda")

outputs = model.generate(input_ids=inputs, max_new_tokens=512, temperature=0.1, top_p=0.9)
print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))

📂 仓库内容

  • —主分支:LoRA 适配器 (~45MB),需要配合基座模型 unsloth/Qwen2.5-0.5B-Instruct-bnb-4bit 使用
  • —`merged_16bit/`:完整 16-bit 合并权重 (~954MB),可直接推理(不含 LoRA 依赖)

📖 训练数据

FreedomIntelligence/medical-o1-reasoning-SFT (英文子集) 包含医学问答 + 复杂推理链(Complex CoT),格式为 <think>推理</think>答案

⚙️ 训练参数

参数值
基座模型Qwen2.5-0.5B-Instruct-bnb-4bit (4-bit)
LoRA rank / alpha16 / 16
目标模块qproj, kproj, vproj, oproj, gateproj, upproj, down_proj
Batch size1 × 8 (gradient accumulation)
Max seq length1024
Learning rate2e-4 (cosine)
优化器adamw_8bit
训练步数~2340(1 epoch),~4680(2 epoch)

🖥️ 硬件环境

  • —GPU:NVIDIA GeForce RTX 3050 Laptop GPU (4GB VRAM)
  • —PyTorch:2.10.0+cu130
  • —CUDA:8.6 (Compute Capability) / Toolkit 13.0
  • —Unsloth:2026.6.9

📜 License

MIT

📖 引用

bibtex
@misc{chen2024huatuogpto1medicalcomplexreasoning,
  title={HuatuoGPT-o1, Towards Medical Complex Reasoning with LLMs},
  author={Junying Chen and Zhenyang Cai and Ke Ji and Xidong Wang and Wanlong Liu and Rongsheng Wang and Jianye Hou and Benyou Wang},
  year={2024},
  eprint={2412.18925},
  archivePrefix={arXiv},
}