Instructions to use ArnavKewalram/gemma-4-E2B-coder-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ArnavKewalram/gemma-4-E2B-coder-v1") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("ArnavKewalram/gemma-4-E2B-coder-v1") model = AutoModelForMultimodalLM.from_pretrained("ArnavKewalram/gemma-4-E2B-coder-v1") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - llama-cpp-python
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="ArnavKewalram/gemma-4-E2B-coder-v1", filename="gemma-4-E2B-coder-v1-F16.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M # Run inference directly in the terminal: llama cli -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M # Run inference directly in the terminal: llama cli -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Use Docker
docker model run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ArnavKewalram/gemma-4-E2B-coder-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ArnavKewalram/gemma-4-E2B-coder-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
- SGLang
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ArnavKewalram/gemma-4-E2B-coder-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ArnavKewalram/gemma-4-E2B-coder-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ArnavKewalram/gemma-4-E2B-coder-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ArnavKewalram/gemma-4-E2B-coder-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Ollama:
ollama run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
- Unsloth Studio
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ArnavKewalram/gemma-4-E2B-coder-v1 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ArnavKewalram/gemma-4-E2B-coder-v1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ArnavKewalram/gemma-4-E2B-coder-v1 to start chatting
- Pi
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
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 ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Run Hermes
hermes
- Atomic Chat new
- Docker Model Runner
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Docker Model Runner:
docker model run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
- Lemonade
How to use ArnavKewalram/gemma-4-E2B-coder-v1 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Run and chat with the model
lemonade run user.gemma-4-E2B-coder-v1-Q4_K_M
List all available models
lemonade list
Releasing gemma-4-E2B-coder-v1 — the first coding fine-tune of Gemma 4 E2B
Releasing gemma-4-E2B-coder-v1 — the first coding fine-tune of Gemma 4 E2B
I just finished training gemma-4-E2B-coder-v1, the first coding fine-tune of google/gemma-4-E2B-it, and I wanted to share some hard-won lessons about fine-tuning this unusual architecture.
What it is
A QLoRA fine-tune of Gemma 4 E2B (3.9B params) on 10,000 samples from Magicoder-OSS-Instruct-75K — real instruction pairs extracted from open-source GitHub repositories.
The Q4_K_M GGUF is ~3.2 GB — larger than a typical sub-3B model because Gemma 4 has a 262K-token vocabulary (the embedding tables alone are ~2 GB).
Try it now:
- 🤗 Live demo Space (no GPU or API key needed)
- 📓 Notebook (view on HF Hub — download to run in Colab/Jupyter)
- 🖥️ Ollama:
ollama run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M
Technical lessons — the hard way
1. Griffin architecture breaks PEFT suffix-matching
Gemma 4 E-series isn't a standard transformer — it alternates between local-attention layers and Griffin linear-recurrent (SSM) layers. The SSM layers wrap their projections in Gemma4ClippableLinear, which PEFT can't inject LoRA into.
What doesn't work: standard suffix-based target_modules:
target_modules=["q_proj", "k_proj", "v_proj", "o_proj", ...] # crashes
# ValueError: Target module Gemma4ClippableLinear(...) is not supported
Even though you exclude input_proj/output_proj, the SSM layers also have q_proj/k_proj sub-modules wrapped in Gemma4ClippableLinear.
What works: filter by isinstance(mod, Linear4bit) at load time, then pass full paths as a list:
from bitsandbytes.nn import Linear4bit
_SUFFIX_TARGETS = {"q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"}
lora_target_modules = [
name for name, mod in model.named_modules()
if isinstance(mod, Linear4bit) and name.split(".")[-1] in _SUFFIX_TARGETS
]
# → 205 verified Linear4bit layers, 0 Gemma4ClippableLinear
lora_config = LoraConfig(..., target_modules=lora_target_modules)
Why a list, not a regex? Passing a list lets PEFT do an O(1) set lookup per module. Passing a 254-path alternation regex string means re.fullmatch(14k_char_regex, key) for every module in a 3.9B model — that took 14+ minutes at 97% CPU.
2. Dataset ordering matters more than you think
The first 10K samples of Magicoder-OSS-Instruct-75K are sorted by sequence length. Without shuffling, step times escalated from ~50s to 426s/step by step 80 (estimated total: 128 hours on an RTX 3080).
After shuffling before selection:
ds = load_dataset("ise-uiuc/Magicoder-OSS-Instruct-75K", split="train")
ds = ds.shuffle(seed=77).select(range(10000)) # shuffle FIRST, then select
Step times stabilized at ~8s and training completed in ~6 hours.
3. VRAM cliffs with gradient checkpointing
With max_seq_len=512 and gradient checkpointing, training hung at 99% VRAM after step 24 with GPU pinned at 100% indefinitely. Reducing to max_seq_len=384 gave ~223 MB headroom and stabilized training.
Training stats
| Parameter | Value |
|---|---|
| Base model | google/gemma-4-E2B-it (3.9B) |
| Dataset | Magicoder-OSS-Instruct-75K, 10K samples, 1 epoch |
| LoRA rank / alpha | 16 / 32 |
| Trainable parameters | 24.2M (0.47%) |
| Max sequence length | 384 tokens |
| Hardware | NVIDIA RTX 3080 10 GB |
| Training time | ~6 hours |
GGUF variants
| File | Size | Use case |
|---|---|---|
| Q4_K_M | ~3.2 GB | Best compression; 4 GB RAM |
| Q5_K_M | ~3.4 GB | Better accuracy |
| Q8_0 | ~4.6 GB | Near-lossless, desktop |
Larger than typical sub-3B quants because Gemma 4's 262K vocabulary means embedding tables are ~2 GB even at Q4.
Full details and training curve: ArnavKewalram/gemma-4-E2B-coder-v1
Would love feedback — especially if you run it on edge hardware or compare against other sub-3B coders!
Update: quantitative eval results added (88.5% avg)
Just ran an 8-prompt keyword eval on the Q4_K_M GGUF (CPU, llama.cpp b9684, temp 0.2):
| Prompt | Score |
|---|---|
| Miller-Rabin primality test | 33% (correct implementation, different var names) |
| Binary search | 75% |
| Thread-safe LRU cache | 100% |
| Recursive list flatten | 100% |
| JavaScript debounce | 100% |
| FizzBuzz | 100% |
| Graph BFS | 100% |
| Retry decorator | 100% |
Average: 88.5% -- details in the updated model card.
Also fixed today:
- tokenizer_config.json: extra_special_tokens format (fixes load error in transformers 4.57+)
- Modelfile: corrected chat template to Gemma 4 E-series format (<|turn> / <turn|>)
- inference.py + notebook: added rust_remote_code=True
Would love to hear results if you test on edge hardware or compare against other sub-4B coders!
Supports Python, JS, TS, Go, Rust, SQL, Bash, C++ with streaming output. Model is pre-cached at build time so first generation takes ~30-60s (previously 2-4 min). Run locally with just 4 GB RAM: ollama run hf.co/ArnavKewalram/gemma-4-E2B-coder-v1:Q4_K_M