AI

MedGemma 2 vs Gemma 4 vs MedGemma 1.5: Local Benchmark

Gemma 4 matched or beat MedGemma 2 on most of what we measured, which is not what the MedGemma 2 model card suggests. Both E4B models answered 40 of 50 MedQA questions in their better mode (Ollama 0.40.19, benchmarked December 2026 on an RTX 4090). At 26B, Gemma 4 scored 46 and MedGemma 2 scored 45. Gemma 4 26B also read the chest X-ray at least as well and kept the right CKD stage in every run without its calculator. The medical models kept one clear lead: MedGemma 1.5 4B named four of five X-ray findings in all three runs, while MedGemma 2 E4B invented a device every time.

Original content from computingforgeeks.com - post 203382

We put MedGemma 2 vs Gemma 4 vs MedGemma 1.5, plus MedGemma 1 27B, through four tests: a scored MedQA sample, two openly licensed images, the FHIR eGFR loop from our MedGemma 2 Ollama guide, and VRAM and speed at 32K context. All six ran as Q4_K_M builds with identical prompts. Audio, 3D scans and bf16 weights were not tested.

MedGemma 2 vs Gemma 4: which model to run for what

No model won every test, so the pick depends on the job and the card you have. The table below gives our pick for each job and the measurement behind it. Every number in it comes from the sections that follow.

JobRun thisMeasured reason
Chest X-ray reads on an 8 GB cardMedGemma 1.5 4B4 of 5 findings in all 3 runs at 4.8 GiB of VRAM; MedGemma 2 E4B invented a device and called the heart normal in all 3
Image reads on a 24 GB cardMedGemma 2 26B4 of 5 X-ray findings and a melanoma call in every run; Gemma 4 26B scored 4, 5 and 4 on the X-ray but thought for 32,216 tokens on one skin run and returned nothing
FHIR tool calling on a small GPUGemma 4 E4B3 of 3 runs returned 35.0 and G3b; MedGemma 2 E4B used a creatinine from a year earlier in 1 of 3
FHIR tool calling on 24 GBGemma 4 26B3 of 3 exact with the calculator, like MedGemma 2 26B, and the right stage in 3 of 3 without it against 2 of 3
Medical text questionsGemma 4 26B46/50 against 45/50 for MedGemma 2 26B and MedGemma 1 27B: a tie within the noise, so the Apache licensed model, faster per token, wins it
Fastest small modelGemma 4 E4B271 tokens/s against 164 for MedGemma 2 E4B, because its Ollama build ships a speculative draft model
Apache 2.0 licence for a productGemma 4MedGemma 1, 1.5 and 2 all ship under the Health AI Developer Foundations terms
Skip itMedGemma 1 27B45/50 on MedQA, but 48.5 tokens/s, no tool support and an invented device in 3 of 3 X-ray runs

Gemma 4 is our pick for five of the eight jobs, so the default for text and tools is the Apache licensed model. The MedGemma models earned their place on images. That matches the model card, where MedGemma 1.5 still beats MedGemma 2 4B on several image classification benchmarks, and Google keeps it available for that reason. The other MedGemma 2 headline features (audio dictation, 128K EHR context and grounded answers) were outside these tests, so weigh them separately if your workload depends on them.

Benchmark results at a glance

The 4B class fits on any 8 GB card and the 26B class needs a 24 GB card at 32K context. X-ray scores count how many of the five findings in the image description each run named (sternotomy wires from the bypass surgery, enlarged heart, Kerley B or interstitial lines, dilated pulmonary vessels, pleural effusion). FHIR scores count runs that reported the correct eGFR of 35.0 and stage G3b for the synthetic patient.

4B classMedGemma 2 E4BGemma 4 E4BMedGemma 1.5 4B
MedQA, thinking on40/50 (80%)38/50 (76%)no thinking mode
MedQA, thinking off38/50 (76%)40/50 (80%)28/50 (56%)
Chest X-ray findings per run0, 0, 0 (invented a device each run)2, 2, 24, 4, 4
Skin lesion called melanoma3 of 33 of 33 of 3
FHIR eGFR with calculator2 of 3 exact, 3 of 3 stage3 of 3no tool support
FHIR eGFR without calculator0 of 30 of 3 exact, 1 of 3 stage (plus 1 hedged)no tool support
VRAM at 32K context5.5 GiB5.5 GiB4.8 GiB
Generation speed164 tokens/s271 tokens/s227 tokens/s
First answer token, thinking on3.32 s1.68 s0.03 s (no thinking)

The 26B class tells a different story, because the medical tuning shows up on the image and on the arithmetic:

26B classMedGemma 2 26BGemma 4 26BMedGemma 1 27B
MedQA, thinking on45/50 (90%)46/50 (92%)no thinking mode
MedQA, thinking off44/50 (88%)44/50 (88%)45/50 (90%)
Chest X-ray findings per run4, 4, 44, 5, 42, 2, 4 (invented a device each run)
Skin lesion called melanoma3 of 32 of 3 (1 run thought for 32,216 tokens and gave no answer)1 of 3 (nevus and dermatofibroma in the others)
FHIR eGFR with calculator3 of 33 of 3no tool support
FHIR eGFR without calculator0 of 3 exact, 2 of 3 within 0.30 of 3 exact, 3 of 3 stage, within 2.0no tool support
VRAM at 32K context19.2 GiB18.5 GiB20.1 GiB
Generation speed160 tokens/s182 tokens/s48.5 tokens/s
First answer token, thinking on3.20 s4.51 s0.12 s (no thinking)

