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

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.2"

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 --model-dir adds folders to search for models. Images go 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.2

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.2
File Size Uploaded Provenance Actions
med_vlm_mlx-0.3.2.tar.gz 166.2 kB Without provenance Details for med_vlm_mlx-0.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 351.9 kB

Release files / med_vlm_mlx-0.3.2.tar.gz

Download URL med_vlm_mlx-0.3.2.tar.gz
Size 166.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2ef57ebbbd926242a826c5355f00d42a8242875116c4207ca8c3b378815d7f95
BLAKE2b-256 checksum
How to use checksums
f43f08fb0a8abc649a50b2d36d4bc11770b42bd2f0cb6b2b801c15bc48be0f8c
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.2-py3-none-any.whl

Download URL med_vlm_mlx-0.3.2-py3-none-any.whl
Size 185.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d2727ddf7693cb34e83075b604577b0d08f35308d4e77bec8b64642051552b1
BLAKE2b-256 checksum
How to use checksums
07160535d5a5bc50bb7ef444125a6cc101f67e2fd6ce1163015eaa3a2a0d1c1d
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.2

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.

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files No provenance

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