Instructions to use Rumiii/gpt-oss-20b-MedReason with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Rumiii/gpt-oss-20b-MedReason with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Rumiii/gpt-oss-20b-MedReason") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Rumiii/gpt-oss-20b-MedReason") model = AutoModelForCausalLM.from_pretrained("Rumiii/gpt-oss-20b-MedReason", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Rumiii/gpt-oss-20b-MedReason with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Rumiii/gpt-oss-20b-MedReason" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Rumiii/gpt-oss-20b-MedReason", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Rumiii/gpt-oss-20b-MedReason
- SGLang
How to use Rumiii/gpt-oss-20b-MedReason with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Rumiii/gpt-oss-20b-MedReason" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Rumiii/gpt-oss-20b-MedReason", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Rumiii/gpt-oss-20b-MedReason" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Rumiii/gpt-oss-20b-MedReason", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use Rumiii/gpt-oss-20b-MedReason with Docker Model Runner:
docker model run hf.co/Rumiii/gpt-oss-20b-MedReason
gpt-oss-20b-MedReason
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