Read the MedQA rows with their sample size in mind. One question is two percentage points. The 95% interval around a score of 80% on 50 questions runs from about 67% to 89%, so a two-question gap between two models is not a ranking. A gap of 10 or more questions is, which is why MedGemma 1.5 at 56% sits in a different class from the rest of the 4B row.

Both 26B models and MedGemma 1 27B score 88 to 92 percent, the E4B models 76 to 80 percent, and MedGemma 1.5 4B trails at 56 percent.Both 26B models and MedGemma 1 27B score 88 to 92 percent, the E4B models 76 to 80 percent, and MedGemma 1.5 4B trails at 56 percent.
MedQA accuracy on 50 test questions, Q4_K_M on Ollama

The chart shows the same pattern at both sizes. Thinking moved each model by two questions at most, in either direction, while the step from the 4B class to the 26B class was worth four to eight. If MedQA style accuracy matters to you, buy VRAM before you turn on thinking.

How we tested

Every model ran under the same Ollama server with the same options, and only the model tag changed between runs. These are the settings that apply to all of them:

  • GPU and host: NVIDIA RTX 4090 24 GB, driver 610.57.04, AMD EPYC 9474F with 32 vCPUs and 108 GiB of RAM, Ubuntu 24.04.5.
  • Server: Ollama 0.40.19 with OLLAMA_CONTEXT_LENGTH=32768, one loaded model and one parallel request, so each model had the card to itself.
  • Quantization: Q4_K_M for all six models, picked by explicit tag rather than the default tag.
  • Sampling: temperature 1.0, top_p 0.95, top_k 64 and seed 42 for MedQA, the values the MedGemma 2 card recommends and used for its own evaluations. The images and FHIR runs use the same three values without a seed.
  • Thinking budget: 8,192 output tokens per MedQA answer, the low end of the 8,192 to 16,384 range the MedGemma 2 card gives for thinking mode.
  • Timing: median of three warm runs, measured on the client side from the streaming API on the same host.

To halve the wall time, the 26B class accuracy runs (MedQA, images and FHIR) ran on a second RTX 4090 with the same CPU, driver and Ollama build. Every tokens per second, first token and VRAM figure comes from the first card, and only the per-answer seconds for the 26B class come from the second. Accuracy does not depend on which card produced the tokens, but speed does, so the speed table uses one box.

Our first MedQA pass used greedy decoding (temperature 0), which is the usual choice for multiple choice scoring. MedGemma 2 E4B spent all 8,192 tokens thinking about question 1 and never gave an answer. We stopped that pass and switched every model to the recommended sampling. The MedGemma 1.5 card uses greedy decoding in its own example, so we also ran it greedy as a check: 29 of 50, against 28 with sampling.

Which MedGemma 1.5 sizes exist

Google shipped MedGemma 1.5 on January 13, 2026 as a single 4B multimodal model, and Google never released a 1.5 version of the 27B. The 27B checkpoints on Hugging Face are MedGemma 1 from 2025. The medgemma page in the Ollama library still links the MedGemma 1 model card. We pulled MedGemma 1.5 from the unsloth GGUF repository instead, through the hf.co syntax in Ollama, because that repository names the 1.5 release. Unlike the Google repository, which requires accepting the terms on Hugging Face, the GGUF repository is not gated, and Ollama fetched the vision projector from it automatically.

ModelOllama tagSize (ollama list)LicenceOllama capabilities
MedGemma 2 E4Bmedgemma2:e4b-q4_K_M6.6 GBHAI-DEF termsvision, audio, tools, thinking
Gemma 4 E4Bgemma4:e4b-it-q4_K_M6.6 GBApache 2.0vision, audio, tools, thinking
MedGemma 1.5 4Bhf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M3.3 GBHAI-DEF termsvision
MedGemma 2 26B A4Bmedgemma2:26b-q4_K_M18 GBHAI-DEF termsvision, tools, thinking
Gemma 4 26B A4Bgemma4:26b-a4b-it-q4_K_M17 GBApache 2.0vision, tools, thinking
MedGemma 1 27Bmedgemma:27b-it-q4_K_M17 GBHAI-DEF termsvision

The licence column matters more than it looks. Gemma 4 is Apache 2.0, so you can ship it inside a product with the usual notice. Every MedGemma release falls under the Health AI Developer Foundations terms. They pass their use restrictions on to anyone you give the weights to, and they require health regulatory authorization where a clinical use needs it. The model card adds that MedGemma is not intended to directly inform diagnosis or treatment. None of these models is a clinical tool. Everything below uses synthetic patients and public domain images, and every answer is test output, not advice.

Step 1: Pull the six models and check capabilities

If Ollama is not installed yet, the MedGemma 2 setup guide covers the install, the service and the context length, and our Ollama install guide for Ubuntu goes deeper on the service itself. Pull each model by its Q4_K_M tag, so the default tag of one family cannot slip in a different quantization than the others:

for m in medgemma2:e4b-q4_K_M gemma4:e4b-it-q4_K_M hf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M medgemma2:26b-q4_K_M gemma4:26b-a4b-it-q4_K_M medgemma:27b-it-q4_K_M; do ollama pull $m; done

The six models take about 69 GB of disk together. Ask the API which capabilities each one reports, because the FHIR test needs tools and the thinking test needs thinking:

