Downloads · 30 days
8
9% of all-time downloads
Rutvik141/medical-reasoning-qwen-0.5b
medical-reasoning-qwen-0.5b is a text generation model from Rutvik141. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
A compact medical-reasoning model fine-tuned from Qwen/Qwen2.5-0.5B-Instruct for step-by-step clinical reasoning. It is optimized to break down cases, propose differentials, and justify answers. Note: Outputs may incl…
Downloads · 30 days
8
9% of all-time downloads
All-time downloads
93
Public
Repo size
24.6 MB
Likes
0
Public
Click a slice to open those files.
.json42.6 MB · 68%
From the Hugging Face model README
A compact medical-reasoning model fine-tuned from Qwen/Qwen2.5-0.5B-Instruct for step-by-step clinical reasoning. It is optimized to break down cases, propose differentials, and justify answers.
Note: Outputs may include intermediate reasoning. Do not treat responses as medical advice.
Out-of-scope / High-risk
Do not use for clinical decisions, triage, or patient-specific recommendations.
FreedomIntelligence/medical-o1-reasoning-SFT (instruction-style, reasoning-focused){system, instruction, input} styleL=1024 by default)transformers, peft, bitsandbytes, acceleratebf16 (fallback fp16 if needed)r=8, alpha=16, lora_dropout=0.1, target_modules=["q_proj","v_proj","o_proj"]load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_use_double_quant=TrueAdamW8bit (bitsandbytes) or adamw_torch_fusedlr=2e-4, cosine decay, warmup_ratio=0.060.01, label smoothing 0.05, gradient clipping 1.0per_device_train_batch_size=4, gradient_accumulation_steps=8 → effective batch 32max_seq_length=10242–3 (use early stopping on val loss)500 steps, keep best on val lossseed=42ceil(num_samples / effective_batch)100k / 32 ≈ 3125Add your concrete scores here once computed.
……from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
repo = "YOUR_ORG/medical-qwen25-0_5b-lora" # replace with your repo
tok = AutoTokenizer.from_pretrained(repo, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
repo,
torch_dtype=torch.bfloat16,
device_map="auto"
)
prompt = """You are a clinician. Reason step by step.
Patient: 56F with chest pain radiating to jaw, diaphoresis...
Question: Most likely diagnosis and initial management?"""
inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=256, temperature=0.2, top_p=0.9)
print(tok.decode(out[0], skip_special_tokens=True))
#Training Script snippet with lora Fine Tunning
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
from peft import LoraConfig, get_peft_model
import torch
base = "Qwen/Qwen2.5-0.5B-Instruct"
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(
base,
load_in_4bit=True,
torch_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
device_map="auto",
low_cpu_mem_usage=True,
)
lora = LoraConfig(r=8, lora_alpha=16, lora_dropout=0.1,
target_modules=["q_proj","v_proj","o_proj"])
model = get_peft_model(model, lora)
model.gradient_checkpointing_enable()
model.config.use_cache = False # training only
args = TrainingArguments(
output_dir="ckpts",
per_device_train_batch_size=4,
gradient_accumulation_steps=8,
learning_rate=2e-4,
lr_scheduler_type="cosine",
warmup_ratio=0.06,
weight_decay=0.01,
num_train_epochs=3,
bf16=True,
save_steps=500,
evaluation_strategy="steps",
eval_steps=500,
logging_steps=50,
save_safetensors=True,
load_best_model_at_end=True,
metric_for_best_model="loss",
gradient_checkpointing=True,
)
# ... Trainer(train_ds, val_ds, callbacks for S3 sync)