gpt-oss-20b-MedReason

image

gpt-oss-20b-MedReason is a medical question-answering model fine-tuned from OpenAI's gpt-oss-20b. It reasons through medical questions, including multiple-choice and open-ended ones, and gives a structured final answer. Weights are released in MXFP4 (about 14 GB), so the model runs on a single 16 GB GPU. It was tested on a T4.

Training Details

Base model openai/gpt-oss-20b
Dataset lingshu-medical-mllm/ReasonMed (300 samples)
Method QLoRA supervised fine-tuning with Unsloth
LoRA r = 16, alpha = 32, applied to attention projections (q, k, v, o)
Training 2 epochs, learning rate 2e-4, effective batch size 8
Format Harmony chat format (analysis channel, then final channel), low reasoning effort

Recommended Prompt

For concise, answer-first responses, use the system prompt below. The model was fine-tuned on long, textbook-style reasoning, so without it the final answer can restate the analysis at length.

You are a medical expert. Answer medical questions accurately.
Analysis: short private working notes. State the likely answer early, then justify it briefly.
Final answer rules: begin with the direct answer in one sentence. Then give at most 4 short bullet points with the key reasoning or management steps. Maximum 120 words. Do not restate the question, do not repeat the analysis, and do not add a differential diagnosis or a conclusion section unless asked. For multiple-choice questions, name the correct letter and option first.

Usage

Install the MXFP4 kernels first. Without them, transformers expands the weights to bf16 (about 40 GB):

pip install -U transformers accelerate kernels==0.17.2

The snippet below limits the analysis to a token budget, then starts the final answer with **Answer:** so it leads with the answer.

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "Rumiii/gpt-oss-20b-MedReason"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, dtype="auto", device_map="auto")

SYSTEM = (
    "You are a medical expert. Answer medical questions accurately.\n"
    "Analysis: short private working notes. State the likely answer early, then justify it briefly.\n"
    "Final answer rules: begin with the direct answer in one sentence. Then give at most 4 short bullet "
    "points with the key reasoning or management steps. Maximum 120 words. Do not restate the question, "
    "do not repeat the analysis, and do not add a differential diagnosis or a conclusion section unless asked. "
    "For multiple-choice questions, name the correct letter and option first."
)
END, RET, CALL = (tok.convert_tokens_to_ids(t) for t in ("<|end|>", "<|return|>", "<|call|>"))

def generate(text, max_new, stop_ids):
    inp = tok(text, return_tensors="pt", add_special_tokens=False).to(model.device)
    out = model.generate(**inp, max_new_tokens=max_new, do_sample=True, temperature=0.4, top_p=0.9,
                         eos_token_id=stop_ids, pad_token_id=tok.eos_token_id)
    ids = out[0][inp["input_ids"].shape[1]:].tolist()
    ids = ids[:-1] if ids and ids[-1] in stop_ids else ids
    return tok.decode(ids, skip_special_tokens=False).strip()

def ask(question, analysis_tokens=300, final_tokens=300):
    messages = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": question}]
    prompt = tok.apply_chat_template(messages, add_generation_prompt=True, tokenize=False,
                                     reasoning_effort="low")
    analysis = generate(prompt + "<|channel|>analysis<|message|>", analysis_tokens, [END, RET])
    final_prompt = (prompt + "<|channel|>analysis<|message|>" + analysis + "<|end|>"
                    + "<|start|>assistant<|channel|>final<|message|>**Answer:** ")
    return "**Answer:** " + generate(final_prompt, final_tokens, [RET, END, CALL])

print(ask("Explain the mechanism of action of metformin."))

Example Output

Question: Explain the mechanism of action of metformin.

Answer: Metformin reduces hepatic glucose production primarily through activation of AMP-activated protein kinase (AMPK), which inhibits acetyl-CoA carboxylase (ACC), decreasing fatty acid synthesis and gluconeogenesis. It also enhances insulin sensitivity in peripheral tissues and modestly reduces intestinal glucose absorption, without stimulating insulin secretion, thereby minimizing hypoglycemia risk.

  • AMPK Activation: Metformin activates AMPK, a key energy sensor in cells.
  • Inhibition of ACC: Activated AMPK inhibits ACC, leading to reduced fatty acid synthesis.
  • Reduced Gluconeogenesis: Lower fatty acid availability diminishes gluconeogenesis in the liver, decreasing glucose output.
  • Improved Insulin Sensitivity: Metformin enhances glucose uptake in skeletal muscle, improving peripheral insulin sensitivity.

Limitations

  • The model was fine-tuned on only 300 samples, which shaped its output style more than its medical knowledge. Its analysis channel tends to be long and formatted like an answer, and the final answer can repeat it. The recommended prompt and the two-step snippet above reduce this but do not remove it.
  • It can make factual and clinical errors. Always verify its output against authoritative sources.
  • It is intended for research and educational use only. It is not a substitute for professional medical advice, diagnosis, or treatment.
Downloads last month
573
Safetensors
Model size
21B params
Tensor type
BF16
·
U8
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Rumiii/gpt-oss-20b-MedReason

Quantized
(262)
this model
Quantizations
2 models

Dataset used to train Rumiii/gpt-oss-20b-MedReason