for m in $(ollama list | awk 'NR>1{print $1}'); do curl -s localhost:11434/api/show -d "{\"model\":\"$m\"}" | python3 -c "import json,sys; d=json.load(sys.stdin); print('$m:', ' '.join(d['capabilities']))"; done

Only the Gemma 4 based models list tools and thinking. Both Gemma 3 based MedGemma builds stop at completion and vision:

medgemma:27b-it-q4_K_M: completion vision
gemma4:26b-a4b-it-q4_K_M: completion vision tools thinking
medgemma2:26b-q4_K_M: completion vision tools thinking
hf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M: completion vision
gemma4:e4b-it-q4_K_M: completion vision audio tools thinking
medgemma2:e4b-q4_K_M: completion vision audio tools thinking

That output already settles part of the comparison. MedGemma 1.5 and MedGemma 1 cannot join a tool calling loop through Ollama at all. That matches the MedGemma 2 model card, which notes that MedGemma 1.5 does not support native tool calling. The E4B models also take audio, which we did not test here.

Step 2: Score each model on 50 MedQA questions

MedQA is a set of USMLE style questions with four options and a published answer key, from Jin et al. (2020). We used the 1,273 question test split from the GBaker/MedQA-USMLE-4-options dataset, which is published under CC BY 4.0, and drew a fixed sample of 50 with seed 42. Download the test file into a working directory:

mkdir -p ~/medbench && cd ~/medbench
curl -sL -o medqa_test.jsonl https://huggingface.co/datasets/GBaker/MedQA-USMLE-4-options/resolve/main/phrases_no_exclude_test.jsonl
wc -l medqa_test.jsonl

The file should hold 1,273 lines, one question each:

1273 medqa_test.jsonl

A short script draws the sample. It keeps the question, the options and the answer letter, and drops the rest. Create the file:

vim make_sample.py

Paste in the sampler:

#!/usr/bin/env python3
"""Draw a fixed 50-question sample from the MedQA (USMLE, 4-option) test split."""
import json
import random
import sys

src, dst, n = sys.argv[1], sys.argv[2], int(sys.argv[3]) if len(sys.argv) > 3 else 50
rows = [json.loads(line) for line in open(src)]
picked = sorted(random.Random(42).sample(range(len(rows)), n))
with open(dst, "w") as f:
    for i in picked:
        r = rows[i]
        f.write(json.dumps({"idx": i, "question": r["question"], "options": r["options"],
                            "answer_idx": r["answer_idx"], "step": r["meta_info"]}) + "\n")
print(f"{n} of {len(rows)} questions written to {dst}")

Draw the sample. The same seed gives the same 50 questions on any machine, so your scores compare directly with ours:

python3 make_sample.py medqa_test.jsonl medqa_sample50.jsonl 50

Our sample holds 26 Step 1 and 24 Step 2 and 3 questions, with the correct letter spread 15 A, 9 B, 13 C and 13 D:

50 of 1273 questions written to medqa_sample50.jsonl

The evaluation script sends each question to the Ollama chat API and asks for a final Answer: X line. It saves every reply, so you can re-score or read any answer later. Open a new file for it:

vim medqa_eval.py

Add the evaluation code. The OPTIONS line holds the sampling settings every model gets:

#!/usr/bin/env python3
"""Ask an Ollama model every MedQA question in a sample file and score the letters it picks.

usage: medqa_eval.py <model> <think: on|off|default> <sample.jsonl> <out.jsonl>
"""
import json
import re
import sys
import time
import urllib.request

OLLAMA = "http://127.0.0.1:11434/api/chat"
model, think, sample, out = sys.argv[1:5]
OPTIONS = {"temperature": 1.0, "top_p": 0.95, "top_k": 64, "seed": 42, "num_ctx": 32768, "num_predict": 8192}
ANSWER = re.compile(r"answer\s*(?:is)?\s*[::]?\s*\**\s*\(?([ABCD])\b", re.I)


