使用 MLX 執行 Gemma

MLX 是陣列框架,適用於 Apple 晶片的機器學習。

快速入門

從 Python Package Index (PyPI) 安裝

pip install mlx mlx-lm mlx-vlm

範例指令:

# Text Generation
mlx_lm.generate --model mlx-community/gemma-4-e2b-it-4bit --prompt "Who are you?"

# Vision Task
mlx_vlm.generate --model mlx-community/gemma-4-e2b-it-4bit --prompt "Describe this image." --image <path_to_image>

你可以使用下列指令啟動伺服器:

mlx_vlm.server --port 8080

# Preload a model at startup (Hugging Face repo or local path)
mlx_vlm.server --model mlx-community/gemma-4-e2b-it-4bit

這會建立伺服器,讓您透過與 OpenAI 相容的端點 (http://localhost:8080/v1) 存取模型。

如要進一步瞭解如何搭配 Gemma 使用 MLX,請參閱官方存放區: