Skip to main content

med-vlm-mlx

Run MedGemma locally on Apple Silicon. Includes Python, CLI and HTTP interfaces.

PyPI Python License Apple Silicon Hugging Face MedMLX

Chest radiograph beside the description MedGemma 1.5 4B generated for it

MedGemma 1.5 4B output for Mikael Häggström's chest radiograph, CC0 1.0.

Input Output
Image + text prompt Generated text
Model Weights download Peak MLX memory
MedGemma 1.5 4B 3.4 GB 4.4 GB
MedGemma 4B 3.0 GB 4.1 GB
MedGemma 27B 16.9 GB 17.9 GB

Peak memory is for describing a 1929×2207 chest radiograph in up to 256 tokens.

Install

uv venv --python 3.13
source .venv/bin/activate
uv pip install "med-vlm-mlx>=0.4.0"

The package imports as mlx_vlm, so install it in a separate environment from upstream mlx-vlm: both install the same modules.

Run

Download the pinned MedGemma 1.5 4B weights, then run:

uvx --from huggingface_hub hf download mlx-community/medgemma-1.5-4b-it-4bit \
  --revision 762746b7a72b0b68dd8fa3f9aea5dc3980674d23 --local-dir medgemma

python -m mlx_vlm.generate \
  --model medgemma --image image.png \
  --prompt 'Describe the image.' --max-tokens 128

Weights

Model MLX weights Revision
MedGemma 1.5 4B mlx-community/medgemma-1.5-4b-it-4bit 762746b7a72b0b68dd8fa3f9aea5dc3980674d23
MedGemma 4B (v1) mlx-community/medgemma-4b-it-4bit db10be5ae6bd569e2063c3c74b9b9dfbcbedcad3
MedGemma 27B multimodal mlx-community/medgemma-27b-it-4bit f57d2d648d28950b1bc7abd6e1b7b06aff0e183a

All three are 4-bit Gemma3 image-text checkpoints; other architectures are rejected. The mlx-community copies are not gated, but the Health AI Developer Foundations terms still apply.

Command line

Command Purpose
python -m mlx_vlm generate Generate text from a prompt and optional images
python -m mlx_vlm convert Convert or quantize a Gemma3 checkpoint to MLX
python -m mlx_vlm server Serve an OpenAI-compatible HTTP API

The mlx_vlm.generate, mlx_vlm.convert and mlx_vlm.server console scripts call the same entry points; add --help for every option. generate takes:

Option Default Meaning
--model mlx-community/medgemma-1.5-4b-it-4bit Model folder or Hub ID; --revision pins a commit
--image Image paths or URLs; prompts without images also work
--prompt Required User prompt
--system System prompt
--max-tokens 2048 Generation limit
--temperature 0 (greedy) Sampling temperature
--top-p, --top-k Sampling cutoffs
--seed 0 Random seed
--prefill-step-size Prefill chunk size
--verbose Streams the text with token timings

Python API

import mlx.core as mx
from mlx_vlm import apply_chat_template, generate, load

if not mx.metal.is_available():
    raise RuntimeError("This example requires Metal")
mx.set_default_device(mx.gpu)

model, processor = load("medgemma", strict=True)
prompt = apply_chat_template(processor, model.config, "Describe this image.", num_images=1)
response = generate(
    model, processor, prompt, image=["image.png"], max_tokens=128, temperature=0.0
)
print(response.text)
  • load takes a local folder, or a Hub ID with revision. With local_files_only=True (and an optional cache_dir) it uses only the Hugging Face cache and raises instead of downloading.
  • stream_generate takes the same arguments and yields GenerationResult text segments; the prompt cache is saved before the final result, which has finish_reason and token_ids, including the stop token.
  • batch_generate shares the same generation and cache code.

HTTP server

python -m mlx_vlm.server --host 127.0.0.1 --port 8080 --model medgemma

curl http://127.0.0.1:8080/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"medgemma","messages":[{"role":"user","content":"What is 2 + 2?"}],"max_tokens":16}'

The server binds 127.0.0.1:8080 by default; schemas are at /docs while it runs.

Endpoint Purpose
/v1/chat/completions Chat completions
/v1/models Available models
/health Health check
/metrics Metrics
/v1/settings Runtime settings
  • --api-key requires a bearer token for inference and management requests, and is required when binding outside loopback.
  • --model-dir adds folders to search for models.
  • Images use a base64 data:image/... URI in an image_url content part next to the text.
  • Requests are batched when their sampling, seed and logprob settings match; others wait their turn in queue order.

Inputs and limitations

  • Text and images only. Requests with audio, video, tool definitions or tool-call turns are rejected.
  • Only MedGemma (Gemma3) checkpoints load. Checkpoint Python code (model_file) and external speculative drafters are refused.
  • Inference only, on Metal: no training or adapters.
  • A prefill chunk that would end inside an image extends to the end of that image, because an image's tokens attend to each other in both directions, so chunks with images can exceed --prefill-step-size.
  • Clinical accuracy has not been evaluated.

Use with MedMLX

Run MedGemma from an MCP client with the MedMLX MCP server. MedMLX manages a separate environment for medgemma. Supply local weights as weights_path; see the bridge guide.

uv tool install --python 3.13 "medmlx[mcp]"
MEDMLX="$(uv tool dir --bin --color never)/medmlx"
mkdir -p "$HOME/medmlx-work"
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"

For Codex, use codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work". Other MCP clients take the same command and arguments. The same install provides the medmlx CLI, for example medmlx describe medgemma.

For AI agents: prefer the MedMLX MCP tools (list_models, describe_model, model_readiness, run_model, get_job) over writing Python against this package.

License

MIT, with Apache-2.0 adaptations. See LICENSE and third-party notices. MedGemma weights are subject to the Health AI Developer Foundations terms.

Metadata

Release files for med-vlm-mlx 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for med-vlm-mlx 0.4.0
File Size Uploaded Provenance Actions
med_vlm_mlx-0.4.0.tar.gz 170.1 kB Without provenance Details for med_vlm_mlx-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for med-vlm-mlx 0.4.0
File Interpreter ABI Platform Actions
med_vlm_mlx-0.4.0-py3-none-any.whl Python 3 none any Details for med_vlm_mlx-0.4.0-py3-none-any.whl

Total release size: 360.2 kB

Release files / med_vlm_mlx-0.4.0.tar.gz

Download URL med_vlm_mlx-0.4.0.tar.gz
Size 170.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7cf2d4b6299b7886c1b9bf8d3637875e0d787242890b37f306aacf835b6ac22b
BLAKE2b-256 checksum
How to use checksums
9d3f8497375e58af865bd1d267201c8a955854e948aa17e5fc0182a70e8cb709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / med_vlm_mlx-0.4.0-py3-none-any.whl

Download URL med_vlm_mlx-0.4.0-py3-none-any.whl
Size 190.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb5fdd5c29cfbd3ee0369c2621caee6ae17480dd948f090738161856a822f0ec
BLAKE2b-256 checksum
How to use checksums
6fb71a5930f19bba537b660d7efc451fb4190677678b9b4737c41107df8d0b61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for med-vlm-mlx 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page