Instructions to use majentik/gemma-4-E2B-RotorQuant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use majentik/gemma-4-E2B-RotorQuant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="majentik/gemma-4-E2B-RotorQuant")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("majentik/gemma-4-E2B-RotorQuant", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use majentik/gemma-4-E2B-RotorQuant with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "majentik/gemma-4-E2B-RotorQuant" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "majentik/gemma-4-E2B-RotorQuant", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/majentik/gemma-4-E2B-RotorQuant
- SGLang
How to use majentik/gemma-4-E2B-RotorQuant 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 "majentik/gemma-4-E2B-RotorQuant" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "majentik/gemma-4-E2B-RotorQuant", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "majentik/gemma-4-E2B-RotorQuant" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "majentik/gemma-4-E2B-RotorQuant", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use majentik/gemma-4-E2B-RotorQuant with Docker Model Runner:
docker model run hf.co/majentik/gemma-4-E2B-RotorQuant
Update KV-cache card with accurate template and fork requirements
Browse files
README.md
CHANGED
|
@@ -1,87 +1,137 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
base_model: google/gemma-4-E2B
|
| 3 |
-
library_name: transformers
|
| 4 |
tags:
|
| 5 |
- rotorquant
|
| 6 |
- kv-cache-quantization
|
| 7 |
- gemma
|
| 8 |
- gemma4
|
| 9 |
-
-
|
| 10 |
- quantized
|
| 11 |
-
|
| 12 |
pipeline_tag: image-text-to-text
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
**RotorQuant KV
|
| 18 |
|
| 19 |
-
This repository
|
| 20 |
|
| 21 |
-
##
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
| 26 |
-
|
|
| 27 |
-
|
|
| 28 |
-
| **
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
## Quickstart
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
```python
|
| 35 |
-
|
| 36 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
model_id = "google/gemma-4-E2B"
|
| 39 |
|
| 40 |
-
|
| 41 |
-
model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto")
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
```
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
## What is RotorQuant?
|
| 52 |
|
| 53 |
-
[RotorQuant](https://github.com/scrya-com/rotorquant) is a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
- **5.3x faster prefill**
|
| 57 |
-
- **28% faster decode**
|
| 58 |
-
- **No weight modification** -- model weights stay at original precision
|
| 59 |
-
- **Reduced inference memory** -- KV cache is compressed significantly
|
| 60 |
-
- **Longer context windows** -- fit more tokens in the same GPU memory
|
| 61 |
|
| 62 |
-
##
|
| 63 |
|
| 64 |
-
|
|
| 65 |
-
|---
|
| 66 |
-
|
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
##
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|---|---|
|
| 73 |
-
| FP16 (original) | ~4 GB |
|
| 74 |
-
| 8-bit quantized | ~2 GB |
|
| 75 |
-
| 4-bit quantized | ~1.2 GB |
|
| 76 |
-
| 2-bit quantized | ~0.6 GB |
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
## See Also
|
| 81 |
|
| 82 |
-
- [google/gemma-4-E2B](https://huggingface.co/google/gemma-4-E2B) -- Base model
|
| 83 |
-
- [majentik/gemma-4-E2B-TurboQuant](https://huggingface.co/majentik/gemma-4-E2B-TurboQuant) -- TurboQuant KV-cache variant
|
| 84 |
-
- [majentik/gemma-4-E2B-RotorQuant-MLX-8bit](https://huggingface.co/majentik/gemma-4-E2B-RotorQuant-MLX-8bit) -- MLX 8-bit weight-quantized variant
|
| 85 |
-
- [majentik/gemma-4-E2B-RotorQuant-MLX-4bit](https://huggingface.co/majentik/gemma-4-E2B-RotorQuant-MLX-4bit) -- MLX 4-bit weight-quantized variant
|
| 86 |
-
- [majentik/gemma-4-E2B-RotorQuant-MLX-2bit](https://huggingface.co/majentik/gemma-4-E2B-RotorQuant-MLX-2bit) -- MLX 2-bit weight-quantized variant
|
| 87 |
- [RotorQuant GitHub](https://github.com/scrya-com/rotorquant)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
base_model: google/gemma-4-E2B
|
|
|
|
| 4 |
tags:
|
| 5 |
- rotorquant
|
| 6 |
- kv-cache-quantization
|
| 7 |
- gemma
|
| 8 |
- gemma4
|
| 9 |
+
- edge
|
| 10 |
- quantized
|
| 11 |
+
library_name: transformers
|
| 12 |
pipeline_tag: image-text-to-text
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# gemma-4-E2B-RotorQuant
|
| 16 |
|
| 17 |
+
**RotorQuant KV cache compression** for [google/gemma-4-E2B](https://huggingface.co/google/gemma-4-E2B).
|
| 18 |
|
| 19 |
+
This is a **documentation repository** that explains how to combine gemma-4-E2B's weights with RotorQuant inference-time KV cache compression. No weights are stored here β use the base model directly and apply RotorQuant via the Python package or llama.cpp fork.
|
| 20 |
|
| 21 |
+
## What is this?
|
| 22 |
|
| 23 |
+
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.
|
| 24 |
+
|
| 25 |
+
| Technique | Where it's applied | Savings |
|
| 26 |
+
|-----------|-------------------|---------|
|
| 27 |
+
| Weight quantization (GGUF/MLX/AWQ) | Baked into model file | Reduces disk + weight memory |
|
| 28 |
+
| **RotorQuant KV cache** | At inference time | Reduces attention memory (critical for long context) |
|
| 29 |
+
|
| 30 |
+
Both can be combined for maximum efficiency.
|
| 31 |
|
| 32 |
## Quickstart
|
| 33 |
|
| 34 |
+
### Option A β Python / transformers
|
| 35 |
+
|
| 36 |
+
Install the `rotorquant` package:
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
pip install rotorquant
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Then use it with the base model:
|
| 43 |
+
|
| 44 |
```python
|
| 45 |
+
import torch
|
| 46 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 47 |
+
from rotorquant import IsoQuantCache
|
| 48 |
+
|
| 49 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E2B", trust_remote_code=True)
|
| 50 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 51 |
+
"google/gemma-4-E2B",
|
| 52 |
+
torch_dtype=torch.bfloat16,
|
| 53 |
+
device_map="auto",
|
| 54 |
+
trust_remote_code=True,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Apply RotorQuant to the KV cache
|
| 58 |
+
cache = IsoQuantCache(bits=4) # or bits=2 for more aggressive compression
|
| 59 |
+
|
| 60 |
+
inputs = tokenizer("Hello, how are you?", return_tensors="pt").to(model.device)
|
| 61 |
+
outputs = model.generate(
|
| 62 |
+
**inputs,
|
| 63 |
+
max_new_tokens=128,
|
| 64 |
+
past_key_values=cache,
|
| 65 |
+
use_cache=True,
|
| 66 |
+
)
|
| 67 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
|
| 68 |
+
```
|
| 69 |
|
|
|
|
| 70 |
|
| 71 |
+
### Option B β llama.cpp / LM Studio / Ollama (with fork)
|
|
|
|
| 72 |
|
| 73 |
+
RotorQuant KV cache types (`iso3`) are **not** in upstream llama.cpp. They require:
|
| 74 |
+
- [llama-cpp-turboquant fork](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache)
|
| 75 |
|
| 76 |
+
Once built:
|
| 77 |
+
|
| 78 |
+
```bash
|
| 79 |
+
llama-cli -m gemma-4-E2B.gguf \
|
| 80 |
+
--cache-type-k iso3 --cache-type-v iso3 \
|
| 81 |
+
-ngl 99 -fa \
|
| 82 |
+
-p "Hello"
|
| 83 |
```
|
| 84 |
|
| 85 |
+
For standard runtimes (LM Studio, Ollama, upstream llama.cpp), use conventional KV cache types (`q8_0`, `q4_0`). You lose the RotorQuant-specific benefits but keep GGUF weight quantization.
|
| 86 |
+
|
| 87 |
+
## Model Specifications
|
| 88 |
+
|
| 89 |
+
| Property | Value |
|
| 90 |
+
|----------|-------|
|
| 91 |
+
| Base Model | [google/gemma-4-E2B](https://huggingface.co/google/gemma-4-E2B) |
|
| 92 |
+
| Architecture | Dense transformer (Edge optimised) |
|
| 93 |
+
| Parameters | ~2B |
|
| 94 |
+
| Context Length | 128K |
|
| 95 |
+
| BF16 Size | ~4 GB |
|
| 96 |
+
| Modalities | Text + Image |
|
| 97 |
+
| License | apache-2.0 |
|
| 98 |
+
|
| 99 |
## What is RotorQuant?
|
| 100 |
|
| 101 |
+
[RotorQuant](https://github.com/scrya-com/rotorquant) is a KV cache compression method based on Clifford algebra (Cl(3,0)) rotors β a faster, more parameter-efficient alternative to Google's TurboQuant. Uses lightweight block-diagonal rotations (independent 2D/4D rotations per pair/quartet) achieving O(d) complexity instead of O(d log d), fully parallelisable with no inter-element dependencies.
|
| 102 |
+
|
| 103 |
+
**Benchmarks** (from the RotorQuant repository, Llama 3.1 8B on RTX 5090 β results vary by model and hardware):
|
| 104 |
+
|
| 105 |
+
- Prefill: 3,822 tok/s (vs TurboQuant 722 tok/s)
|
| 106 |
+
- Decode: 119 tok/s (vs TurboQuant 93 tok/s)
|
| 107 |
+
- Perplexity: 6.91 (vs TurboQuant 7.07)
|
| 108 |
+
- Parameters: 4 per rotor (vs TurboQuant 16,384)
|
| 109 |
|
| 110 |
+
> Benchmarks are from the RotorQuant repository using Llama 3.1 8B. Performance on gemma-4-E2B will differ. Please open a discussion if you have independent results.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
## Current Ecosystem Support
|
| 113 |
|
| 114 |
+
| Runtime | RotorQuant Support | Notes |
|
| 115 |
+
|---------|----------------------|-------|
|
| 116 |
+
| Python transformers + `rotorquant` | β
Full | Drop-in cache class |
|
| 117 |
+
| llama.cpp upstream | β Not merged | Use fork below |
|
| 118 |
+
| llama-cpp-turboquant fork | β
`planar3`, `iso3` | [GitHub](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache) |
|
| 119 |
+
| LM Studio | β [Requested](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/1719) | Use `q8_0` as alternative |
|
| 120 |
+
| Ollama | β Not supported | Use `OLLAMA_KV_CACHE_TYPE=q8_0` |
|
| 121 |
+
| vLLM | β Not supported | β |
|
| 122 |
+
| koboldcpp | β Not supported | β |
|
| 123 |
|
| 124 |
+
## Pre-quantized weight variants
|
| 125 |
|
| 126 |
+
If you want combined weight + KV cache compression, majentik hosts pre-quantized versions:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
- [MLX (Apple Silicon)](https://huggingface.co/majentik?search=gemma-4-E2B+MLX)
|
| 129 |
+
- [GGUF (llama.cpp / Ollama / LM Studio)](https://huggingface.co/majentik?search=gemma-4-E2B+GGUF)
|
| 130 |
|
| 131 |
## See Also
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
- [RotorQuant GitHub](https://github.com/scrya-com/rotorquant)
|
| 134 |
+
- [TurboQuant paper (arXiv 2504.19874)](https://arxiv.org/abs/2504.19874)
|
| 135 |
+
- [llama-cpp-turboquant fork](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache)
|
| 136 |
+
- [Base model: google/gemma-4-E2B](https://huggingface.co/google/gemma-4-E2B)
|
| 137 |
+
- [gemma-4-E2B announcement](https://blog.google/technology/developers/gemma-4/)
|