Gemma 4 E4B Turboquant
> [!TIP] > KV-cache quantization without any fork (recommended, 2026): upstream > llama.cpp/Ollama now cover this natively — use -ctk q80 -ctv q80 > (half KV memory, negligible quality loss: perplexity +0.002–0.05)...
Model source
- Kind
- Text model
- File size
- 14.9 GB
- Base model
- google/gemma-4-E4B
- Version
- vmodel
- Updated
- Sep 18, 2026
- Downloads
- 32
- Tasks
- Captioning
- Source
- Hugging Face
Source description
[!TIP] KV-cache quantization without any fork (recommended, 2026): upstream llama.cpp/Ollama now cover this natively — use
-ctk q8_0 -ctv q8_0(~half KV memory, negligible quality loss: perplexity +0.002–0.05) or-ctk q4_0 -ctv q4_0(~quarter memory, ≈7.6% perplexity increase). In Ollama:OLLAMA_KV_CACHE_TYPE=q8_0withOLLAMA_FLASH_ATTENTION=1. Keep K and V types symmetric to stay on the fast fused Flash-Attention path. Since April 2026, mainline llama.cpp also applies Hadamard rotation to KV activations (PR #21038), which greatly improves low-bit KV quality (opt-out:LLAMA_ATTN_ROT_DISABLE=1).The RotorQuant/TurboQuant fork flow below is experimental/legacy: the TurboQuant llama.cpp PR was closed without merging (June 2026) and the fork is unmaintained relative to mainline. It is NOT required to use this model.
gemma-4-E4B-TurboQuant
TurboQuant KV cache compression for google/gemma-4-E4B.
This is a documentation repository that explains how to combine gemma-4-E4B's weights with TurboQuant inference-time KV cache compression. No weights are stored here — use the base model directly and apply TurboQuant via the Python package or llama.cpp fork.
Hardware compatibility
| Device | VRAM / RAM | Recommendation |
|---|---|---|
| Any host that runs the base model | baseline + runtime savings | RotorQuant/TurboQuant is a KV-cache runtime modifier; pair with any weight variant |
What is this?
KV cache compression reduces the memory used by the attention cache during inference. Unlike weight quantization (which is baked into the GGUF/MLX file), KV cache compression is applied at runtime — so the same base weights can be used with or without compression.
| Technique | Where it's applied | Savings |
|---|---|---|
| TurboQuant KV cache | At inference time | Reduces attention memory (critical for long context) |
Both can be combined for maximum efficiency.
Quickstart
Option A — Python / transformers
Install the turboquant package:
pip install turboquant
Then use it with the base model:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from turboquant import TurboQuantCache
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E4B", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"google/gemma-4-E4B",
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
# Apply TurboQuant to the KV cache
cache = TurboQuantCache(bits=4) # or bits=2 for more aggressive compression
inputs = tokenizer("Hello, how are you?", return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=128,
past_key_values=cache,
use_cache=True,
)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
Option B — llama.cpp / LM Studio / Ollama (with fork)
TurboQuant KV cache types (planar3) are not in upstream llama.cpp. They require:
Once built:
llama-cli -m gemma-4-E4B.gguf \
--cache-type-k planar3 --cache-type-v planar3 \
-ngl 99 -fa \
-p "Hello"
For standard runtimes (LM Studio, Ollama, upstream llama.cpp), use conventional KV cache types (q8_0, q4_0). You lose the TurboQuant-specific benefits but keep GGUF weight quantization.
Model Specifications
| Property | Value |
|---|---|
| Base Model | google/gemma-4-E4B |
| Architecture | Dense transformer (Edge optimised) |
| Parameters | ~4B |
| Context Length | 128K |
| BF16 Size | ~8 GB |
| Modalities | Text + Image + Audio |
| License | apache-2.0 |
What is TurboQuant?
TurboQuant (ICLR 2026) applies random orthogonal rotations followed by optimal scalar quantization to the KV cache. Bit-identical prefill logits at 4-bit, up to 4-8× memory savings for long sequences.
Benchmarks (from the TurboQuant repository, Llama 3.1 8B on RTX 5090 — results vary by model and hardware):
- 4-bit KV cache: bit-identical prefill logits
- ~1.4-1.7× speedup on Apple Silicon
- Up to 8× KV memory savings
Benchmarks are from the TurboQuant repository using Llama 3.1 8B. Performance on gemma-4-E4B will differ. Please open a discussion if you have independent results.
Current Ecosystem Support
| Runtime | TurboQuant Support | Notes |
|---|---|---|
Python transformers + turboquant | ✅ Full | Drop-in cache class |
| llama.cpp upstream | ❌ Not merged | Use fork below |
| llama-cpp-turboquant fork | ✅ planar3, iso3 | GitHub |
| LM Studio | ❌ Requested | Use q8_0 as alternative |
| Ollama | ❌ Not supported | Use OLLAMA_KV_CACHE_TYPE=q8_0 |
| vLLM | ❌ Not supported | — |
| koboldcpp | ❌ Not supported | — |
Pre-quantized weight variants
If you want combined weight + KV cache compression, majentik hosts pre-quantized versions:
See Also
- RotorQuant GitHub
- TurboQuant paper (arXiv 2504.19874)
- llama-cpp-turboquant fork
- Base model: google/gemma-4-E4B
- gemma-4-E4B announcement
Variants in this family
(Showing 13 sibling variants under majentik/gemma-4-e4b-*. The current variant — TurboQuant — is bolded.)
| Variant | Runtime | Approx size | Use case |
|---|---|---|---|
| RotorQuant | runtime modifier | n/a | KV-cache root (weight-agnostic) |
| RotorQuant-GGUF-IQ4_XS | llama.cpp | ~3.4 GB | Lossy 4-bit, low-RAM CPU/edge |
| RotorQuant-GGUF-Q2_K | llama.cpp | ~2.4 GB | Lossy, low-RAM CPU/edge |
| RotorQuant-GGUF-Q3_K_M | llama.cpp | ~3.1 GB | Smaller 3-bit, CPU-friendly |
| RotorQuant-GGUF-Q4_K_M | llama.cpp | ~4.4 GB | Balanced default |
| RotorQuant-GGUF-Q5_K_M | llama.cpp | ~5.3 GB | Higher fidelity, more RAM |
| RotorQuant-GGUF-Q8_0 | llama.cpp | ~8.4 GB | Near-lossless reference |
| RotorQuant-MLX-2bit | mlx-lm | ~1.3 GB | Apple Silicon, smallest |
| RotorQuant-MLX-4bit | mlx-lm | ~2.5 GB | Apple Silicon balanced |
| RotorQuant-MLX-8bit | mlx-lm | ~4.7 GB | Apple Silicon reference |
| TurboQuant | runtime modifier | n/a | KV-cache root (weight-agnostic) |
| TurboQuant-MLX-2bit | mlx-lm | ~1.3 GB | Apple Silicon, smallest |
| TurboQuant-MLX-4bit | mlx-lm | ~2.5 GB | Apple Silicon balanced |
| TurboQuant-MLX-8bit | mlx-lm | ~4.7 GB | Apple Silicon reference |
Sources
1 source
Sources
1 sourceVerified Sep 18
Model artifacts
1 artifact
Model artifacts
1 artifactSource excerpts
2 excerpts
Source excerpts
2 excerpts--- license: apache-2.0 base_model: google/gemma-4-E4B tags: - turboquant - kv-cache-quantization - gemma - gemma4 - edge - quantized library_name: transformers pipeline_tag: image-text-to-text --- > [!TIP] > **KV-cache quantization without any fork (recommended, 2026):** upstream > llama.cpp/Ollama now cover this natively — use `-ctk q8_0 -ctv q8_0` > (~half KV memory, negligible quality loss: perplexity +0.002–0.05) or > `-ctk q4_0 -ctv q4_0` (~quarter memory, ≈7.6% perplexity increase). In > Ollama: `OLLAMA_KV_CACHE_TYPE=q8_0` with `OLLAMA_FLASH_ATTENTION=1`. Keep > K and V types symmetric to stay on the fast fused Flash-Attention path. > Since April 2026, mainline llama.cpp also applies Hadamard rotation to > KV activations ([PR #21038](https://github.com/ggml-org/llama.cpp/pull/21038)), > which greatly improves low-bit KV quality (opt-out: > `LLAMA_ATTN_ROT_DISABLE=1`). > > The RotorQuant/TurboQuant fork flow below is **experimental/legacy**: the > TurboQuant llama.cpp PR was closed without merging (June 2026) and the fork > is unmaintained relative to mainline. It is NOT required to use this model. <!-- kv-upstream-note --> # gemma-4-E4B-TurboQuant **TurboQuant KV cache compression** for [google/gemma-4-E4B](https://huggingface.co/google/gemma-4-E4B). This is a **documentation repository** that explains how to combine gemma-4-E4B's weights with TurboQuant inference-time KV cache compression. No weights are stored here — use the base model directly and apply TurboQuant via the Python package or llama.cpp fork. ## Hardware compatibility | Device | VRAM / RAM | Recommendation | | --- | --- | --- | | Any host that runs the base model | baseline + runtime savings | RotorQuant/TurboQuant is a KV-cache runtime modifier; pair with any weight variant | ## What is this? KV cache compression reduces the memory used by the attention cache during inference. Unlike weight quantization (which is baked into the GGUF/MLX file), KV cache compression is applied at runtime — so the same base weights can be used with or without compression. | Technique | Where it's applied | Savings | |-----------|-------------------|---------| | **TurboQuant KV cache** | At inference time | Reduces attention memory (critical for long context) | Both can be combined for maximum efficiency. ## Quickstart ### Option A — Python / transformers Install the `turboquant` pac...
Source context: 32 downloads · 8 likes · Pipeline image-text-to-text · Library transformers · Repo majentik/gemma-4-E4B-turboquant
