interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / ARCHITECTURE_COVERAGE.md

190 lines · 7646 bytes Raw Blame History Rendered
1# MojoLlama Studio — Architecture Coverage & Per-Architecture Performance
2
3## Overview
4
5MojoLlama Studio supports **10+ model architectures** via the llama.cpp backend.
6This document tracks each architecture's support level, known performance, and
7architecture-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
32The llama.cpp GGUF inference engine natively supports all listed architectures
33without any code changes. The `general.architecture` field in each GGUF model
34determines the tensor naming convention and attention/layer computation path.
35llama.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```
47LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine
48Modules: q_proj, v_proj, k_proj, o_proj
49Format: alpaca, ctx: 2048
50```
51Best for: General instruction tuning, chat fine-tuning.
52
53### Mistral / Mixtral
54```
55LoRA rank: 32, alpha: 64, LR: 1e-4, scheduler: cosine
56Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
57Format: sharegpt, ctx: 4096
58```
59Higher rank due to sliding window attention. MoE variant needs
60full feed-forward module adaptation.
61
62### Qwen2 / Qwen3
63```
64LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: linear
65Modules: q_proj, v_proj
66Format: alpaca, ctx: 2048
67```
68MoE variant (Qwen3-30B-A3B): uses router + expert dispatch via
69TurboEngine v4 universal. ~28.5 tok/s on CPU (Threadripper 3970X).
70
71### DeepSeek V2/V3/R1
72```
73LoRA rank: 64, alpha: 128, LR: 1e-4, scheduler: cosine
74Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
75Format: sharegpt, ctx: 4096
76```
77Multi-head Latent Attention (MLA) compresses KV cache via latent vectors.
78Higher rank recommended for reasoning-heavy tasks. Needs 2x-4x grad
79accumulation for stability.
80
81### Gemma 2/4
82```
83LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine
84Modules: q_proj, v_proj, k_proj, o_proj
85Format: alpaca, ctx: 2048
86```
87Gemma uses GeLU activation (vs SiLU in Llama). Gemma 4 adds RoPE
88scaling differences. GGUF metadata prefix: `gemma.`
89
90### Phi-3/Phi-4
91```
92LoRA rank: 8, alpha: 16, LR: 5e-4, scheduler: constant
93Modules: q_proj, v_proj
94Format: alpaca, ctx: 2048
95```
96Lowest rank recommended — these are small, capable models and
97over-parameterization quickly leads to catastrophic forgetting.
98Higher dropout (0.1) and constant LR work well.
99
100### ChatGLM / GLM-4
101```
102LoRA rank: 16, alpha: 32, LR: 2e-4, scheduler: cosine
103Modules: q_proj, v_proj, k_proj, o_proj
104Format: alpaca, ctx: 2048
105```
106Prefix-encoder architecture: different attention masking pattern
107than decoder-only models. Uses a different tokenizer (sentencepiece
108based). GGUF metadata prefix: `chatglm.`
109
110### Command R / R+
111```
112LoRA rank: 32, alpha: 64, LR: 1e-4, scheduler: cosine
113Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
114Format: sharegpt, ctx: 4096
115```
116Very large FFN layers — full module set recommended for adapters.
117Smaller batch size (2) with grad accumulation due to memory footprint.
118
119## Quantization Handling
120
121Quantization is architecture-agnostic at the GGUF level. The quantizer
122(`quantizer.py`) now reads architecture metadata to determine the correct
123GGUF key prefix for extracting model configuration (context length,
124embedding dim, layers, etc.).
125
126Key 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
143Per-architecture benchmark data (from `llama-bench` on Threadripper 3970X,
14432c/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
160To verify a model loads correctly:
161
162```bash
163# Via MojoLlama server
164mojollama-server --model path/to/model.gguf
165# Check /api/models for architecture detection
166curl http://localhost:8080/api/models | jq '.models[] | {name, architecture, n_params_hr}'
167
168# Direct GGUF metadata read
169python3 -c "
170from mojollama.quantizer import _read_gguf_metadata
171import json
172meta = _read_gguf_metadata('path/to/model.gguf')
173print(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