1python3.12 -m mlx_vlm.generate \2 --model cloudyu/gemma4-31B-Fable-5-Distilled-MLX-mxfp4 \3 --prompt "Write a Python function to reverse a linked list."\4 --max-tokens 512
Image understanding
bash
1python3.12 -m mlx_vlm.generate \2 --model cloudyu/gemma4-31B-Fable-5-Distilled-MLX-mxfp4 \3 --image photo.jpg \4 --prompt "Describe this image in detail."\5 --max-tokens 256
1from mlx_vlm import load, generate
2from mlx_vlm.utils import load_image
34model, processor = load("cloudyu/gemma4-31B-Fable-5-Distilled-MLX-mxfp4")56# Text7messages =[{"role":"user","content":"Write a Python function to reverse a linked list."}]8prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)9output = generate(model, processor, prompt, max_tokens=512)10print(output)1112# Image13image = load_image("photo.jpg")14messages =[{"role":"user","content":[15{"type":"image"},16{"type":"text","text":"Describe this image."}17]}]18prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)19output = generate(model, processor, prompt, image=image, max_tokens=256)20print(output)
Important: Video Processing Bug Fix
Upstream mlx-vlm has a bug in Gemma 4 video processing that causes hallucinated output (e.g., "a gray horizontal line on a dark background" instead of actual video content). The fix is submitted at:
PR #1431 — fix: Gemma4 video processing - float32 overflow and wrong token scatter
Two bugs fixed by this PR:
Float32 overflow in _resize_frames: fetch_video() returns float32 frames in [0,255] range, but _resize_frames treats them as [0,1] and multiplies by 255 again, causing overflow/clipping. Also, the output dtype was float32 instead of uint8, preventing the rescale step from triggering.
Wrong token scatter: Video pixel values were passed as pixel_values (scattered at image_token_id positions) instead of pixel_values_videos (scattered at video_token_id positions), so vision features were never injected into video prompt slots.
Until this PR is merged, apply the changes manually:
mlx_vlm/models/gemma4/processing_gemma4.py: Fix _resize_frames output dtype and value range
mlx_vlm/video_generate.py: Change kwargs["pixel_values"] to kwargs["pixel_values_videos"]