def ask(prompt):
    body = {"model": model, "messages": [{"role": "user", "content": prompt}],
            "stream": False, "options": OPTIONS}
    if think != "default":
        body["think"] = think == "on"
    req = urllib.request.Request(OLLAMA, data=json.dumps(body).encode(),
                                 headers={"Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=1800) as r:
        return json.load(r)


rows = [json.loads(line) for line in open(sample)]
right = 0
with open(out, "w") as f:
    for n, q in enumerate(rows, 1):
        opts = "\n".join(f"{k}. {v}" for k, v in sorted(q["options"].items()))
        prompt = (f"{q['question']}\n\n{opts}\n\nChoose the single best option. "
                  "End your reply with one line in the form: Answer: <letter>")
        t0 = time.time()
        r = ask(prompt)
        text = r["message"].get("content", "")
        hits = ANSWER.findall(text)
        pred = hits[-1].upper() if hits else None
        ok = pred == q["answer_idx"]
        right += ok
        f.write(json.dumps({"idx": q["idx"], "gold": q["answer_idx"], "pred": pred, "correct": ok,
                            "eval_count": r.get("eval_count"), "seconds": round(time.time() - t0, 2),
                            "thinking_chars": len(r["message"].get("thinking") or ""),
                            "content": text}) + "\n")
        f.flush()
        print(f"{n:2d}/{len(rows)} idx={q['idx']:4d} gold={q['answer_idx']} pred={pred} "
              f"{'ok' if ok else 'WRONG'} tokens={r.get('eval_count')} {time.time() - t0:.1f}s", flush=True)
print(f"ACCURACY {model} think={think}: {right}/{len(rows)} = {100 * right / len(rows):.1f}%")

Run it once per model and mode. The second argument switches thinking on or off, and default sends no thinking flag, which the two MedGemma builds without a thinking mode need:

python3 medqa_eval.py gemma4:e4b-it-q4_K_M off medqa_sample50.jsonl medqa-gemma4-e4b-nothink.jsonl
python3 medqa_eval.py medgemma2:e4b-q4_K_M on medqa_sample50.jsonl medqa-medgemma2-e4b-think.jsonl
python3 medqa_eval.py hf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M default medqa_sample50.jsonl medqa-medgemma15.jsonl

Each line shows the gold letter, the letter the model picked, the tokens it generated and the seconds it took. This is the start of Gemma 4 E4B with thinking off:

 1/50 idx=  13 gold=D pred=D ok tokens=965 4.2s
 2/50 idx=  51 gold=A pred=A ok tokens=887 3.3s
 3/50 idx=  54 gold=A pred=A ok tokens=366 1.5s
 4/50 idx=  61 gold=A pred=A ok tokens=419 1.8s
 5/50 idx=  65 gold=B pred=B ok tokens=442 1.9s
 6/50 idx=  88 gold=C pred=C ok tokens=604 2.6s
 7/50 idx= 161 gold=B pred=B ok tokens=351 1.4s
 8/50 idx= 178 gold=D pred=D ok tokens=856 3.6s
 9/50 idx= 189 gold=C pred=B WRONG tokens=343 1.5s
10/50 idx= 191 gold=C pred=D WRONG tokens=448 2.0s

One model ignored the format. MedGemma 1.5 skipped the requested answer line in 9 of its 50 replies. Six of those ended with LaTeX instead (The final answer is $\boxed{A}$), and the live counter in medqa_eval.py scored them as wrong. Scoring from the saved replies fixes that. Create the scorer:

vim score.py

It takes the last answer line or boxed letter in each reply, and a reply with neither still counts as wrong:

#!/usr/bin/env python3
"""Score medqa_eval.py result files from the saved replies.

Takes the last "Answer: X" or \\boxed{X} in each reply, since MedGemma 1.5 ignores the requested
format and ends with LaTeX instead. A reply with neither, or one cut off at the token cap, scores wrong.
"""
import json
import re
import sys

PICK = re.compile(r"answer\s*(?:is)?\s*[::]?\s*\**\s*\(?([ABCD])\b|\\boxed\{\s*([ABCD])\s*\}", re.I)


def letter(text):
    hits = [(m.group(1) or m.group(2)).upper() for m in PICK.finditer(text)]
    return hits[-1] if hits else None


print(f"{'run':52} {'correct':>8} {'acc%':>6} {'no letter':>9} {'capped':>6} {'avg tok':>8} {'avg s':>6}")
for path in sys.argv[1:]:
    rows = [json.loads(line) for line in open(path)]
    picks = [letter(r["content"]) for r in rows]
    ok = sum(p == r["gold"] for p, r in zip(picks, rows))
    none = sum(p is None for p in picks)
    capped = sum((r["eval_count"] or 0) >= 8192 for r in rows)
    tok = sum(r["eval_count"] or 0 for r in rows) / len(rows)
    sec = sum(r["seconds"] for r in rows) / len(rows)
    name = path.rsplit("/", 1)[-1]
    print(f"{name:52} {ok:>3}/{len(rows):<4} {100 * ok / len(rows):6.1f} {none:9d} {capped:6d} {tok:8.0f} {sec:6.1f}")

Score all the result files together:

python3 score.py medqa-*.jsonl

These are our six models in both modes, gathered from the two cards into one table. capped counts answers that used the whole 8,192 token budget. no letter counts replies with no answer in them:

run                                                   correct   acc% no letter capped  avg tok  avg s
medqa-gemma4_e4b-it-q4_K_M-nothink.jsonl              40/50     80.0         0      0      602    2.5
medqa-gemma4_e4b-it-q4_K_M-think.jsonl                38/50     76.0         0      0     1107    4.3
medqa-medgemma-1.5-4b-it-GGUF_Q4_K_M-default.jsonl    28/50     56.0         3      0      723    3.4
medqa-medgemma-1.5-greedy.jsonl                       29/50     58.0         5      1      810    4.0
medqa-medgemma2_e4b-q4_K_M-nothink.jsonl              38/50     76.0         0      0      624    3.9
medqa-medgemma2_e4b-q4_K_M-think.jsonl                40/50     80.0         5      5     3932   24.8
medqa-gemma4_26b-a4b-it-q4_K_M-nothink.jsonl          44/50     88.0         0      0      444    2.5
medqa-gemma4_26b-a4b-it-q4_K_M-think.jsonl            46/50     92.0         2      2     3518   20.4
medqa-medgemma_27b-it-q4_K_M-default.jsonl            45/50     90.0         0      0      650   14.1
medqa-medgemma2_26b-q4_K_M-nothink.jsonl              44/50     88.0         0      0      374    2.4
medqa-medgemma2_26b-q4_K_M-think.jsonl                45/50     90.0         2      2     2545   18.5

Three results in that table change how you would run these models:

  • Thinking is expensive on MedGemma 2 E4B: it cost six times the tokens (3,932 per answer against 624) for two extra correct answers.
  • The token cap took real answers: five MedGemma 2 E4B replies hit 8,192 tokens with no letter, so they count as wrong whatever the model would have concluded.
  • Gemma 4 thinks more briefly: 1,107 tokens per answer at E4B, and it scored two fewer with thinking on than off.

At 26B, thinking added one question for MedGemma 2 and two for Gemma 4, at seven to eight times the tokens. For bulk question answering, thinking off is the better trade at both sizes.

The MedGemma 2 card reports 82.3% on MedQA (4 options) for MedGemma 2 4B, 74.0% for Gemma 4 E4B and 69.1% for MedGemma 1.5 4B, for the original weights that its quantization note calls BF16. Our MedGemma 2 E4B result of 80% sits next to that, and our Gemma 4 E4B result of 76 to 80% sits above it. MedGemma 1.5 landed at 56% with sampling and 58% greedy, 11 to 13 points under its card. The card warns that quantized builds can behave differently from the BF16 weights, so treat that gap as the price of a 3.3 GB community GGUF.

MedGemma 1 27B, the oldest model here, scored 45 of 50. That is level with MedGemma 2 26B and in line with the 85.3% the MedGemma 1.5 card lists for it. It needed 14.1 seconds per answer, though, against 2.4 for MedGemma 2 26B with thinking off.

Step 3: Read a chest X-ray and a skin lesion

Each model saw two openly licensed images three times, at the recommended sampling. The first is the chest X-ray from our MedGemma 2 guide, released under CC0 by Mikael Häggström on Wikimedia Commons. Its description gives the ground truth: an 83 year old man after bypass surgery, with distinct Kerley B lines, an enlarged heart, somewhat dilated pulmonary vessels and a minor pleural effusion. It adds that there is no obvious lung edema and sums the film up as stage II heart failure.

De-identified frontal chest X-ray with cardiomegaly, sternotomy wires and Kerley B lines used to test MedGemma 2

The second is a public domain clinical photograph of a melanoma from the US National Cancer Institute, also on Wikimedia Commons. It tests dermatology, the other image domain MedGemma 2 claims.

Clinical photograph of an irregular dark melanoma on skin used to test MedGemma 2, Gemma 4 and MedGemma 1.5

Download both images. Wikimedia refuses requests without a descriptive user agent, so set one:

curl -fsSL -A "medgemma-lab/1.0 (https://computingforgeeks.com/)" -o chest-xray-kerley-b-lines.jpg https://upload.wikimedia.org/wikipedia/commons/c/ca/Chest_radiograph_of_a_lung_with_Kerley_B_lines.jpg
curl -fsSL -A "medgemma-lab/1.0 (https://computingforgeeks.com/)" -o melanoma-nci.jpg https://upload.wikimedia.org/wikipedia/commons/6/6c/Melanoma.jpg

Put each prompt in a text file, so every model gets exactly the same words:

echo "You are reviewing a de-identified frontal chest radiograph for a teaching exercise. Describe the key findings in a short structured report (devices, heart size, lungs, pleura), then give an impression." > xray_prompt.txt
echo "You are reviewing a de-identified clinical photograph of a skin lesion for a teaching exercise. Describe the lesion (shape, border, colour, surface), give the most likely diagnosis with a short differential, and say whether it needs urgent referral." > skin_prompt.txt

The image script sends one image and one prompt to a model as many times as you ask, and prints each reply with its token counts. Create it:

vim image_eval.py

Paste in the image runner:

#!/usr/bin/env python3
"""Send one image and prompt to an Ollama model N times; print each reply with its token stats.

usage: image_eval.py <model> <image> <prompt-file> [runs]
"""
import base64
import json
import sys
import time
import urllib.request

model, image, prompt_file = sys.argv[1:4]
runs = int(sys.argv[4]) if len(sys.argv) > 4 else 3
prompt = open(prompt_file).read().strip()
img = base64.b64encode(open(image, "rb").read()).decode()
OPTIONS = {"temperature": 1.0, "top_p": 0.95, "top_k": 64, "num_ctx": 32768}

for run in range(1, runs + 1):
    body = {"model": model, "stream": False, "options": OPTIONS,
            "messages": [{"role": "user", "content": prompt, "images": [img]}]}
    req = urllib.request.Request("http://127.0.0.1:11434/api/chat", data=json.dumps(body).encode(),
                                 headers={"Content-Type": "application/json"})
    t0 = time.time()
    with urllib.request.urlopen(req, timeout=1800) as r:
        d = json.load(r)
    m = d["message"]
    print(f"===== {model} run {run}")
    print(m.get("content", "").strip())
    print(f"--- thinking chars: {len(m.get('thinking') or '')}, prompt tokens: {d.get('prompt_eval_count')}, "
          f"output tokens: {d.get('eval_count')}, "
          f"tok/s: {d['eval_count'] / (d['eval_duration'] / 1e9):.1f}, wall: {time.time() - t0:.1f}s\n", flush=True)

Run it for each model and image, for example the small MedGemma 2 on the X-ray:

python3 image_eval.py medgemma2:e4b-q4_K_M chest-xray-kerley-b-lines.jpg xray_prompt.txt 3

MedGemma 2 E4B repeated the failure from our first guide. All three runs called the heart normal and the lungs clear. Each one also invented a different device: a pacemaker, then a central venous catheter, then a port and a catheter:

===== medgemma2:e4b-q4_K_M run 1
**Findings:**

*   **Devices:** A right-sided pacemaker is present with leads visible extending toward the right atrium and right ventricle.
*   **Heart size:** The heart size is normal.
*   **Lungs:** The lungs are clear. There are no focal opacities, consolidations, or masses.
*   **Pleura:** There is no pleural effusion or pneumothorax.

**Impression:**

No acute cardiopulmonary process.
--- thinking chars: 1155, prompt tokens: 634, output tokens: 394, tok/s: 160.9, wall: 14.1s

At less than half the VRAM, MedGemma 1.5 got four of five findings on the same image in all three runs. It named the sternotomy wires, the enlarged heart, the interstitial markings and an effusion in each run, in about 100 tokens and under a second:

===== hf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M run 1
FINDINGS:

*   **Devices:** Sternotomy wires are present.
*   **Heart Size:** Cardiomegaly is present.
*   **Lungs:** Bilateral pulmonary edema is present. There is also reticular opacities.
*   **Pleura:** Small bilateral pleural effusions are present.

IMPRESSION:

*   Cardiomegaly with pulmonary edema and bilateral pleural effusions.
--- thinking chars: 0, prompt tokens: 308, output tokens: 88, tok/s: 220.3, wall: 0.7s

The full scorecard for the X-ray, counting runs out of three that named each finding:

ModelWiresBig heartInterstitial linesEffusionInvented device
MedGemma 2 E4B00003
Gemma 4 E4B03301
MedGemma 1.5 4B33330
MedGemma 2 26B33330
Gemma 4 26B33330
MedGemma 1 27B12323

A finding counts when the report states it as present or suggested. A hedge such as “no large effusion, mild blunting may be present” does not count. Most runs that saw the interstitial lines also called frank pulmonary edema, which over-reads a film the description says has no obvious edema, although their heart failure impressions match it. On that rule Gemma 4 E4B saw the large heart and the interstitial pattern every time but missed the wires and the effusion. In run 3 it read the same lines as interstitial lung disease instead of heart failure. That still beats MedGemma 2 E4B, which reported a normal study with a device that is not there.

At 26B, Gemma 4 matched MedGemma 2 on the four main findings and went one further in run 2. It called the hila prominent and described pulmonary venous congestion, the closest any run came to the dilated vessels. MedGemma 1 27B was the only model to mention possible Kerley B lines, yet it invented a chest tube, a tracheostomy tube or a catheter in every run.

The skin lesion was easier. MedGemma 2 at both sizes, Gemma 4 E4B and MedGemma 1.5 named melanoma first and asked for urgent referral in all 12 of their runs. Gemma 4 26B did the same twice. Its first run thought for 32,216 tokens, filled the 32K context in 197 seconds and returned an empty answer, so give thinking models an output cap. MedGemma 1 27B called the lesion a benign nevus in one run and found it “hard to justify urgent referral”, the kind of answer that would hurt a patient. In another run it led with dermatofibroma but still asked for urgent referral.

Step 4: Test FHIR tool calling and eGFR math

This test reuses the HAPI FHIR server, the Synthea population (-p 25, seed 42) and the fhir_agent.py script from our MedGemma 2 guide, which covers both setups step by step. The model has to find the patient Tremblay, read his latest serum creatinine, compute eGFR with the CKD-EPI 2021 equation and name the CKD stage. For this patient (male, born 1978-04-17, creatinine 2.2549 mg/dL on 2026-11-30) the right answer is 35.0 mL/min/1.73m² and stage G3b.

Our GPU host was a container with no Docker, so we ran HAPI FHIR from the WAR file inside the hapiproject/hapi image with Java 21, bound to 127.0.0.1:8080. On a normal Ubuntu host, the Docker command from the guide gives you the same server on the same port:

sudo docker run -d --name hapi-fhir --restart unless-stopped -p 127.0.0.1:8080:8080 hapiproject/hapi:latest

Synthea dates everything relative to the day you run it, so your population may differ from ours (31 patients here, 29 in the guide). If there is no Tremblay in your list, pick a patient with a CKD condition, pass your own question as the second argument, and use the egfr_ckd_epi_2021 tool result as your reference value.

To test the arithmetic of the model itself, we added a --no-calc flag that removes the egfr_ckd_epi_2021 tool from the schema list before the first request. Open the script from the guide:

vim ~/fhir_agent.py

Add these three lines above the OLLAMA = line, so the flag is read before the script uses its arguments:

NO_CALC = "--no-calc" in sys.argv
if NO_CALC:
    sys.argv.remove("--no-calc")

Then add these two lines above def chat(messages):, after the SCHEMAS list:

if NO_CALC:
    SCHEMAS = [s for s in SCHEMAS if s["function"]["name"] != "egfr_ckd_epi_2021"]

Run each model three times in each mode. The model name is the first argument, as in the guide:

python3 ~/fhir_agent.py medgemma2:26b-q4_K_M
python3 ~/fhir_agent.py medgemma2:26b-q4_K_M --no-calc

Both Gemma 3 based models, MedGemma 1.5 and MedGemma 1, fail on the first request with HTTP Error 400: Bad Request, because Ollama refuses a tools list for a model without tool support. The API body names the reason:

{"error":"hf.co/unsloth/medgemma-1.5-4b-it-GGUF:Q4_K_M does not support tools"}
{"error":"registry.ollama.ai/library/medgemma:27b-it-q4_K_M does not support tools"}

With the calculator available, every tool capable model called it in every run. The one slip came from MedGemma 2 E4B in its second run, which passed the creatinine from 2025-12-01 instead of the newest one and reported 34.2. That is still stage G3b, but the prompt asked for the most recent value:

[tool call] egfr_ckd_epi_2021({"birth_date": "1978-04-17", "creatinine_mg_dl": 2.3101, "on_date": "2025-12-01", "sex": "male"})
[result]    {"age": 47, "egfr": 34.2, "unit": "mL/min/1.73m2", "stage": "G3b"}

Without the calculator the models had to do the CKD-EPI arithmetic in their heads, and this is where size mattered most. These are the eGFR values and stages each run reported, against 35.0 and G3b:

ModelRun 1Run 2Run 3
MedGemma 2 E4B28.56, stage “3a”19.76, stage 426.11, stage 4
Gemma 4 E4B46, stage 3a42, stage 3bno number, stage 3b “or possibly Stage 4”
MedGemma 2 26B35.3, stage 3b34.7, stage 3b29.1, stage 4
Gemma 4 26B34.6, stage 3b33, stage G3babout 33, stage G3b

MedGemma 2 26B landed within 0.3 of the answer in runs 1 and 2, and run 2 wrote out the 2021 equation with every constant right. Its third run printed an exponent of -0.411, which is not in the 2021 equation. That term drops out here because the creatinine is above 0.9, so the stage 4 result came from a plain multiplication error. The small models were further off. MedGemma 2 E4B labelled 28.56 as stage 3a and then went lower. Gemma 4 E4B claimed in run 3 that CKD-EPI 2021 needs the race of the patient, the one input the 2021 revision removed. Gemma 4 26B did best without the tool, with 34.6, 33 and about 33, all in stage G3b. Its third run first sent a malformed patient ID and had to repeat the lookup. The rule from our first guide holds for every model here: give the model the calculator and keep the arithmetic in code.

Step 5: Measure VRAM, speed and first token time

Speed and memory came from a separate script that streams the response. That lets it time the first token of any kind and the first token of the visible answer. With thinking on, those two differ by the time the model spends thinking. Open a file for it:

vim perf.py

Add the timing code:

#!/usr/bin/env python3
"""Time to first token and generation speed for one Ollama model at 32K context (streaming API).

usage: perf.py <model> <think: on|off|default> [runs]
"""
import json
import subprocess
import sys
import time
import urllib.request

model, think = sys.argv[1:3]
runs = int(sys.argv[3]) if len(sys.argv) > 3 else 3
PROMPT = ("A 67-year-old man with type 2 diabetes has a serum creatinine of 1.4 mg/dL. In five short bullet "
          "points, explain what eGFR measures and why it matters for metformin dosing.")
OPTIONS = {"temperature": 1.0, "top_p": 0.95, "top_k": 64, "num_ctx": 32768, "seed": 42}


def stream(prompt):
    body = {"model": model, "stream": True, "options": OPTIONS,
            "messages": [{"role": "user", "content": prompt}]}
    if think != "default":
        body["think"] = think == "on"
    req = urllib.request.Request("http://127.0.0.1:11434/api/chat", data=json.dumps(body).encode(),
                                 headers={"Content-Type": "application/json"})
    t0, first_any, first_answer, last = time.time(), None, None, None
    with urllib.request.urlopen(req, timeout=1800) as r:
        for line in r:
            d = json.loads(line)
            m = d.get("message", {})
            now = time.time() - t0
            if first_any is None and (m.get("content") or m.get("thinking")):
                first_any = now
            if first_answer is None and m.get("content"):
                first_answer = now
            if d.get("done"):
                last = d
    return first_any, first_answer, last


load_start = time.time()
_, _, warm = stream("Say ready.")
print(f"== {model} think={think}  first request incl. load: {time.time() - load_start:.1f}s "
      f"(load_duration {warm['load_duration'] / 1e9:.1f}s)")
for i in range(1, runs + 1):
    fa, fans, d = stream(PROMPT)
    tps = d["eval_count"] / (d["eval_duration"] / 1e9)
    pps = d["prompt_eval_count"] / max(d["prompt_eval_duration"] / 1e9, 1e-9)
    print(f"run {i}: ttft_any={fa:.3f}s ttft_answer={fans:.3f}s output_tokens={d['eval_count']} "
          f"gen_tok/s={tps:.1f} prompt_tokens={d['prompt_eval_count']} prompt_tok/s={pps:.0f} "
          f"total={d['total_duration'] / 1e9:.2f}s", flush=True)
print(subprocess.run(["ollama", "ps"], capture_output=True, text=True).stdout.strip())
print("nvidia-smi memory.used:", subprocess.run(
    ["nvidia-smi", "--query-gpu=memory.used", "--format=csv,noheader"], capture_output=True, text=True).stdout.strip())

It sends a short warm-up and three timed runs of a fixed clinical prompt at 32K context, then prints ollama ps and the GPU memory in use:

python3 perf.py gemma4:e4b-it-q4_K_M default 3

Gemma 4 E4B ran at about 270 tokens per second with thinking on, and the first visible answer token arrived 1.7 seconds after the request:

== gemma4:e4b-it-q4_K_M think=default  first request incl. load: 15.9s (load_duration 15.8s)
run 1: ttft_any=0.097s ttft_answer=1.679s output_tokens=637 gen_tok/s=268.2 prompt_tokens=62 prompt_tok/s=750 total=2.46s
run 2: ttft_any=0.069s ttft_answer=1.700s output_tokens=656 gen_tok/s=270.9 prompt_tokens=62 prompt_tok/s=1422 total=2.48s
run 3: ttft_any=0.043s ttft_answer=1.665s output_tokens=656 gen_tok/s=272.4 prompt_tokens=62 prompt_tok/s=3798 total=2.44s
NAME                    ID              SIZE      PROCESSOR    CONTEXT    RUNNER      UNTIL
gemma4:e4b-it-q4_K_M    dc35e8d9c606    593 MB    100% GPU     32768      llamacpp    9 minutes from now
nvidia-smi memory.used: 5648 MiB

Ignore the SIZE column for this model. ollama ps reported 593 MB for Gemma 4 E4B while nvidia-smi showed 5,648 MiB in use. Every VRAM figure here comes from nvidia-smi, with nothing else on the card. The medians across the three runs:

ModelVRAM at 32KTokens/s (thinking on / off)First token (any / answer)First token, thinking off
MedGemma 2 E4B5.5 GiB163.7 / 165.10.040 s / 3.324 s0.019 s
Gemma 4 E4B5.5 GiB270.9 / 243.80.069 s / 1.679 s0.027 s
MedGemma 1.5 4B4.8 GiB226.6 (no thinking)0.031 s0.031 s
MedGemma 2 26B19.2 GiB159.6 / 161.20.122 s / 3.203 s0.049 s
Gemma 4 26B18.5 GiB181.6 / 181.00.154 s / 4.513 s0.044 s
MedGemma 1 27B20.1 GiB48.5 (no thinking)0.124 s0.124 s

The 107 token per second gap between the two E4B models has nothing to do with the medical training. The Ollama log shows that Gemma 4 E4B starts its llama-server with a multi-token prediction draft model for speculative decoding, and MedGemma 2 E4B starts without one:

--spec-type draft-mtp --spec-draft-n-max 3 --spec-draft-backend-sampling --spec-draft-model /root/.ollama/models/blobs/sha256-05612e54110f8f68bade01dfcc546cdc6914d11dde0b650a65f263f0f87bbbd2

Speculative decoding drafts up to three tokens ahead and keeps the ones the main model agrees with, so it speeds up generation without changing what the model is. A MedGemma 2 build with a draft model would likely close most of that gap. Until one appears, Gemma 4 E4B is the fastest model here by a wide margin. At 26B neither build ships a draft model, and the gap shrinks to 22 tokens per second.

The thinking rows matter more than raw speed for chat use. MedGemma 2 thinks before every answer by default, so its first visible token arrives after 3.2 to 3.3 seconds at both sizes, against 0.02 to 0.05 seconds with thinking off. MedGemma 1 27B is a dense model with all 27 billion parameters active per token, so it generates 48.5 tokens per second. The two 26B mixture of experts models activate about 4 billion parameters per token and run three times faster in less memory. Our GPU guide for local LLMs maps VRAM to model size if you are buying a card, and the Ollama models cheat sheet lists what else fits on the same cards.

Why these results differ from the model card

The MedGemma 2 card shows MedGemma 2 ahead of Gemma 4 on almost every medical benchmark it lists. At the 4B size that includes 82.3% against 74.0% on MedQA and 59.1% against 37.9% on MedCalc-Bench. Our runs did not reproduce that gap, and four differences in method explain most of it:

  • Sample size: 50 MedQA questions put a 95% interval of about 22 points around each score, so the 8 point E4B gap on the card fits inside our noise.
  • Weights: the card measures the original weights (BF16, per its quantization note), we ran Q4_K_M, and the card says quantized builds should be validated separately.
  • Thinking budget: MedGemma 2 E4B lost 5 of 50 answers to the 8,192 token cap, and a 16,384 budget would likely recover some.
  • Task shape: one patient, one X-ray and one skin photo are spot checks, while the FHIR, calculation and imaging numbers on the card come from full benchmark sets.

None of that makes the local numbers less useful, because they are the numbers you get from the builds people actually pull. What they tell you is to test your own task before you trust a model card ranking. Start with Gemma 4 for text and tool calling, and keep MedGemma 1.5 4B for image reads on a small card. Use MedGemma 2 26B when one 24 GB card has to handle images, tools and text together. It was the only model with no failed run across both images and the FHIR loop with its calculator. If several people will query it at once, compare the serving stacks in our Ollama vs vLLM vs llama.cpp benchmark before you settle on Ollama for production.

Keep reading

Run Amazon Ergo Locally: Hardware Requirements and vLLM Setup AI Run Amazon Ergo Locally: Hardware Requirements and vLLM Setup Open Source LLM Comparison Table (2026) AI Open Source LLM Comparison Table (2026) Ollama Models Cheat Sheet: Best Models by VRAM, Tested (PDF) AI Ollama Models Cheat Sheet: Best Models by VRAM, Tested (PDF) AI NAS Explained: Is Local AI on a NAS Worth It? AI AI NAS Explained: Is Local AI on a NAS Worth It? Build a FHIR MCP Server for MedGemma 2 with Ollama AI Build a FHIR MCP Server for MedGemma 2 with Ollama Gemini 4 Neon: Pricing, API Access and What Changed AI Gemini 4 Neon: Pricing, API Access and What Changed

Leave a Comment

Press ESC to close