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

Model weights · MedMLX

Input Output
Image + text prompt Generated text

Weights: 3.4 GB (MedGemma 1.5 4B), 3.0 GB (MedGemma 4B) or 16.9 GB (MedGemma 27B) download. Peak MLX memory to describe a 1929×2207 chest radiograph in up to 256 tokens: 4.4 GB (MedGemma 1.5 4B), 4.1 GB (MedGemma 4B) and 17.9 GB (MedGemma 27B).

Use with MedMLX

The MedMLX MCP server is the lowest-friction way to use MedGemma. MedMLX runs this package in its own isolated environment as the provisional medgemma model, so an AI agent can describe, check and run it for you. Pass a local MedGemma folder as weights_path; see the bridge setup and limits.

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.

Install

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

Needs macOS on Apple Silicon with Metal and Python 3.13. 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 --model (default mlx-community/medgemma-1.5-4b-it-4bit, with --revision for a pinned commit), --image (paths or URLs), a required --prompt, --system, --max-tokens (2048), --temperature (0, greedy), --top-p, --top-k, --seed (0) and --prefill-step-size. --verbose streams the text with token timings. Prompts without images also work.

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; iterate it to the end so the prompt cache and cleanup run. The final result has finish_reason and token_ids, which include 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 and provides /v1/chat/completions, /v1/models, /health, /metrics and /v1/settings for runtime settings; schemas are at /docs while it runs. --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, adapters, or CPU, MPS or PyTorch fallback.
  • Prompts with images are prefilled whole, because a chunk could split an image's bidirectional attention block; text-only prompts use chunked prefill. The full prompt mask grows with the square of the prompt length.
  • The checks cover numerical agreement on small synthetic models and one public radiograph per checkpoint. Clinical accuracy has not been evaluated.

License

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

For research and education. Outputs require human review.

Metadata

Release files for med-vlm-mlx 0.3.4

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.3.4
File Size Uploaded Provenance Actions
med_vlm_mlx-0.3.4.tar.gz 165.7 kB Without provenance Details for med_vlm_mlx-0.3.4.tar.gz

Built distribution (wheel)

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

Total release size: 350.4 kB

Release files / med_vlm_mlx-0.3.4.tar.gz

Download URL med_vlm_mlx-0.3.4.tar.gz
Size 165.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ae9e4a39462719ad6ffed5feaf1c1fe43e31f7fe1209404f3784fb832a0fee5d
BLAKE2b-256 checksum
How to use checksums
45d148a66c6bb23ea35188aee4e4146d2220087faca63f424021ef73de0bd899
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.4-py3-none-any.whl

Download URL med_vlm_mlx-0.3.4-py3-none-any.whl
Size 184.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e14ffde880cf2c1917daf5f23536365483567463cdec48c1069d14100217b073
BLAKE2b-256 checksum
How to use checksums
5be25948ef2f662ede96fa058a1473360de0b83752fc101fe565472e39881c6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.4

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