Views
No views yet
pip install ternary-quant1from ternary_quant.inference import load_ternary_model
2
3# GPU — fastest (dequantize once, use cuBLAS)
4model, tokenizer = load_ternary_model(
5 "AsadIsmail/Gemma4-E2B-ternary", device="cuda", runtime_mode="cached"
6)
7
8# GPU — lowest VRAM (~2.3 GB (use runtime_mode='gemlite' or 'triton'))
9model, tokenizer = load_ternary_model(
10 "AsadIsmail/Gemma4-E2B-ternary", device="cuda", runtime_mode="gemlite"
11)
12
13# CPU — auto BF16 on Intel AVX2+
14model, tokenizer = load_ternary_model(
15 "AsadIsmail/Gemma4-E2B-ternary", device="cpu", runtime_mode="cached"
16)
17
18# Apple Silicon
19model, tokenizer = load_ternary_model(
20 "AsadIsmail/Gemma4-E2B-ternary", device="mps", runtime_mode="metal"
21)
22
23# Generate
24from ternary_quant.inference import generate_text
25output = generate_text(model, tokenizer, "Ternary quantization works by", max_new_tokens=100)
26print(output)| Hardware | Speed | Mode |
|---|---|---|
| NVIDIA GPU | 15.6 tok/s (CUDA, runtime_mode='cached') | runtime_mode='cached' (dequantize to FP16 once) |
| Intel CPU | 6.3 tok/s (Intel CPU, BF16 auto-detected) | runtime_mode='cached' (auto BF16) |
| Apple Silicon | — | runtime_mode='metal' |
| Property | Value |
|---|---|
| Base model | google/gemma-4-E2B-it |
| Quantized components | text_backbone + vision_backbone |
| Scheme | tritplane3 (sum of ternary planes) |
| Weight values | {-1, 0, +1} packed 2-bit (4 values per byte) |
| Group size | 32 (per-group float16 scale + offset) |
| FP16 VRAM | 4.0 GB |
| Packed VRAM | ~2.3 GB (use runtime_mode='gemlite' or 'triton') |
| Compression | 1.8× (text + vision backbone) |
| Quality | coherent output ✓ (text + image verified) |