Views
No views yet
hf auth login.mrdbourke username to your own username.1pip install mlx-vlm huggingface_hub
2
3# (Optional) Pre-create the repo as private
4hf repo create sunny-medgemma-1.5-4b-finetune-mlx-4bit --repo-type model --private
5
6# Convert and upload
7mlx_vlm.convert \
8 --model mrdbourke/sunny-medgemma-1.5-4b-finetune \
9 -q \
10 --upload-repo mrdbourke/sunny-medgemma-1.5-4b-finetune-mlx-4bitpip install mlx-vlmNote on prompt order: This model expects<image>+<text>→<text>format. The image must come before the text in the prompt. The example below handles this automatically.
wget -O test-skin-image-daniel-bourke.jpeg "https://github.com/mrdbourke/sunny/blob/main/images/test-skin-image-daniel-bourke.jpeg?raw=true"1# On your Mac — save as test_sunny_mlx.py and run with: python test_sunny_mlx.py
2import json
3import urllib.request
4from pathlib import Path
5from mlx_vlm import load, generate
6
7MODEL_ID = "mrdbourke/sunny-medgemma-1.5-4b-finetune-mlx-4bit"
8
9# Download a test image (or replace with your own local path)
10IMAGE_URL = "https://github.com/mrdbourke/sunny/blob/main/images/test-skin-image-daniel-bourke.jpeg?raw=true"
11IMAGE_PATH = "test-skin-image.jpeg"
12
13if not Path(IMAGE_PATH).exists():
14 print(f"[INFO] Downloading test image...")
15 urllib.request.urlretrieve(IMAGE_URL, IMAGE_PATH)
16
17print(f"[INFO] Loading model: {MODEL_ID}")
18model, processor = load(MODEL_ID)
19print(f"[INFO] Model loaded!")
20
21# Prompt format: <image> + <text> -> <text>
22prompt = "<bos><start_of_turn>user\n<start_of_image>sunscreen extract<end_of_turn>\n<start_of_turn>model\n"
23
24output = generate(
25 model,
26 processor,
27 prompt,
28 [IMAGE_PATH],
29 max_tokens=512,
30 temperature=0.7,
31 top_p=0.95,
32 repetition_penalty=1.2,
33 verbose=True,
34)
35
36print(output)1# Default test image
2python -m mlx_vlm.generate \
3 --model mrdbourke/sunny-medgemma-1.5-4b-finetune-mlx-4bit \
4 --image-path test-skin-image.jpeg \
5 --prompt "<bos><start_of_turn>user\n<start_of_image>sunscreen extract<end_of_turn>\n<start_of_turn>model\n" \
6 --max-tokens 512
7
8# Or pass your own image
9python -m mlx_vlm.generate \
10 --model mrdbourke/sunny-medgemma-1.5-4b-finetune-mlx-4bit \
11 --image-path /path/to/your/image.jpeg \
12 --prompt "<bos><start_of_turn>user\n<start_of_image>sunscreen extract<end_of_turn>\n<start_of_turn>model\n" \
13 --max-tokens 512