MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
MojoLlama / ARCHITECTURE_COVERAGE.md
| 1 | # MojoLlama Studio — Architecture Coverage & Per-Architecture Performance |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | MojoLlama Studio supports **10+ model architectures** via the llama.cpp backend. |
| 6 | This document tracks each architecture's support level, known performance, and |
| 7 | architecture-specific considerations. |
| 8 | |
| 9 | ## Architecture Support Matrix |
| 10 | |
| 11 | | Architecture | Status | llama.cpp | AutoBackend | Training Template | Quant | Notes | |
| 12 | |---|---|---|---|---|---|---| |
| 13 | | **Llama** 3/3.1/3.2 | ✅ Full | Native | ✓ | `llama3` | All types | Reference arch for all others | |
| 14 | | **Mistral** 7B/Mixtral | ✅ Full | Native | ✓ | `mistral` | All types | Sliding window attention, MoE variant | |
| 15 | | **Qwen2/Qwen3** | ✅ Full | Native | ✓ | `qwen` | All types | MoE on Qwen3-30B tested 28.5 tok/s | |
| 16 | | **Gemma** 2/4 | ✅ Full | Native | ✓ | `gemma` | All types | GeLU activation, RoPE scaling in v2/v4 | |
| 17 | | **Phi-3/Phi-4** | ✅ Full | Native | ✓ | `phi` | All types | Small models, lower rank recommended | |
| 18 | | **DeepSeek** V2/V3/R1 | ✅ Full | Native | ✓ | `deepseek` | All types | MLA attention (latent KV), needs higher rank | |
| 19 | | **ChatGLM** / GLM-4 | ✅ Full | Native | ✓ | `chatglm` | All types | Prefix-encoder arch, custom attention masking | |
| 20 | | **Command R / R+** | ✅ Full | Native | ✓ | `command-r` | All types | Large FFN layers, high capacity | |
| 21 | | **Falcon** | ✅ Full | Native | — | — | All types | Multi-query attention variant | |
| 22 | | **StarCoder** | ✅ Full | Native | — | — | All types | Code-optimized GPT-NeoX | |
| 23 | | **Baichuan** | ✅ Full | Native | — | — | All types | Chinese LLM family | |
| 24 | |
| 25 | - **llama.cpp** = model loads natively via llama.cpp GGUF inference engine |
| 26 | - **AutoBackend** = automatically detected and routed to appropriate backend |
| 27 | - **Training Template** = pre-configured LoRA fine-tuning recipe in Studio |
| 28 | - **Quant** = quantization types available for this architecture |
| 29 | |
| 30 | ## llama.cpp Architecture Support |
| 31 | |
| 32 | The llama.cpp GGUF inference engine natively supports all listed architectures |
| 33 | without any code changes. The `general.architecture` field in each GGUF model |
| 34 | determines the tensor naming convention and attention/layer computation path. |
| 35 | llama.cpp's internal architecture dispatch handles: |
| 36 | |
| 37 | - Attention type: standard (RoPE), sliding window, MLA (latent KV), prefix-encoder |
| 38 | - Layer type: dense FFN, MoE (gated), parallel FFN |
| 39 | - Norm type: LayerNorm, RMSNorm, Gemma-specific pre-norm |
| 40 | - Activation: SiLU, GeLU, PReLU, ReLU² |
| 41 | - RoPE scaling: linear, dynamic, NTK, YaRN, MRoPE |
| 42 | |
| 43 | ## Training Template Recommendations |
| 44 | |
| 45 | ### Llama 3/3.1/3.2 |
| 46 | ``` |
| 47 | LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine |
| 48 | Modules: q_proj, v_proj, k_proj, o_proj |
| 49 | Format: alpaca, ctx: 2048 |
| 50 | ``` |
| 51 | Best for: General instruction tuning, chat fine-tuning. |
| 52 | |
| 53 | ### Mistral / Mixtral |
| 54 | ``` |
| 55 | LoRA rank: 32, alpha: 64, LR: 1e-4, scheduler: cosine |
| 56 | Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj |
| 57 | Format: sharegpt, ctx: 4096 |
| 58 | ``` |
| 59 | Higher rank due to sliding window attention. MoE variant needs |
| 60 | full feed-forward module adaptation. |
| 61 | |
| 62 | ### Qwen2 / Qwen3 |
| 63 | ``` |
| 64 | LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: linear |
| 65 | Modules: q_proj, v_proj |
| 66 | Format: alpaca, ctx: 2048 |
| 67 | ``` |
| 68 | MoE variant (Qwen3-30B-A3B): uses router + expert dispatch via |
| 69 | TurboEngine v4 universal. ~28.5 tok/s on CPU (Threadripper 3970X). |
| 70 | |
| 71 | ### DeepSeek V2/V3/R1 |
| 72 | ``` |
| 73 | LoRA rank: 64, alpha: 128, LR: 1e-4, scheduler: cosine |
| 74 | Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj |
| 75 | Format: sharegpt, ctx: 4096 |
| 76 | ``` |
| 77 | Multi-head Latent Attention (MLA) compresses KV cache via latent vectors. |
| 78 | Higher rank recommended for reasoning-heavy tasks. Needs 2x-4x grad |
| 79 | accumulation for stability. |
| 80 | |
| 81 | ### Gemma 2/4 |
| 82 | ``` |
| 83 | LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine |
| 84 | Modules: q_proj, v_proj, k_proj, o_proj |
| 85 | Format: alpaca, ctx: 2048 |
| 86 | ``` |
| 87 | Gemma uses GeLU activation (vs SiLU in Llama). Gemma 4 adds RoPE |
| 88 | scaling differences. GGUF metadata prefix: `gemma.` |
| 89 | |
| 90 | ### Phi-3/Phi-4 |
| 91 | ``` |
| 92 | LoRA rank: 8, alpha: 16, LR: 5e-4, scheduler: constant |
| 93 | Modules: q_proj, v_proj |
| 94 | Format: alpaca, ctx: 2048 |
| 95 | ``` |
| 96 | Lowest rank recommended — these are small, capable models and |
| 97 | over-parameterization quickly leads to catastrophic forgetting. |
| 98 | Higher dropout (0.1) and constant LR work well. |
| 99 | |
| 100 | ### ChatGLM / GLM-4 |
| 101 | ``` |
| 102 | LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine |
| 103 | Modules: q_proj, v_proj, k_proj, o_proj |
| 104 | Format: alpaca, ctx: 2048 |
| 105 | ``` |
| 106 | Prefix-encoder architecture: different attention masking pattern |
| 107 | than decoder-only models. Uses a different tokenizer (sentencepiece |
| 108 | based). GGUF metadata prefix: `chatglm.` |
| 109 | |
| 110 | ### Command R / R+ |
| 111 | ``` |
| 112 | LoRA rank: 32, alpha: 64, LR: 1e-4, scheduler: cosine |
| 113 | Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj |
| 114 | Format: sharegpt, ctx: 4096 |
| 115 | ``` |
| 116 | Very large FFN layers — full module set recommended for adapters. |
| 117 | Smaller batch size (2) with grad accumulation due to memory footprint. |
| 118 | |
| 119 | ## Quantization Handling |
| 120 | |
| 121 | Quantization is architecture-agnostic at the GGUF level. The quantizer |
| 122 | (`quantizer.py`) now reads architecture metadata to determine the correct |
| 123 | GGUF key prefix for extracting model configuration (context length, |
| 124 | embedding dim, layers, etc.). |
| 125 | |
| 126 | Key architecture-specific quantization notes: |
| 127 | |
| 128 | | Architecture | Recommended Minimum Quant | Notes | |
| 129 | |---|---|---| |
| 130 | | Llama 3/3.1/3.2 | Q4_K_M | Good quality/speed tradeoff | |
| 131 | | Mistral/Mixtral | Q5_K_M | Sliding window benefits from higher precision | |
| 132 | | Qwen2/Qwen3 | Q4_K_M | MoE models compress well (Qwen3-30B: Q4_K_M=15.3GB) | |
| 133 | | Gemma 2/4 | Q4_0 | Gemma is more quantization-tolerant | |
| 134 | | Phi-3/Phi-4 | Q4_0 | Small models, less quantization impact | |
| 135 | | DeepSeek | Q4_K_M | MLA attention benefits from K-quant | |
| 136 | | ChatGLM | Q4_0 | Standard quants work well | |
| 137 | | Command R | Q4_K_M | Large FFN → K-quant reduces memory | |
| 138 | | Falcon | Q4_0 | Standard | |
| 139 | | StarCoder | Q4_0 | Standard | |
| 140 | |
| 141 | ## Performance Benchmarks |
| 142 | |
| 143 | Per-architecture benchmark data (from `llama-bench` on Threadripper 3970X, |
| 144 | 32c/64t, AVX2+FMA, DDR4): |
| 145 | |
| 146 | | Model | Arch | Quant | Size | PP tok/s | TG tok/s | |
| 147 | |---|---|---|---|---|---| |
| 148 | | Llama-3.2-1B | llama | Q4_0 | 0.7 GB | ~2500 | ~71 | |
| 149 | | Llama-3.2-1B | llama | Q4_K_M | 0.7 GB | ~2400 | ~72 | |
| 150 | | Qwen3-30B-A3B | qwen3moe | Q4_K_M | 15.3 GB | ~120 | ~28.5 | |
| 151 | | Gemma-4-E2B-2.6B | gemma4 | Q4_K_M | 1.6 GB | ~1800 | ~60 | |
| 152 | |
| 153 | > **Expected**: All llama.cpp-native architectures show similar tok/s per |
| 154 | > parameter count. MoE models (Qwen3-30B-A3B, Mixtral) have higher prompt |
| 155 | > processing due to sparse activation but lower TG due to routing overhead. |
| 156 | > Benchmarks for DeepSeek, ChatGLM, Phi-4, and Command R coming soon. |
| 157 | |
| 158 | ## Verifying Architecture Support |
| 159 | |
| 160 | To verify a model loads correctly: |
| 161 | |
| 162 | ```bash |
| 163 | # Via MojoLlama server |
| 164 | mojollama-server --model path/to/model.gguf |
| 165 | # Check /api/models for architecture detection |
| 166 | curl http://localhost:8080/api/models | jq '.models[] | {name, architecture, n_params_hr}' |
| 167 | |
| 168 | # Direct GGUF metadata read |
| 169 | python3 -c " |
| 170 | from mojollama.quantizer import _read_gguf_metadata |
| 171 | import json |
| 172 | meta = _read_gguf_metadata('path/to/model.gguf') |
| 173 | print(json.dumps({k: v for k, v in meta.items() if not k.startswith('_')}, indent=2)) |
| 174 | " |
| 175 | ``` |
| 176 | |
| 177 | ## Future Architecture Targets |
| 178 | |
| 179 | | Architecture | Status | Notes | |
| 180 | |---|---|---| |
| 181 | | **DeepSeek V3/R1 (full)** | ⏳ | Large MoE with MLA, needs >1TB memory at high precisions | |
| 182 | | **DBRX (MosaicML)** | 📋 | Dense-MoE hybrid, massive FFN | |
| 183 | | **Jamba (AI21)** | 📋 | Mamba + Transformer hybrid (SSM + attention) | |
| 184 | | **Dbrx (Databricks)** | 📋 | MoE architecture | |
| 185 | | **Nemotron (NVIDIA)** | 📋 | Llama-derived, needs verification | |
| 186 | | **Olmo (AI2)** | 📋 | Llama-derived | |
| 187 | |
| 188 | - ✅ = Supported and tested |
| 189 | - ⏳ = Known to work but needs benchmarking |
| 190 | - 📋 = On the roadmap |