Instructions to use jdfelo/gemma-4-31B-v2-MLX-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use jdfelo/gemma-4-31B-v2-MLX-4bit with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("jdfelo/gemma-4-31B-v2-MLX-4bit") config = load_config("jdfelo/gemma-4-31B-v2-MLX-4bit") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use jdfelo/gemma-4-31B-v2-MLX-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "jdfelo/gemma-4-31B-v2-MLX-4bit"
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "jdfelo/gemma-4-31B-v2-MLX-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use jdfelo/gemma-4-31B-v2-MLX-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "jdfelo/gemma-4-31B-v2-MLX-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default jdfelo/gemma-4-31B-v2-MLX-4bit
Run Hermes
hermes
- OpenClaw new
How to use jdfelo/gemma-4-31B-v2-MLX-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "jdfelo/gemma-4-31B-v2-MLX-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "jdfelo/gemma-4-31B-v2-MLX-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
gemma-4-31B-v2-MLX-4bit
A 4-bit MLX build of an abliterated Gemma 4 31B for Apple Silicon. One repo, three ways to run it:
- Plain chat in LM Studio or mlx-lm, about 15 tok/s. Vision weights are stripped automatically.
- Fast text with MTP speculative decoding: up to 37.1 tok/s.
- Image understanding through mlx-vlm.
Everything except the vision tower is 4-bit (group size 64). Perplexity 59.80 vs 59.96 bf16. About 18 GB on disk, fits a 48 GB Mac.
Quick start (gets you the 31.8 tok/s config)
huggingface-cli download jdfelo/gemma-4-31B-v2-MLX-4bit run_mac.sh chat.html patch_mlx_vlm_fast_verify.py --local-dir .
bash run_mac.sh
The script installs mlx-vlm, applies the fast-verify patch, installs the fast mlx wheel from this repo if your machine can use it (Python 3.11 + macOS 26), downloads the model and drafter, starts an OpenAI-compatible server on :8080, and opens a browser chat. It picks the right block size for whichever mlx you end up on.
DRAFT=0 bash run_mac.sh # dense only, no drafter
BLOCK=3 bash run_mac.sh # force a block size (auto by default)
Apple Silicon only.
Speed (MacBook Pro M5 Pro, 48 GB)
| Config | tok/s | speedup |
|---|---|---|
| dense 4-bit | 15.0 | 1.0x |
| MTP, stock pip mlx 0.31.2 | 20.4 | 1.4x |
| MTP + fast-verify patch | 24.6 | 1.6x |
| MTP + patch + fast mlx wheel | 31.8 | 2.1x |
Output is byte-identical to dense greedy at temperature 0 in every config (verified). Dense is bandwidth-bound (17.3 GB of weights per token, ~276 GB/s measured, ≈16 tok/s ceiling); everything past it comes from speculative decoding.
The two pieces behind the jump from 20 to 32, both in this repo:
patch_mlx_vlm_fast_verify.py. mlx-vlm's Gemma 4 is missing a hook its own MTP loop looks for, so every verify round did K+1 sequential lm_head projections with a blocking sync each. The patch adds the 9-line hook: one batched projection, one sync, same logits. Idempotent,--revertundoes it.wheels/mlx-0.32.0.dev*.whl. A prebuilt mlx with theqmv_widekernel (PR #3764, merged upstream but not yet on PyPI). Stock 0.31.2 re-reads the whole weight matrix once per verify row; qmv_wide reads it once per round. Verify at block 4 drops from 142 ms to 95 ms. Built for Python 3.11 on macOS 26 (Apple Silicon). On other setups, either build mlx from source (pip wheel git+https://github.com/ml-explore/mlx --no-deps, afterxcodebuild -downloadComponent MetalToolchain) or skip it and stay at 24.6.
Doing it by hand
pip install -U "git+https://github.com/Blaizzy/mlx-vlm.git"
python patch_mlx_vlm_fast_verify.py
pip install --force-reinstall --no-deps "$(huggingface-cli download jdfelo/gemma-4-31B-v2-MLX-4bit wheels/mlx-0.32.0.dev20260702+e9463bb-cp311-cp311-macosx_26_0_universal2.whl)"
python -m mlx_vlm server --host 127.0.0.1 --port 8080 \
--model jdfelo/gemma-4-31B-v2-MLX-4bit \
--draft-model mlx-community/gemma-4-31B-it-assistant-bf16 \
--draft-kind mtp --draft-block-size 4
Use --draft-block-size 3 if you stayed on stock mlx 0.31.2. One-off generation works the
same way with python -m mlx_vlm generate ... --prompt "..." --temperature 0.
Dense in LM Studio: drop this repo into ~/.lmstudio/models/jdfelo/, load it, chat. LM Studio
can't run the MTP drafter, so use mlx-vlm for the fast path.
Dense with mlx-lm:
pip install -U mlx-lm
mlx_lm.generate --model jdfelo/gemma-4-31B-v2-MLX-4bit --prompt "Hi" --max-tokens 128
Tip: sudo sysctl iogpu.wired_limit_mb=36864 keeps the weights wired on a 48 GB Mac.
Ollama can't run this (it wants GGUF, these are MLX weights).
Responsible use
This is an abliterated, uncensored model with the usual safety refusals removed. You are responsible for how you use it. The underlying Gemma components remain covered by Google's Gemma Terms.
- Downloads last month
- 263
4-bit
Model tree for jdfelo/gemma-4-31B-v2-MLX-4bit
Base model
jdfelo/gemma-4-31B-v2