Text Generation
Transformers
rotorquant
kv-cache-quantization
mistral
Mixture of Experts
lean4
formal-proofs
quantized
Instructions to use majentik/Leanstral-RotorQuant with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use majentik/Leanstral-RotorQuant with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="majentik/Leanstral-RotorQuant")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("majentik/Leanstral-RotorQuant", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use majentik/Leanstral-RotorQuant with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "majentik/Leanstral-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/Leanstral-RotorQuant", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/majentik/Leanstral-RotorQuant
- SGLang
How to use majentik/Leanstral-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/Leanstral-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/Leanstral-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/Leanstral-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/Leanstral-RotorQuant", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use majentik/Leanstral-RotorQuant with Docker Model Runner:
docker model run hf.co/majentik/Leanstral-RotorQuant
File size: 6,868 Bytes
feab54a fe57fd2 feab54a 007a3e6 fe57fd2 feab54a fe57fd2 feab54a 007a3e6 fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 feab54a fe57fd2 b1b152f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | ---
license: apache-2.0
base_model: mistralai/Leanstral-2603
tags:
- rotorquant
- kv-cache-quantization
- mistral
- moe
- lean4
- formal-proofs
- quantized
library_name: transformers
pipeline_tag: text-generation
---
# Leanstral-RotorQuant
**RotorQuant KV cache compression** for [mistralai/Leanstral-2603](https://huggingface.co/mistralai/Leanstral-2603).
This is a **documentation repository** that explains how to combine Leanstral'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.
## 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 |
|-----------|-------------------|---------|
| Weight quantization (GGUF/MLX/AWQ) | Baked into model file | Reduces disk + weight memory |
| **RotorQuant 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 `rotorquant` package:
```bash
pip install rotorquant
```
Then use it with the base model:
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from rotorquant import IsoQuantCache
tokenizer = AutoTokenizer.from_pretrained("mistralai/Leanstral-2603", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"mistralai/Leanstral-2603",
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
# Apply RotorQuant to the KV cache
cache = IsoQuantCache(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)
RotorQuant KV cache types (`iso3`) are **not** in upstream llama.cpp. They require:
- [llama-cpp-turboquant fork](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache)
Once built:
```bash
llama-cli -m Leanstral.gguf \
--cache-type-k iso3 --cache-type-v iso3 \
-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 RotorQuant-specific benefits but keep GGUF weight quantization.
## Model Specifications
| Property | Value |
|----------|-------|
| Base Model | [mistralai/Leanstral-2603](https://huggingface.co/mistralai/Leanstral-2603) |
| Architecture | Sparse MoE (128 experts, 4 active) |
| Parameters | 119B total (MoE) |
| Context Length | 256K |
| BF16 Size | ~238 GB |
| Modalities | Text |
| License | apache-2.0 |
## What is RotorQuant?
[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.
**Benchmarks** (from the RotorQuant repository, Llama 3.1 8B on RTX 5090 β results vary by model and hardware):
- Prefill: 3,822 tok/s (vs TurboQuant 722 tok/s)
- Decode: 119 tok/s (vs TurboQuant 93 tok/s)
- Perplexity: 6.91 (vs TurboQuant 7.07)
- Parameters: 4 per rotor (vs TurboQuant 16,384)
> Benchmarks are from the RotorQuant repository using Llama 3.1 8B. Performance on Leanstral will differ. Please open a discussion if you have independent results.
## Current Ecosystem Support
| Runtime | RotorQuant Support | Notes |
|---------|----------------------|-------|
| Python transformers + `rotorquant` | β
Full | Drop-in cache class |
| llama.cpp upstream | β Not merged | Use fork below |
| llama-cpp-turboquant fork | β
`planar3`, `iso3` | [GitHub](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache) |
| LM Studio | β [Requested](https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/1719) | 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:
- [MLX (Apple Silicon)](https://huggingface.co/majentik?search=Leanstral+MLX)
- [GGUF (llama.cpp / Ollama / LM Studio)](https://huggingface.co/majentik?search=Leanstral+GGUF)
## See Also
- [RotorQuant GitHub](https://github.com/scrya-com/rotorquant)
- [TurboQuant paper (arXiv 2504.19874)](https://arxiv.org/abs/2504.19874)
- [llama-cpp-turboquant fork](https://github.com/johndpope/llama-cpp-turboquant/tree/feature/planarquant-kv-cache)
- [Base model: mistralai/Leanstral-2603](https://huggingface.co/mistralai/Leanstral-2603)
- [Leanstral announcement](https://mistral.ai/news/leanstral)
## Variants in this family
(Showing 8 sibling variants under `majentik/leanstral-*`. The current variant β `RotorQuant` β is **bolded**.)
| Variant | Runtime | Approx size | Use case |
|---|---|---|---|
| **RotorQuant** | runtime modifier | n/a | KV-cache root (weight-agnostic) |
| [RotorQuant-MLX-2bit](https://huggingface.co/majentik/leanstral-rotorquant-mlx-2bit) | mlx-lm | card-only | Apple Silicon, smallest |
| [RotorQuant-MLX-4bit](https://huggingface.co/majentik/leanstral-rotorquant-mlx-4bit) | mlx-lm | card-only | Apple Silicon balanced |
| [RotorQuant-MLX-8bit](https://huggingface.co/majentik/leanstral-rotorquant-mlx-8bit) | mlx-lm | card-only | Apple Silicon reference |
| [TurboQuant](https://huggingface.co/majentik/leanstral-turboquant) | runtime modifier | n/a | KV-cache root (weight-agnostic) |
| [TurboQuant-MLX-2bit](https://huggingface.co/majentik/leanstral-turboquant-mlx-2bit) | mlx-lm | card-only | Apple Silicon, smallest |
| [TurboQuant-MLX-4bit](https://huggingface.co/majentik/leanstral-turboquant-mlx-4bit) | mlx-lm | card-only | Apple Silicon balanced |
| [TurboQuant-MLX-8bit](https://huggingface.co/majentik/leanstral-turboquant-mlx-8bit) | mlx-lm | card-only | Apple Silicon reference |
|