Instructions to use avinashmohan/gemma-4-E2B-it-4bit-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use avinashmohan/gemma-4-E2B-it-4bit-mlx with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("avinashmohan/gemma-4-E2B-it-4bit-mlx") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- LM Studio
- Pi new
How to use avinashmohan/gemma-4-E2B-it-4bit-mlx with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "avinashmohan/gemma-4-E2B-it-4bit-mlx"
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": "avinashmohan/gemma-4-E2B-it-4bit-mlx" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use avinashmohan/gemma-4-E2B-it-4bit-mlx 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 "avinashmohan/gemma-4-E2B-it-4bit-mlx"
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 avinashmohan/gemma-4-E2B-it-4bit-mlx
Run Hermes
hermes
- MLX LM
How to use avinashmohan/gemma-4-E2B-it-4bit-mlx with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "avinashmohan/gemma-4-E2B-it-4bit-mlx"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "avinashmohan/gemma-4-E2B-it-4bit-mlx" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "avinashmohan/gemma-4-E2B-it-4bit-mlx", "messages": [ {"role": "user", "content": "Hello"} ] }'
Gemma 4 E2B-it — MLX 4-bit Quantized
MLX-compatible 4-bit quantized version of google/gemma-4-E2B-it, converted for Apple Silicon inference via mlx-lm.
- Original model: google/gemma-4-E2B-it (9.6 GB bf16)
- Quantized size: 2.61 GB (4-bit, group_size=64)
- Bits per weight: 6.399
- Performance: ~35 tokens/sec on Apple Silicon
Usage
Note: Requires
gemma4.pymodel support in mlx-lm. See PR #1095, or manually placegemma4.pyin yourmlx_lm/models/directory.
from mlx_lm import load, generate
model, tokenizer = load("avinashmohan/gemma-4-E2B-it-4bit-mlx")
messages = [{"role": "user", "content": "What is the capital of France?"}]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
response = generate(model, tokenizer, prompt=prompt, max_tokens=100)
print(response)
# The capital of France is **Paris**.
Architecture highlights
Gemma 4 introduces several features over Gemma 3:
- Per-Layer Embeddings (PLE): each decoder layer receives its own token embedding, gated and projected into the residual stream
- KV cache sharing: the last 20 of 35 layers reuse KV caches from earlier layers, reducing memory
- ProportionalRoPE: global attention uses partial rotation (25% of dims), the rest pass through
- Heterogeneous head dims: sliding attention (head_dim=256) vs global attention (global_head_dim=512)
- v_norm: RMS normalization on value states (without learned scale)
- RMSNorm without +1 offset: unlike Gemma 3's
(1 + weight), Gemma 4 uses plainweight - Attention scale = 1.0: QK-norm replaces traditional
1/sqrt(d)scaling
Conversion
Converted using a custom script that reads raw bf16 bytes via memory-mapped I/O, splits the oversized PLE embedding tensor (4.7 GB, exceeds Metal's 4 GB buffer limit) into per-layer chunks, and quantizes via mlx.nn.quantize.
- Downloads last month
- 51
Quantized