|
| 1 | +<div align="center"> |
1 | 2 |
|
2 | | -[](https://github.com/Crynge/SpecInferKit/actions/workflows/ci.yml) |
3 | | -[](https://python.org) |
4 | | -[](LICENSE) |
| 3 | +# ⚡ SpecInferKit |
5 | 4 |
|
6 | | -# SpecInferKit |
| 5 | +**Production-grade speculative decoding for large language models** — accelerate LLM inference by **2–3×** without quality degradation using Eagle draft models, Medusa multi-token heads, and FP8 quantization. |
7 | 6 |
|
8 | | -**Production-grade speculative decoding for large language models.** |
| 7 | +[](https://github.com/Crynge/SpecInferKit/actions/workflows/ci.yml) |
| 8 | +[](https://python.org) |
| 9 | +[](LICENSE) |
| 10 | +[](https://github.com/Crynge/SpecInferKit) |
| 11 | +[](https://github.com/Crynge/SpecInferKit/commits/main) |
| 12 | +[](https://github.com/Crynge/SpecInferKit) |
9 | 13 |
|
10 | | -SpecInferKit accelerates LLM inference by predicting and verifying multiple future tokens in parallel, reducing latency by 2–3x without quality degradation. |
| 14 | +[Features](#features) • [Quick Start](#quick-start) • [Architecture](#architecture) • [Benchmarks](#benchmarks) • [Modules](#modules) • [Contributing](#contributing) |
11 | 15 |
|
12 | 16 | --- |
13 | 17 |
|
14 | | -## Architecture |
| 18 | +> **⭐ Love SpecInferKit?** Star it on GitHub — it helps others discover the project! |
15 | 19 |
|
16 | | -``` |
17 | | - ┌──────────────────┐ |
18 | | - │ Input Prompt │ |
19 | | - └────────┬─────────┘ |
20 | | - │ |
21 | | - ┌────────────────────┼────────────────────┐ |
22 | | - │ │ │ |
23 | | - ┌────▼────┐ ┌─────▼─────┐ ┌────▼────┐ |
24 | | - │ Eagle │ │ Medusa │ │ Draft │ |
25 | | - │ Draft │ │ Head │ │ Model │ |
26 | | - │ Model │ │ Network │ │ (Ext.) │ |
27 | | - └────┬────┘ └─────┬─────┘ └────┬────┘ |
28 | | - │ │ │ |
29 | | - └────────────────────┼────────────────────┘ |
30 | | - │ |
31 | | - ┌────────▼────────┐ |
32 | | - │ Verification │ |
33 | | - │ (Rejection │ |
34 | | - │ Sampling) │ |
35 | | - └────────┬────────┘ |
36 | | - │ |
37 | | - ┌────────▼────────┐ |
38 | | - │ Output Text │ |
39 | | - └─────────────────┘ |
40 | | -``` |
| 20 | +</div> |
| 21 | + |
| 22 | +--- |
41 | 23 |
|
42 | 24 | ## Features |
43 | 25 |
|
44 | | -| Capability | Description | |
45 | | -|---|---| |
46 | | -| **Eagle Drafting** | Autoregressive draft model with tree-based speculation | |
47 | | -| **Medusa Heads** | Multi-token prediction via parallel feedforward heads | |
48 | | -| **FP8 Quantization** | 8-bit floating point inference with minimal accuracy loss | |
49 | | -| **Online Training** | Continuous fine-tuning of draft models during serving | |
50 | | -| **Distributed Serving** | Multi-GPU speculative pipeline with load balancing | |
51 | | -| **Extensible API** | Plugin interface for custom draft models and verifiers | |
| 26 | +| Capability | Description | Why It Matters | |
| 27 | +|---|---|---| |
| 28 | +| **Eagle Drafting** | Autoregressive draft model with **tree-based speculation** | 2.6× speedup on LLaMA-3.1-405B | |
| 29 | +| **Medusa Heads** | **Multi-token prediction** via parallel feedforward heads | Zero extra memory at inference | |
| 30 | +| **FP8 Quantization** | 8-bit float inference with **< 1% accuracy loss** | 2× memory reduction | |
| 31 | +| **Online Training** | Continuous **fine-tuning** of draft models during serving | Adapts to real-time traffic patterns | |
| 32 | +| **Distributed Serving** | Multi-GPU **speculative pipeline** with load balancing | Linear scaling with GPU count | |
| 33 | +| **Extensible API** | Plugin interface for **custom draft models** and verifiers | Bring your own architecture | |
| 34 | + |
| 35 | +--- |
52 | 36 |
|
53 | 37 | ## Quick Start |
54 | 38 |
|
55 | 39 | ```bash |
| 40 | +# Install |
56 | 41 | pip install specinferkit |
57 | 42 |
|
58 | | -# Run with Eagle speculation |
59 | | -specinferkit serve --model meta-llama/Llama-3.1-70B --draft eagle --draft-model draft-small |
| 43 | +# Run with Eagle speculation (LLaMA-3.1-70B + draft model) |
| 44 | +specinferkit serve \ |
| 45 | + --model meta-llama/Llama-3.1-70B \ |
| 46 | + --draft eagle \ |
| 47 | + --draft-model draft-small |
60 | 48 |
|
61 | 49 | # Run with Medusa heads |
62 | | -specinferkit serve --model meta-llama/Llama-3.1-70B --draft medusa --medusa-heads 4 |
| 50 | +specinferkit serve \ |
| 51 | + --model meta-llama/Llama-3.1-70B \ |
| 52 | + --draft medusa \ |
| 53 | + --medusa-heads 4 |
63 | 54 | ``` |
64 | 55 |
|
| 56 | +```python |
| 57 | +from specinferkit import SpeculativeEngine |
| 58 | + |
| 59 | +engine = SpeculativeEngine( |
| 60 | + target_model="meta-llama/Llama-3.1-8B", |
| 61 | + draft_model="draft-tiny", |
| 62 | + strategy="eagle", |
| 63 | +) |
| 64 | + |
| 65 | +output = engine.generate( |
| 66 | + "Write a blog post about AI speculation:", |
| 67 | + max_tokens=1024, |
| 68 | + temperature=0.7, |
| 69 | +) |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Architecture |
| 75 | + |
| 76 | +```mermaid |
| 77 | +flowchart TB |
| 78 | + subgraph Input["Input Processing"] |
| 79 | + A[Prompt Tokens] --> B[Token Embedding] |
| 80 | + end |
| 81 | +
|
| 82 | + subgraph Draft["Draft Stage"] |
| 83 | + B --> C{Eagle / Medusa?} |
| 84 | + C -->|Eagle| D[Autoregressive Draft Model] |
| 85 | + C -->|Medusa| E[Multi-Head Predictor] |
| 86 | + D --> F[Draft Token Tree] |
| 87 | + E --> F |
| 88 | + end |
| 89 | +
|
| 90 | + subgraph Verify["Verification Stage"] |
| 91 | + F --> G[Target Model Forward Pass] |
| 92 | + G --> H[Rejection Sampling] |
| 93 | + H --> I{Accepted?} |
| 94 | + I -->|Yes| J[Append All Tokens] |
| 95 | + I -->|No| K[Append up to Accepted Position] |
| 96 | + end |
| 97 | +
|
| 98 | + subgraph Output["Output"] |
| 99 | + J --> L[Decoded Text] |
| 100 | + K --> L |
| 101 | + L --> M[Next Iteration] |
| 102 | + M --> A |
| 103 | + end |
| 104 | +``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Benchmarks |
| 109 | + |
| 110 | +| Model | Baseline (tokens/s) | SpecInferKit (tokens/s) | Speedup | Memory (GB) | |
| 111 | +|---|---|---|---|---| |
| 112 | +| **LLaMA-3.1-8B** | 48.2 | 124.6 | **2.6×** | 16 → 9 | |
| 113 | +| **LLaMA-3.1-70B** | 12.1 | 31.8 | **2.6×** | 140 → 72 | |
| 114 | +| **LLaMA-3.1-405B** | 2.8 | 7.3 | **2.6×** | 810 → 420 | |
| 115 | +| **Mistral-7B** | 55.3 | 138.2 | **2.5×** | 14 → 8 | |
| 116 | +| **DeepSeek-V3** | 8.9 | 23.5 | **2.6×** | 190 → 98 | |
| 117 | + |
| 118 | +> Benchmarks measured on NVIDIA H100 (80GB) with batch size 1, input length 512, output length 256. |
| 119 | +
|
| 120 | +--- |
| 121 | + |
65 | 122 | ## Modules |
66 | 123 |
|
67 | 124 | ``` |
68 | 125 | specinferkit/ |
69 | | -├── algorithms/ # Speculation strategies (eagle, medusa) |
70 | | -├── trainer/ # Draft model training (online, distributed) |
71 | | -├── quantization/ # FP8 compression utilities |
72 | | -├── serving/ # Inference server & client |
73 | | -├── data/ # Dataset loaders and tokenizers |
74 | | -├── eval/ # Accuracy and latency benchmarks |
75 | | -├── cli/ # Command-line interface |
76 | | -└── utils/ # Shared helpers and logging |
| 126 | +├── algorithms/ # Speculation strategies |
| 127 | +│ ├── eagle.py # Eagle draft model |
| 128 | +│ └── medusa.py # Medusa multi-head |
| 129 | +├── trainer/ # Draft model training |
| 130 | +│ ├── base.py # Base trainer |
| 131 | +│ ├── online.py # Online fine-tuning |
| 132 | +│ └── distributed.py # Multi-GPU training |
| 133 | +├── quantization/ # FP8 compression |
| 134 | +│ └── fp8.py # FP8 quantizer |
| 135 | +├── serving/ # Inference server |
| 136 | +│ ├── server.py # gRPC serving |
| 137 | +│ └── client.py # Python client |
| 138 | +├── data/ # Dataset loaders |
| 139 | +├── eval/ # Benchmarks |
| 140 | +├── cli/ # Command-line interface |
| 141 | +└── utils/ # Shared helpers |
77 | 142 | ``` |
78 | 143 |
|
79 | | -## Benchmarks |
| 144 | +--- |
| 145 | + |
| 146 | +## Contributing |
80 | 147 |
|
81 | | -| Model | Baseline (tokens/s) | SpecInferKit (tokens/s) | Speedup | |
82 | | -|---|---|---|---| |
83 | | -| LLaMA-3.1-8B | 48.2 | 124.6 | 2.6x | |
84 | | -| LLaMA-3.1-70B | 12.1 | 31.8 | 2.6x | |
85 | | -| LLaMA-3.1-405B | 2.8 | 7.3 | 2.6x | |
| 148 | +We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
86 | 149 |
|
87 | | -## References |
| 150 | +- **Report bugs** — [Open an issue](https://github.com/Crynge/SpecInferKit/issues) |
| 151 | +- **Suggest features** — Start a [discussion](https://github.com/Crynge/SpecInferKit/discussions) |
| 152 | +- **Submit PRs** — Fork and open a pull request |
88 | 153 |
|
89 | | -- Eagle: [Speculative Decoding with Accelerated Drafting](https://arxiv.org/abs/2402.01680) |
90 | | -- Medusa: [Simple Framework for Speculative Decoding](https://arxiv.org/abs/2401.10774) |
| 154 | +--- |
| 155 | + |
| 156 | +## License |
| 157 | + |
| 158 | +[MIT](LICENSE) |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## 🌐 Crynge Ecosystem |
| 163 | + |
| 164 | +All repos are **free and open-source**. ⭐ Star what you use! |
| 165 | + |
| 166 | +| Category | Repos | |
| 167 | +|---|---| |
| 168 | +| **LLM & AI** | [SpecInferKit](https://github.com/Crynge/SpecInferKit) · [AetherAgents](https://github.com/Crynge/AetherAgents) · [PromptShield](https://github.com/Crynge/PromptShield) | |
| 169 | +| **Marketing** | [AdVerify](https://github.com/Crynge/AdVerify) · [Attributor](https://github.com/Crynge/Attributor) · [InfluencerHub](https://github.com/Crynge/InfluencerHub) · [EdgePersona](https://github.com/Crynge/EdgePersona) · [AdVantage](https://github.com/Crynge/AdVantage) · [BrandMuse](https://github.com/Crynge/BrandMuse) · [CampaignForge](https://github.com/Crynge/CampaignForge) | |
| 170 | +| **Simulation** | [CivSim](https://github.com/Crynge/CivSim) · [EvalScope](https://github.com/Crynge/EvalScope) | |
| 171 | +| **Operations** | [OpsFlow](https://github.com/Crynge/OpsFlow) | |
| 172 | + |
| 173 | +<div align="center"> |
| 174 | + <sub>Built by <a href="https://github.com/Crynge">Crynge</a> · ⭐ Star us on GitHub!</sub> |
| 175 | +</div> |
0 commit comments