Image-Text-to-Text
MLX
English
gemma4_unified
gemma
gemma-4
multimodal
vision
audio
mixed-quantization
8bit
inference
conversational
Instructions to use andrzejmontano/gemma-4-12B-it-Mixed-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use andrzejmontano/gemma-4-12B-it-Mixed-8bit 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("andrzejmontano/gemma-4-12B-it-Mixed-8bit") config = load_config("andrzejmontano/gemma-4-12B-it-Mixed-8bit") # 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 andrzejmontano/gemma-4-12B-it-Mixed-8bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "andrzejmontano/gemma-4-12B-it-Mixed-8bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "andrzejmontano/gemma-4-12B-it-Mixed-8bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent
How to use andrzejmontano/gemma-4-12B-it-Mixed-8bit 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 "andrzejmontano/gemma-4-12B-it-Mixed-8bit"
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 andrzejmontano/gemma-4-12B-it-Mixed-8bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use andrzejmontano/gemma-4-12B-it-Mixed-8bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "andrzejmontano/gemma-4-12B-it-Mixed-8bit"
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 "andrzejmontano/gemma-4-12B-it-Mixed-8bit" \ --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"
File size: 5,376 Bytes
79e8ffd 0920de3 79e8ffd 5c17fd3 79e8ffd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | ---
license: apache-2.0
tags:
- gemma
- gemma-4
- multimodal
- vision
- audio
- mixed-quantization
- 8bit
- mlx
- inference
pipeline_tag: image-text-to-text
library_name: mlx
language:
- en
base_model:
- google/gemma-4-12b-it
---
# gemma-4-12B-it-Mixed-8bit
**Mixed-precision 8-bit quantization of [Gemma 4 12B IT](https://huggingface.co/google/gemma-4-12b-it)** — Google's unified multimodal model (text + vision + audio + video), optimized for efficient local inference with minimal quality loss.
## Quick Stats
| Metric | Value |
|--------|-------|
| Base model | [google/gemma-4-12b-it](https://huggingface.co/google/gemma-4-12b-it) |
| Architecture | Gemma4Unified (48-layer dense, hybrid attention) |
| Quantization | MLP-only 8-bit, group-size=64 |
| BF16 size | ~24 GB |
| **Mixed 8-bit size** | **~15 GB (≈38% reduction)** |
| Modalities | Text, Vision, Audio, Video |
| License | Gemma License (inherits from base model) |
## Quantization Strategy
This model uses **surgical mixed-precision quantization**: only the SwiGLU MLP projection matrices (`gate_proj`, `up_proj`, `down_proj`) in the language model are quantized to 8-bit. All other components remain in BF16:
- ✅ **Quantized (8-bit)**: LLM MLP layers (144 tensors across 48 layers, ~60% of model mass)
- ✅ **Protected (BF16)**: All attention (sliding + full), vision tower, audio embedder, embeddings, LM head, MultimodalEmbedder, all normalization layers, layer_scalars
**Rationale**: MLP layers are "knowledge lookup" / feature transformation layers that are extremely quantization-tolerant. Attention mechanisms carry reasoning and context-window recall. Vision, audio, and multimodal projection layers are kept in BF16 to preserve modality fidelity.
## Model Architecture
### Language Model (Text)
- **48 dense layers** in pattern `[sliding_attention × 5, full_attention × 1] × 8`
- **Hybrid attention**: Sliding window attention (40 layers, head_dim=256) + full global attention (8 layers, head_dim=512)
- **Heads**: 16 query / 8 KV / 1 global KV
- **Hidden size**: 3840, **Intermediate**: 15360
- **Vocab**: 262,144, **Context**: 262,144 tokens
- **RoPE**: Default (θ=10,000) for sliding; Proportional (θ=1,000,000, partial_rotary=0.25) for full attention
- **No MoE** (dense architecture)
### Vision Tower
- **ViT** with patch_size=16, pooling_kernel=3
- **280 soft tokens** per image, projected to 3840-dim
- Position embedding size: 1120
### Audio Tower
- **Audio embedder**: 640-dim embedding, 640 samples per token
- Simple linear projection (no convolutional audio tower in this checkpoint)
### Multimodal
- **Unified processor**: `Gemma4UnifiedProcessor` handling text, images, audio, and video
- **Special tokens**: `<|image|>`, `<|audio|>`, `<|video|>` with BOI/EOI, BOA/EOA delimiters
- **MultimodalEmbedder** projects vision and audio into the shared 3840-dim text space
## MTP Speculative Decoding
This model supports **Multi-Token Prediction (MTP)** speculative decoding via the companion assistant/drafter model. This model achieves 20-30% faster token generation with gemma-4-12B-it-assistant in BF16 format.
## Usage
### oMLX (Recommended)
Loads natively with MTP and vision support.
### MLX / mlx-vlm
```python
from mlx_vlm.utils import load
model, processor = load("your-username/gemma-4-12B-it-Mixed-8bit", lazy=True)
# Model loads in ~15 GB vs ~24 GB for BF16
```
## Files
| File | Description |
|------|-------------|
| `model-00001.safetensors` – `model-00003.safetensors` | Sharded model weights (~5 GB each) |
| `config.json` | Model configuration with quantization metadata |
| `tokenizer.json` / `tokenizer_config.json` | Tokenizer (262K vocab) |
| `chat_template.jinja` | Chat template with thinking/tool support |
| `generation_config.json` | Generation parameters |
| `processor_config.json` | Unified processor config |
## Quantization Details
| Parameter | Value |
|-----------|-------|
| Quantization mode | Affine (8-bit) |
| Group size | 64 |
| Layers quantized | 48 (all MLP: gate_proj, up_proj, down_proj) |
| Tensors quantized | ~144 |
| Layers protected | Attention (Q/K/V/O), Vision, Audio, Embeddings, Norms, Scalars |
| Script | `quantization_scripts/mixed_quantize_gemma4_12b.py` |
## Reproducing
```bash
# Quantize from the BF16 base model
mlx-env/bin/python quantization_scripts/mixed_quantize_gemma4_12b.py \
--bits 8 --group-size 64
```
The script:
1. Lazily loads the BF16 checkpoint via `mlx_vlm.utils.load()`
2. Applies 8-bit quantization to MLP projections only (via `class_predicate` filter)
3. Saves config with quantization metadata
4. Flattens, evaluates, and shards to 5 GB safetensors
## Limitations
- Mixed quantization may show minor quality degradation on edge cases compared to BF16
- The vision tower, audio embedder, and multimodal projector are kept in BF16 — they are not quantized in this version
- Audio support uses a simple linear projection (no convolutional audio tower); complex audio understanding may be limited
- MTP speculative decoding requires the companion assistant model to be loaded alongside
- The base model uses `transformers_version: 5.10.0.dev0` — some fields may not be recognized by stable transformers releases yet
## License
This model inherits the Apache 2.0 license of the base [google/gemma-4-12b-it](https://huggingface.co/google/gemma-4-12b-it).
|