Instructions to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf 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 xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0 # Run inference directly in the terminal: llama cli -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0 # Run inference directly in the terminal: llama cli -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Use Docker
docker model run hf.co/xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
- Llama new
- LM Studio
- Jan
- vLLM
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
- Ollama
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with Ollama:
ollama run hf.co/xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
- Unsloth Desktop
- Pi
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with Docker Model Runner:
docker model run hf.co/xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
- Lemonade
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Run and chat with the model
lemonade run user.gemma-4-E4B-it-qat-q4_0-exact-gguf-Q4_0
List all available models
lemonade list
- Hermes Agent
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
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 xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0
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 "xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf:Q4_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Gemma 4 E4B-it QAT, exact Q4_0 GGUF, text only (unofficial)
This is an unofficial build, made and published independently of Google. It is a
llama.cpp GGUF of Gemma 4 E4B-it in which every 4-bit weight is the value Google's
quantization-aware training (QAT) produced. Every weight matrix is stored at 4 bits,
including both embedding tables. It is 4.22 GB, against 5.15 GB for Google's
gemma-4-E4B-it-qat-q4_0-gguf,
and follows the unquantized model much more closely. Google's model card is kept
unchanged in ORIGINAL_README.md.
The E2B counterpart, built by the same script, is
xbill9/gemma-4-E2B-it-qat-q4_0-exact-gguf.
| Google Q4_0 GGUF | This GGUF | |
|---|---|---|
| File size | 5,154,941,280 B | 4,215,695,712 B |
| Embedding tables | Q6_K | Q4_0 |
per_layer_model_proj |
F16 | Q4_0 |
| Mean KL divergence from bf16, CPU | 0.035254 ± 0.000773 | 0.001031 ± 0.000053 |
| 99th percentile KL divergence, CPU | 0.215774 | 0.008396 |
| Same top token as bf16, CPU | 90.64 ± 0.46 % | 98.41 ± 0.20 % |
| Perplexity relative to bf16, CPU | 1.0816 ± 0.0089 | 1.0256 ± 0.0052 |
| Generation, 128 tokens, GTX 1650 Ti | 37.56 tok/s | 39.84 tok/s (1.061x) |
| Prompt processing, 512 tokens, GTX 1650 Ti | 170.1 tok/s | 172.8 tok/s (1.016x) |
| Weights in VRAM, GTX 1650 Ti | 2696.06 MiB | 2493.32 MiB |
| Whole process in VRAM, 8192 context | 3052 MiB | 2848 MiB |
Measured with llama.cpp build f95b0d9 (318) on an i7-10750H laptop with a GTX 1650 Ti Max-Q
(4 GB, no tensor cores). Divergence and perplexity: llama-perplexity on wikitext-2 test, 16
chunks of 512 tokens, on the CPU, against a bf16 GGUF of the same QAT weights with identical
metadata. Speed: llama-bench, 5 repetitions, four passes alternating which file runs first,
each pass starting at or below 50 °C; the table gives the mean of the four passes, and the
generation ratio was 1.058–1.063 in every pass. Logs are in evidence/.
It fits a 4 GB card. With -ngl 99 -c 8192 the whole process holds 2848 MiB, because
per_layer_token_embd (1.59 GB, 38% of the file) is read a few rows per token from the
memory-mapped file and never goes to VRAM. The KV cache at 8192 context is 168 MiB.
What is in it
- Language model only. Vision and audio live in Google's separate
gemma-4-E4B-it-mmproj.gguf, which is not included here. - Metadata copied byte for byte from Google's GGUF at revision
4b4a2c1: tokenizer, chat template, hyperparameters and tensor order. - Weights rebuilt from
google/gemma-4-E4B-it-qat-q4_0-unquantizedat revision476025a: all 342 layer matrices (attention, MLP, per-layer gate and projection), both embedding tables (token_embd,per_layer_token_embd) andper_layer_model_proj, as Q4_0. - Copied unchanged: the norms and scale vectors (F32, 2.2 MB in all).
Why it is smaller and closer
QAT trained these weights on a 4-bit grid: in every block of 32 values, each value is a
block scale times an integer from -8 to 7. That holds for the two embedding tables and
per_layer_model_proj as well as the layers. The embedding tables make up 3.49 billion of
the model's values, and Google's GGUF stores them as Q6_K. Stored as Q4_0 they keep the
trained values and take less space, which is where most of the 0.94 GB goes.
For the layer matrices, Google's GGUF uses llama.cpp's standard Q4_0 step, the block's largest magnitude divided by 8. QAT often puts a block's largest value on a lower level, and in those blocks the standard step moves values off the trained grid. This build recovers each block's trained step instead (largest magnitude divided by 8, 7, … 1, whichever puts every value on an integer level, then refined by least squares) and stores it as the fp16 block scale.
Every one of the rebuilt blocks landed on a 4-bit grid, and 96.81% of rebuilt values are
bit-identical to the source after bf16 rounding. The rest differ by the fp16 rounding of the
scale. Per-tensor counts are in evidence/build_report.json.
The generation speed-up is about half the E2B build's (1.11–1.12x on the same card). That fits
where the bytes are: token_embd doubles as the output projection and is read in full for
every token, and it is a smaller share of what E4B reads per token than of what E2B does.
Memory traffic was not measured directly.
Running it
llama.cpp (tested on CUDA; divergence measured on CPU):
llama-server -m gemma-4-E4B-it-q4_0-exact.gguf -ngl 99 -fa 1 -c 8192 --jinja # GPU
llama-server -m gemma-4-E4B-it-q4_0-exact.gguf -t 6 -c 8192 --jinja # CPU
Do not pass --no-mmap: llama.cpp reads per_layer_token_embd lazily from the map, and
without it the file would not fit a 4 GB card.
llama-server turns thinking on by default, so a reply lands in reasoning_content
and a short max_tokens can leave content empty. To get direct answers, start the server
with --reasoning off, or send "chat_template_kwargs": {"enable_thinking": false} with a
request.
Rebuilding it
hf download google/gemma-4-E4B-it-qat-q4_0-unquantized --revision 476025a --local-dir src
hf download google/gemma-4-E4B-it-qat-q4_0-gguf gemma-4-E4B_q4_0-it.gguf --revision 4b4a2c1 --local-dir gguf
python3 gguf_exact.py src gguf/gemma-4-E4B_q4_0-it.gguf gemma-4-E4B-it-q4_0-exact.gguf
Needs only numpy, and takes about 7.5 minutes and 6.2 GiB of RAM on a laptop. The output is
deterministic: SHA-256 5462cc102b7d22c4748f9b8e82091f2ae064e10a45525151af6f9a7d0da7caf9.
--bf16 writes the reference instead: the same file with the source bf16 weights. The script
stops if any block fails to land on a 4-bit grid. It is the E2B build's script, unchanged
apart from its docstring.
Limitations
- Text only.
- Tested with llama.cpp on one laptop: divergence on its CPU (AVX2), speed and five greedy chat prompts on its GPU (GTX 1650 Ti, CUDA). Other backends and runtimes were not tested, and divergence was not measured on CUDA.
- Built and checked on one machine only; the E2B build was reproduced on two.
- The divergence figures cover 8,192 tokens of English Wikipedia text.
- Unofficial. Report problems here, not to Google.
License and attribution
Gemma 4 is released by Google DeepMind under the Apache 2.0 license. This repository redistributes Google's weights in a changed storage format, under the same license. The weights, training, tokenizer, chat template and the original model card are Google DeepMind's; this build and card are not affiliated with or endorsed by Google.
- Downloads last month
- 909
4-bit
Model tree for xbill9/gemma-4-E4B-it-qat-q4_0-exact-gguf
Base model
google/gemma-4-E4B