tokenbench 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TokenBench
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokenbench
3
+ Version: 2.1.0
4
+ Summary: Zero-dependency local GPU VRAM & LLM compatibility checker with Ollama and vLLM launch commands
5
+ Author: TokenBench
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://stigla610.github.io/ai-cost-engine/
8
+ Project-URL: Calculators, https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html
9
+ Project-URL: Benchmarks, https://stigla610.github.io/ai-cost-engine/benchmarks.html
10
+ Project-URL: Cloud GPU Pricing, https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html
11
+ Project-URL: Hugging Face Space, https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator
12
+ Project-URL: Repository, https://github.com/stigla610/ai-cost-engine
13
+ Project-URL: Issues, https://github.com/stigla610/ai-cost-engine/issues
14
+ Keywords: llm,vram,gpu,ollama,vllm,ai-pricing,local-llm
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Dynamic: license-file
30
+
31
+ # ⚑ TokenBench β€” AI API Pricing, LLM VRAM & Cloud GPU Break-Even Engine
32
+
33
+ [![Live Demo](https://img.shields.io/badge/Live_Calculators-TokenBench-38bdf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
34
+ [![PyPI](https://img.shields.io/pypi/v/tokenbench?style=for-the-badge&color=0ea5e9)](https://pypi.org/project/tokenbench/)
35
+ [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-f59e0b?style=for-the-badge)](https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator)
36
+ [![Models Tracked](https://img.shields.io/badge/Models_Tracked-450%2B-10b981?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
37
+ [![Auto-Sync](https://img.shields.io/badge/Updated-Daily_via_GitHub_Actions-818cf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)
38
+
39
+ **TokenBench** is an open, daily-updated benchmark and calculator suite for comparing **LLM API token pricing**, estimating **local GPU VRAM requirements** (FP16, Q8_0, and 4-bit GGUF/AWQ/EXL2 quantization + KV cache overhead), and finding the exact **daily token break-even point** between serverless APIs and dedicated Cloud GPUs.
40
+
41
+ πŸ‘‰ **Launch the Live Web App:** **[https://stigla610.github.io/ai-cost-engine/](https://stigla610.github.io/ai-cost-engine/)**
42
+
43
+ ---
44
+
45
+ ## πŸ–₯️ Local GPU Hardware Checker CLI (`tokenbench`)
46
+
47
+ Zero-dependency Python 3 CLI that auto-detects your local GPU VRAM (`nvidia-smi`, Apple Silicon Unified Memory, or Windows GPU) and tells you which open-weight models fit in FP16, `Q8_0`, or `Q4_K_M`β€”complete with copy-paste **`ollama run`** and **`vllm serve`** commands.
48
+
49
+ ### Install via `pip`
50
+ ```bash
51
+ pip install tokenbench
52
+ tokenbench
53
+ tokenbench --vram 24 --ctx 32768 --search qwen
54
+ ```
55
+
56
+ ### Or Run Instantly (No Install)
57
+
58
+ **Linux / macOS:**
59
+ ```bash
60
+ curl -sL https://stigla610.github.io/ai-cost-engine/tokenbench.py | python3 -
61
+ ```
62
+
63
+ **Windows (PowerShell):**
64
+ ```powershell
65
+ irm https://stigla610.github.io/ai-cost-engine/tokenbench.py | python -
66
+ ```
67
+
68
+ *(Or clone and run `pip install .` from source.)*
69
+
70
+ **Supported CLI Flags:**
71
+ * `--vram 24` β€” Override detected VRAM in GB
72
+ * `--ctx 32768` β€” Account for larger KV-cache context windows
73
+ * `--search llama` β€” Filter by model family (`llama`, `qwen`, `deepseek`, `gemma`, `mistral`)
74
+ * `--live` β€” Pull live pricing and 130+ open-weight models from OpenRouter API
75
+ * `--json` β€” Machine-readable JSON output
76
+
77
+ ```text
78
+ ⚑ TokenBench Local GPU & LLM Compatibility Checker
79
+ ==============================================================================
80
+ Hardware : NVIDIA GPU: NVIDIA GeForce RTX 4090 (24 GB)
81
+ Usable : 24 GB VRAM | Context: 32,768 tokens | Catalog: curated
82
+ ==============================================================================
83
+
84
+ Model Params Q4 Q8 FP16 Fit Run Command
85
+ ------------------------------------------------------------------------------
86
+ Qwen3 8B 8B 5.8G 9.9G 18.8G βœ… FP16 ollama run qwen3:8b
87
+ Qwen3 14B 14B 10.2G 17.4G 32.9G 🟒 Q8_0 ollama run qwen3:14b
88
+ Qwen3 30B A3B (MoE) 30B 21.8G 37.2G 70.5G ⚑ Q4_K_M ollama run qwen3:30b-a3b
89
+ Qwen3 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen3:32b
90
+ Qwen2.5 Coder 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen2.5-coder:32b
91
+ ```
92
+
93
+ ---
94
+
95
+ ## πŸ› οΈ Interactive Calculators & Directories
96
+
97
+ * **[Batch Workload API Cost Simulator](https://stigla610.github.io/ai-cost-engine/)** β€” Slide your daily input/output token volume to rank 450+ models (OpenAI, Anthropic, Google Gemini, DeepSeek, Meta Llama, Qwen, Mistral, xAI Grok) from cheapest to most expensive per month.
98
+ * **[LLM Cost & Break-Even Benchmarks Hub](https://stigla610.github.io/ai-cost-engine/benchmarks.html)** β€” Live break-even tables and workload presets across frontier proprietary and open-weight models.
99
+ * **[LLM VRAM & Home GPU Electricity Calculator](https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html)** β€” Calculate exact GPU memory needed for 1B–405B+ models across context lengths (`2K` to `128K` tokens) and compare your local PC's `$/kWh` power bill against cloud GPU instances.
100
+ * **[Cloud GPU Hourly Price Matrix](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)** β€” Compare on-demand RTX 4090, NVIDIA A100 (80GB), and NVIDIA H100 (80GB) hourly and monthly rates.
101
+
102
+ ---
103
+
104
+ ## πŸ“Š Quick Reference: LLM VRAM Requirements by Model Size
105
+
106
+ Memory estimates include model weights plus baseline 8K context KV-cache overhead:
107
+
108
+ | Parameter Size | Example Open-Weight Models | 4-Bit (Q4_K_M / AWQ) | 8-Bit (Q8_0 / FP8) | 16-Bit (FP16 / BF16) | Recommended Hardware |
109
+ | :--- | :--- | :--- | :--- | :--- | :--- |
110
+ | **7B – 8B** | [Llama 3.1 8B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-1-8b-instruct-vram-requirements.html), Qwen3 8B, Ministral 8B | **5.2 GB** | **9.2 GB** | **17.6 GB** | RTX 3060 12GB / RTX 4060 Ti 16GB |
111
+ | **14B** | [Microsoft Phi-4](https://stigla610.github.io/ai-cost-engine/vram/microsoft-phi-4-vram-requirements.html), [Qwen3 14B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-14b-vram-requirements.html) | **9.1 GB** | **16.1 GB** | **30.8 GB** | RTX 4070 Ti 16GB / RTX 4090 24GB |
112
+ | **24B – 32B** | [Qwen3 32B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-32b-vram-requirements.html), [Mistral Small 24B](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-small-3-2-24b-instruct-vram-requirements.html), [Gemma 4 31B](https://stigla610.github.io/ai-cost-engine/vram/google-gemma-4-31b-it-vram-requirements.html) | **15.6 – 20.8 GB** | **27.6 – 36.8 GB** | **52.8 – 70.4 GB** | 1x RTX 3090 / 4090 (24GB) |
113
+ | **70B – 72B** | [Llama 3.3 70B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-3-70b-instruct-vram-requirements.html), [Qwen2.5 72B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen-2-5-72b-instruct-vram-requirements.html) | **45.5 – 46.8 GB** | **80.5 – 82.8 GB** | **154.0 – 158.4 GB** | 2x RTX 3090/4090 (48GB) or 1x A100 80GB |
114
+ | **109B – 123B** | [Llama 4 Scout](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-scout-vram-requirements.html), [Mistral Large](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-large-vram-requirements.html), [gpt-oss-120b](https://stigla610.github.io/ai-cost-engine/vram/openai-gpt-oss-120b-vram-requirements.html) | **70.8 – 80.0 GB** | **125.4 – 141.5 GB** | **239.8 – 270.6 GB** | 1x–2x A100 / H100 80GB or Mac Ultra |
115
+ | **235B – 400B** | [Qwen3 235B MoE](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-235b-a22b-2507-vram-requirements.html), [Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-maverick-vram-requirements.html) | **152.8 – 260.0 GB** | **270.2 – 460.0 GB** | **517.0 – 880.0 GB** | 2x–4x H100 80GB Cluster |
116
+ | **671B MoE** | [DeepSeek V3](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-chat-vram-requirements.html), [DeepSeek R1](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-r1-0528-vram-requirements.html) | **436.2 GB** | **771.6 GB** | **1,476.2 GB** | 6x–8x H100 / A100 80GB Node |
117
+
118
+ ---
119
+
120
+ ## βš–οΈ Popular Head-to-Head API Cost Comparisons
121
+
122
+ * [OpenAI GPT-5 vs Anthropic Claude Sonnet 4.5](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-anthropic-claude-sonnet-4-5.html)
123
+ * [OpenAI GPT-5 vs Google Gemini 2.5 Pro](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-google-gemini-2-5-pro.html)
124
+ * [OpenAI GPT-5 vs DeepSeek V3](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-deepseek-deepseek-chat.html)
125
+ * [OpenAI GPT-5 vs Meta Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-meta-llama-llama-4-maverick.html)
126
+ * [OpenAI GPT-5 vs Qwen3 32B](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-qwen-qwen3-32b.html)
127
+
128
+ ---
129
+
130
+ ## πŸš€ Building Locally
131
+
132
+ ```bash
133
+ python build_site.py
134
+ ```
135
+
136
+ Generates all static HTML calculators, JSON-LD structured data, SVG brand assets, and `sitemap.xml` inside `./dist`.
@@ -0,0 +1,106 @@
1
+ # ⚑ TokenBench β€” AI API Pricing, LLM VRAM & Cloud GPU Break-Even Engine
2
+
3
+ [![Live Demo](https://img.shields.io/badge/Live_Calculators-TokenBench-38bdf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
4
+ [![PyPI](https://img.shields.io/pypi/v/tokenbench?style=for-the-badge&color=0ea5e9)](https://pypi.org/project/tokenbench/)
5
+ [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-f59e0b?style=for-the-badge)](https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator)
6
+ [![Models Tracked](https://img.shields.io/badge/Models_Tracked-450%2B-10b981?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
7
+ [![Auto-Sync](https://img.shields.io/badge/Updated-Daily_via_GitHub_Actions-818cf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)
8
+
9
+ **TokenBench** is an open, daily-updated benchmark and calculator suite for comparing **LLM API token pricing**, estimating **local GPU VRAM requirements** (FP16, Q8_0, and 4-bit GGUF/AWQ/EXL2 quantization + KV cache overhead), and finding the exact **daily token break-even point** between serverless APIs and dedicated Cloud GPUs.
10
+
11
+ πŸ‘‰ **Launch the Live Web App:** **[https://stigla610.github.io/ai-cost-engine/](https://stigla610.github.io/ai-cost-engine/)**
12
+
13
+ ---
14
+
15
+ ## πŸ–₯️ Local GPU Hardware Checker CLI (`tokenbench`)
16
+
17
+ Zero-dependency Python 3 CLI that auto-detects your local GPU VRAM (`nvidia-smi`, Apple Silicon Unified Memory, or Windows GPU) and tells you which open-weight models fit in FP16, `Q8_0`, or `Q4_K_M`β€”complete with copy-paste **`ollama run`** and **`vllm serve`** commands.
18
+
19
+ ### Install via `pip`
20
+ ```bash
21
+ pip install tokenbench
22
+ tokenbench
23
+ tokenbench --vram 24 --ctx 32768 --search qwen
24
+ ```
25
+
26
+ ### Or Run Instantly (No Install)
27
+
28
+ **Linux / macOS:**
29
+ ```bash
30
+ curl -sL https://stigla610.github.io/ai-cost-engine/tokenbench.py | python3 -
31
+ ```
32
+
33
+ **Windows (PowerShell):**
34
+ ```powershell
35
+ irm https://stigla610.github.io/ai-cost-engine/tokenbench.py | python -
36
+ ```
37
+
38
+ *(Or clone and run `pip install .` from source.)*
39
+
40
+ **Supported CLI Flags:**
41
+ * `--vram 24` β€” Override detected VRAM in GB
42
+ * `--ctx 32768` β€” Account for larger KV-cache context windows
43
+ * `--search llama` β€” Filter by model family (`llama`, `qwen`, `deepseek`, `gemma`, `mistral`)
44
+ * `--live` β€” Pull live pricing and 130+ open-weight models from OpenRouter API
45
+ * `--json` β€” Machine-readable JSON output
46
+
47
+ ```text
48
+ ⚑ TokenBench Local GPU & LLM Compatibility Checker
49
+ ==============================================================================
50
+ Hardware : NVIDIA GPU: NVIDIA GeForce RTX 4090 (24 GB)
51
+ Usable : 24 GB VRAM | Context: 32,768 tokens | Catalog: curated
52
+ ==============================================================================
53
+
54
+ Model Params Q4 Q8 FP16 Fit Run Command
55
+ ------------------------------------------------------------------------------
56
+ Qwen3 8B 8B 5.8G 9.9G 18.8G βœ… FP16 ollama run qwen3:8b
57
+ Qwen3 14B 14B 10.2G 17.4G 32.9G 🟒 Q8_0 ollama run qwen3:14b
58
+ Qwen3 30B A3B (MoE) 30B 21.8G 37.2G 70.5G ⚑ Q4_K_M ollama run qwen3:30b-a3b
59
+ Qwen3 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen3:32b
60
+ Qwen2.5 Coder 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen2.5-coder:32b
61
+ ```
62
+
63
+ ---
64
+
65
+ ## πŸ› οΈ Interactive Calculators & Directories
66
+
67
+ * **[Batch Workload API Cost Simulator](https://stigla610.github.io/ai-cost-engine/)** β€” Slide your daily input/output token volume to rank 450+ models (OpenAI, Anthropic, Google Gemini, DeepSeek, Meta Llama, Qwen, Mistral, xAI Grok) from cheapest to most expensive per month.
68
+ * **[LLM Cost & Break-Even Benchmarks Hub](https://stigla610.github.io/ai-cost-engine/benchmarks.html)** β€” Live break-even tables and workload presets across frontier proprietary and open-weight models.
69
+ * **[LLM VRAM & Home GPU Electricity Calculator](https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html)** β€” Calculate exact GPU memory needed for 1B–405B+ models across context lengths (`2K` to `128K` tokens) and compare your local PC's `$/kWh` power bill against cloud GPU instances.
70
+ * **[Cloud GPU Hourly Price Matrix](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)** β€” Compare on-demand RTX 4090, NVIDIA A100 (80GB), and NVIDIA H100 (80GB) hourly and monthly rates.
71
+
72
+ ---
73
+
74
+ ## πŸ“Š Quick Reference: LLM VRAM Requirements by Model Size
75
+
76
+ Memory estimates include model weights plus baseline 8K context KV-cache overhead:
77
+
78
+ | Parameter Size | Example Open-Weight Models | 4-Bit (Q4_K_M / AWQ) | 8-Bit (Q8_0 / FP8) | 16-Bit (FP16 / BF16) | Recommended Hardware |
79
+ | :--- | :--- | :--- | :--- | :--- | :--- |
80
+ | **7B – 8B** | [Llama 3.1 8B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-1-8b-instruct-vram-requirements.html), Qwen3 8B, Ministral 8B | **5.2 GB** | **9.2 GB** | **17.6 GB** | RTX 3060 12GB / RTX 4060 Ti 16GB |
81
+ | **14B** | [Microsoft Phi-4](https://stigla610.github.io/ai-cost-engine/vram/microsoft-phi-4-vram-requirements.html), [Qwen3 14B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-14b-vram-requirements.html) | **9.1 GB** | **16.1 GB** | **30.8 GB** | RTX 4070 Ti 16GB / RTX 4090 24GB |
82
+ | **24B – 32B** | [Qwen3 32B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-32b-vram-requirements.html), [Mistral Small 24B](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-small-3-2-24b-instruct-vram-requirements.html), [Gemma 4 31B](https://stigla610.github.io/ai-cost-engine/vram/google-gemma-4-31b-it-vram-requirements.html) | **15.6 – 20.8 GB** | **27.6 – 36.8 GB** | **52.8 – 70.4 GB** | 1x RTX 3090 / 4090 (24GB) |
83
+ | **70B – 72B** | [Llama 3.3 70B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-3-70b-instruct-vram-requirements.html), [Qwen2.5 72B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen-2-5-72b-instruct-vram-requirements.html) | **45.5 – 46.8 GB** | **80.5 – 82.8 GB** | **154.0 – 158.4 GB** | 2x RTX 3090/4090 (48GB) or 1x A100 80GB |
84
+ | **109B – 123B** | [Llama 4 Scout](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-scout-vram-requirements.html), [Mistral Large](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-large-vram-requirements.html), [gpt-oss-120b](https://stigla610.github.io/ai-cost-engine/vram/openai-gpt-oss-120b-vram-requirements.html) | **70.8 – 80.0 GB** | **125.4 – 141.5 GB** | **239.8 – 270.6 GB** | 1x–2x A100 / H100 80GB or Mac Ultra |
85
+ | **235B – 400B** | [Qwen3 235B MoE](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-235b-a22b-2507-vram-requirements.html), [Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-maverick-vram-requirements.html) | **152.8 – 260.0 GB** | **270.2 – 460.0 GB** | **517.0 – 880.0 GB** | 2x–4x H100 80GB Cluster |
86
+ | **671B MoE** | [DeepSeek V3](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-chat-vram-requirements.html), [DeepSeek R1](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-r1-0528-vram-requirements.html) | **436.2 GB** | **771.6 GB** | **1,476.2 GB** | 6x–8x H100 / A100 80GB Node |
87
+
88
+ ---
89
+
90
+ ## βš–οΈ Popular Head-to-Head API Cost Comparisons
91
+
92
+ * [OpenAI GPT-5 vs Anthropic Claude Sonnet 4.5](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-anthropic-claude-sonnet-4-5.html)
93
+ * [OpenAI GPT-5 vs Google Gemini 2.5 Pro](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-google-gemini-2-5-pro.html)
94
+ * [OpenAI GPT-5 vs DeepSeek V3](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-deepseek-deepseek-chat.html)
95
+ * [OpenAI GPT-5 vs Meta Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-meta-llama-llama-4-maverick.html)
96
+ * [OpenAI GPT-5 vs Qwen3 32B](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-qwen-qwen3-32b.html)
97
+
98
+ ---
99
+
100
+ ## πŸš€ Building Locally
101
+
102
+ ```bash
103
+ python build_site.py
104
+ ```
105
+
106
+ Generates all static HTML calculators, JSON-LD structured data, SVG brand assets, and `sitemap.xml` inside `./dist`.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tokenbench"
7
+ version = "2.1.0"
8
+ description = "Zero-dependency local GPU VRAM & LLM compatibility checker with Ollama and vLLM launch commands"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{name = "TokenBench"}]
13
+ requires-python = ">=3.8"
14
+ keywords = ["llm", "vram", "gpu", "ollama", "vllm", "ai-pricing", "local-llm"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.8",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://stigla610.github.io/ai-cost-engine/"
31
+ Calculators = "https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html"
32
+ Benchmarks = "https://stigla610.github.io/ai-cost-engine/benchmarks.html"
33
+ "Cloud GPU Pricing" = "https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html"
34
+ "Hugging Face Space" = "https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator"
35
+ Repository = "https://github.com/stigla610/ai-cost-engine"
36
+ Issues = "https://github.com/stigla610/ai-cost-engine/issues"
37
+
38
+ [project.scripts]
39
+ tokenbench = "tokenbench:main"
40
+
41
+ [tool.setuptools]
42
+ py-modules = ["tokenbench"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokenbench
3
+ Version: 2.1.0
4
+ Summary: Zero-dependency local GPU VRAM & LLM compatibility checker with Ollama and vLLM launch commands
5
+ Author: TokenBench
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://stigla610.github.io/ai-cost-engine/
8
+ Project-URL: Calculators, https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html
9
+ Project-URL: Benchmarks, https://stigla610.github.io/ai-cost-engine/benchmarks.html
10
+ Project-URL: Cloud GPU Pricing, https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html
11
+ Project-URL: Hugging Face Space, https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator
12
+ Project-URL: Repository, https://github.com/stigla610/ai-cost-engine
13
+ Project-URL: Issues, https://github.com/stigla610/ai-cost-engine/issues
14
+ Keywords: llm,vram,gpu,ollama,vllm,ai-pricing,local-llm
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Dynamic: license-file
30
+
31
+ # ⚑ TokenBench β€” AI API Pricing, LLM VRAM & Cloud GPU Break-Even Engine
32
+
33
+ [![Live Demo](https://img.shields.io/badge/Live_Calculators-TokenBench-38bdf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
34
+ [![PyPI](https://img.shields.io/pypi/v/tokenbench?style=for-the-badge&color=0ea5e9)](https://pypi.org/project/tokenbench/)
35
+ [![Hugging Face Space](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Space-f59e0b?style=for-the-badge)](https://huggingface.co/spaces/stigla610/llm-vram-cost-calculator)
36
+ [![Models Tracked](https://img.shields.io/badge/Models_Tracked-450%2B-10b981?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/)
37
+ [![Auto-Sync](https://img.shields.io/badge/Updated-Daily_via_GitHub_Actions-818cf8?style=for-the-badge)](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)
38
+
39
+ **TokenBench** is an open, daily-updated benchmark and calculator suite for comparing **LLM API token pricing**, estimating **local GPU VRAM requirements** (FP16, Q8_0, and 4-bit GGUF/AWQ/EXL2 quantization + KV cache overhead), and finding the exact **daily token break-even point** between serverless APIs and dedicated Cloud GPUs.
40
+
41
+ πŸ‘‰ **Launch the Live Web App:** **[https://stigla610.github.io/ai-cost-engine/](https://stigla610.github.io/ai-cost-engine/)**
42
+
43
+ ---
44
+
45
+ ## πŸ–₯️ Local GPU Hardware Checker CLI (`tokenbench`)
46
+
47
+ Zero-dependency Python 3 CLI that auto-detects your local GPU VRAM (`nvidia-smi`, Apple Silicon Unified Memory, or Windows GPU) and tells you which open-weight models fit in FP16, `Q8_0`, or `Q4_K_M`β€”complete with copy-paste **`ollama run`** and **`vllm serve`** commands.
48
+
49
+ ### Install via `pip`
50
+ ```bash
51
+ pip install tokenbench
52
+ tokenbench
53
+ tokenbench --vram 24 --ctx 32768 --search qwen
54
+ ```
55
+
56
+ ### Or Run Instantly (No Install)
57
+
58
+ **Linux / macOS:**
59
+ ```bash
60
+ curl -sL https://stigla610.github.io/ai-cost-engine/tokenbench.py | python3 -
61
+ ```
62
+
63
+ **Windows (PowerShell):**
64
+ ```powershell
65
+ irm https://stigla610.github.io/ai-cost-engine/tokenbench.py | python -
66
+ ```
67
+
68
+ *(Or clone and run `pip install .` from source.)*
69
+
70
+ **Supported CLI Flags:**
71
+ * `--vram 24` β€” Override detected VRAM in GB
72
+ * `--ctx 32768` β€” Account for larger KV-cache context windows
73
+ * `--search llama` β€” Filter by model family (`llama`, `qwen`, `deepseek`, `gemma`, `mistral`)
74
+ * `--live` β€” Pull live pricing and 130+ open-weight models from OpenRouter API
75
+ * `--json` β€” Machine-readable JSON output
76
+
77
+ ```text
78
+ ⚑ TokenBench Local GPU & LLM Compatibility Checker
79
+ ==============================================================================
80
+ Hardware : NVIDIA GPU: NVIDIA GeForce RTX 4090 (24 GB)
81
+ Usable : 24 GB VRAM | Context: 32,768 tokens | Catalog: curated
82
+ ==============================================================================
83
+
84
+ Model Params Q4 Q8 FP16 Fit Run Command
85
+ ------------------------------------------------------------------------------
86
+ Qwen3 8B 8B 5.8G 9.9G 18.8G βœ… FP16 ollama run qwen3:8b
87
+ Qwen3 14B 14B 10.2G 17.4G 32.9G 🟒 Q8_0 ollama run qwen3:14b
88
+ Qwen3 30B A3B (MoE) 30B 21.8G 37.2G 70.5G ⚑ Q4_K_M ollama run qwen3:30b-a3b
89
+ Qwen3 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen3:32b
90
+ Qwen2.5 Coder 32B 32B 23.2G 39.7G 75.2G ⚑ Q4_K_M ollama run qwen2.5-coder:32b
91
+ ```
92
+
93
+ ---
94
+
95
+ ## πŸ› οΈ Interactive Calculators & Directories
96
+
97
+ * **[Batch Workload API Cost Simulator](https://stigla610.github.io/ai-cost-engine/)** β€” Slide your daily input/output token volume to rank 450+ models (OpenAI, Anthropic, Google Gemini, DeepSeek, Meta Llama, Qwen, Mistral, xAI Grok) from cheapest to most expensive per month.
98
+ * **[LLM Cost & Break-Even Benchmarks Hub](https://stigla610.github.io/ai-cost-engine/benchmarks.html)** β€” Live break-even tables and workload presets across frontier proprietary and open-weight models.
99
+ * **[LLM VRAM & Home GPU Electricity Calculator](https://stigla610.github.io/ai-cost-engine/vram-electricity-calculator.html)** β€” Calculate exact GPU memory needed for 1B–405B+ models across context lengths (`2K` to `128K` tokens) and compare your local PC's `$/kWh` power bill against cloud GPU instances.
100
+ * **[Cloud GPU Hourly Price Matrix](https://stigla610.github.io/ai-cost-engine/gpu-cloud-pricing.html)** β€” Compare on-demand RTX 4090, NVIDIA A100 (80GB), and NVIDIA H100 (80GB) hourly and monthly rates.
101
+
102
+ ---
103
+
104
+ ## πŸ“Š Quick Reference: LLM VRAM Requirements by Model Size
105
+
106
+ Memory estimates include model weights plus baseline 8K context KV-cache overhead:
107
+
108
+ | Parameter Size | Example Open-Weight Models | 4-Bit (Q4_K_M / AWQ) | 8-Bit (Q8_0 / FP8) | 16-Bit (FP16 / BF16) | Recommended Hardware |
109
+ | :--- | :--- | :--- | :--- | :--- | :--- |
110
+ | **7B – 8B** | [Llama 3.1 8B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-1-8b-instruct-vram-requirements.html), Qwen3 8B, Ministral 8B | **5.2 GB** | **9.2 GB** | **17.6 GB** | RTX 3060 12GB / RTX 4060 Ti 16GB |
111
+ | **14B** | [Microsoft Phi-4](https://stigla610.github.io/ai-cost-engine/vram/microsoft-phi-4-vram-requirements.html), [Qwen3 14B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-14b-vram-requirements.html) | **9.1 GB** | **16.1 GB** | **30.8 GB** | RTX 4070 Ti 16GB / RTX 4090 24GB |
112
+ | **24B – 32B** | [Qwen3 32B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-32b-vram-requirements.html), [Mistral Small 24B](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-small-3-2-24b-instruct-vram-requirements.html), [Gemma 4 31B](https://stigla610.github.io/ai-cost-engine/vram/google-gemma-4-31b-it-vram-requirements.html) | **15.6 – 20.8 GB** | **27.6 – 36.8 GB** | **52.8 – 70.4 GB** | 1x RTX 3090 / 4090 (24GB) |
113
+ | **70B – 72B** | [Llama 3.3 70B](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-3-3-70b-instruct-vram-requirements.html), [Qwen2.5 72B](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen-2-5-72b-instruct-vram-requirements.html) | **45.5 – 46.8 GB** | **80.5 – 82.8 GB** | **154.0 – 158.4 GB** | 2x RTX 3090/4090 (48GB) or 1x A100 80GB |
114
+ | **109B – 123B** | [Llama 4 Scout](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-scout-vram-requirements.html), [Mistral Large](https://stigla610.github.io/ai-cost-engine/vram/mistralai-mistral-large-vram-requirements.html), [gpt-oss-120b](https://stigla610.github.io/ai-cost-engine/vram/openai-gpt-oss-120b-vram-requirements.html) | **70.8 – 80.0 GB** | **125.4 – 141.5 GB** | **239.8 – 270.6 GB** | 1x–2x A100 / H100 80GB or Mac Ultra |
115
+ | **235B – 400B** | [Qwen3 235B MoE](https://stigla610.github.io/ai-cost-engine/vram/qwen-qwen3-235b-a22b-2507-vram-requirements.html), [Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/vram/meta-llama-llama-4-maverick-vram-requirements.html) | **152.8 – 260.0 GB** | **270.2 – 460.0 GB** | **517.0 – 880.0 GB** | 2x–4x H100 80GB Cluster |
116
+ | **671B MoE** | [DeepSeek V3](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-chat-vram-requirements.html), [DeepSeek R1](https://stigla610.github.io/ai-cost-engine/vram/deepseek-deepseek-r1-0528-vram-requirements.html) | **436.2 GB** | **771.6 GB** | **1,476.2 GB** | 6x–8x H100 / A100 80GB Node |
117
+
118
+ ---
119
+
120
+ ## βš–οΈ Popular Head-to-Head API Cost Comparisons
121
+
122
+ * [OpenAI GPT-5 vs Anthropic Claude Sonnet 4.5](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-anthropic-claude-sonnet-4-5.html)
123
+ * [OpenAI GPT-5 vs Google Gemini 2.5 Pro](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-google-gemini-2-5-pro.html)
124
+ * [OpenAI GPT-5 vs DeepSeek V3](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-deepseek-deepseek-chat.html)
125
+ * [OpenAI GPT-5 vs Meta Llama 4 Maverick](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-meta-llama-llama-4-maverick.html)
126
+ * [OpenAI GPT-5 vs Qwen3 32B](https://stigla610.github.io/ai-cost-engine/compare/openai-gpt-5-vs-qwen-qwen3-32b.html)
127
+
128
+ ---
129
+
130
+ ## πŸš€ Building Locally
131
+
132
+ ```bash
133
+ python build_site.py
134
+ ```
135
+
136
+ Generates all static HTML calculators, JSON-LD structured data, SVG brand assets, and `sitemap.xml` inside `./dist`.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ tokenbench.py
5
+ tokenbench.egg-info/PKG-INFO
6
+ tokenbench.egg-info/SOURCES.txt
7
+ tokenbench.egg-info/dependency_links.txt
8
+ tokenbench.egg-info/entry_points.txt
9
+ tokenbench.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tokenbench = tokenbench:main
@@ -0,0 +1 @@
1
+ tokenbench
@@ -0,0 +1,453 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ TokenBench CLI β€” Local GPU Hardware Checker & LLM VRAM / Deploy Command Advisor.
4
+
5
+ Zero-dependency Python 3 utility that detects your local GPU VRAM (NVIDIA via nvidia-smi,
6
+ Apple Silicon Unified Memory, or Windows/Linux GPU fallback) and shows which open-weight LLMs
7
+ fit in FP16, 8-bit (Q8_0), or 4-bit (Q4_K_M / AWQ) quantization at your target context length,
8
+ along with ready-to-run Ollama and vLLM commands.
9
+
10
+ Usage:
11
+ python tokenbench.py
12
+ python tokenbench.py --vram 24 --ctx 32768 --search qwen
13
+ python tokenbench.py --live --search llama
14
+ """
15
+
16
+ import argparse
17
+ import json
18
+ import os
19
+ import platform
20
+ import re
21
+ import subprocess
22
+ import sys
23
+ import urllib.request
24
+
25
+ __version__ = "2.1.0"
26
+ SITE_BASE_URL = "https://stigla610.github.io/ai-cost-engine"
27
+
28
+ CURATED_OPEN_MODELS = [
29
+ {"name": "Llama 3.2 1B", "params_b": 1.2, "ollama": "llama3.2:1b", "hf": "meta-llama/Llama-3.2-1B-Instruct", "ctx": 131072},
30
+ {"name": "Llama 3.2 3B", "params_b": 3.2, "ollama": "llama3.2:3b", "hf": "meta-llama/Llama-3.2-3B-Instruct", "ctx": 131072},
31
+ {"name": "Gemma 3 4B", "params_b": 4.0, "ollama": "gemma3:4b", "hf": "google/gemma-3-4b-it", "ctx": 131072},
32
+ {"name": "Llama 3.1 8B Instruct", "params_b": 8.0, "ollama": "llama3.1:8b", "hf": "meta-llama/Llama-3.1-8B-Instruct", "ctx": 131072},
33
+ {"name": "Qwen3 8B", "params_b": 8.0, "ollama": "qwen3:8b", "hf": "Qwen/Qwen3-8B", "ctx": 131072},
34
+ {"name": "Mistral Nemo 12B", "params_b": 12.2, "ollama": "mistral-nemo:12b", "hf": "mistralai/Mistral-Nemo-Instruct-2407", "ctx": 131072},
35
+ {"name": "Gemma 3 12B", "params_b": 12.0, "ollama": "gemma3:12b", "hf": "google/gemma-3-12b-it", "ctx": 131072},
36
+ {"name": "Microsoft Phi-4 14B", "params_b": 14.0, "ollama": "phi4:14b", "hf": "microsoft/phi-4", "ctx": 16384},
37
+ {"name": "Qwen3 14B", "params_b": 14.0, "ollama": "qwen3:14b", "hf": "Qwen/Qwen3-14B", "ctx": 131072},
38
+ {"name": "OpenAI gpt-oss-20b", "params_b": 20.0, "ollama": "gpt-oss:20b", "hf": "openai/gpt-oss-20b", "ctx": 131072},
39
+ {"name": "Codestral 22B", "params_b": 22.0, "ollama": "codestral:22b", "hf": "mistralai/Codestral-22B-v0.1", "ctx": 32768},
40
+ {"name": "Mistral Small 3.2 24B", "params_b": 24.0, "ollama": "mistral-small3.2:24b", "hf": "mistralai/Mistral-Small-3.2-24B-Instruct-2506", "ctx": 131072},
41
+ {"name": "Gemma 4 26B A4B", "params_b": 26.0, "ollama": "gemma4:26b", "hf": "google/gemma-4-26b-a4b-it", "ctx": 131072},
42
+ {"name": "Gemma 3 27B", "params_b": 27.0, "ollama": "gemma3:27b", "hf": "google/gemma-3-27b-it", "ctx": 131072},
43
+ {"name": "Qwen3 30B A3B (MoE)", "params_b": 30.0, "ollama": "qwen3:30b-a3b", "hf": "Qwen/Qwen3-30B-A3B", "ctx": 131072},
44
+ {"name": "Gemma 4 31B", "params_b": 31.0, "ollama": "gemma4:31b", "hf": "google/gemma-4-31b-it", "ctx": 131072},
45
+ {"name": "Qwen3 32B", "params_b": 32.0, "ollama": "qwen3:32b", "hf": "Qwen/Qwen3-32B", "ctx": 131072},
46
+ {"name": "Qwen2.5 Coder 32B", "params_b": 32.0, "ollama": "qwen2.5-coder:32b", "hf": "Qwen/Qwen2.5-Coder-32B-Instruct", "ctx": 32768},
47
+ {"name": "Llama 3.3 70B Instruct", "params_b": 70.0, "ollama": "llama3.3:70b", "hf": "meta-llama/Llama-3.3-70B-Instruct", "ctx": 131072},
48
+ {"name": "Qwen2.5 72B Instruct", "params_b": 72.0, "ollama": "qwen2.5:72b", "hf": "Qwen/Qwen2.5-72B-Instruct", "ctx": 32768},
49
+ {"name": "Llama 4 Scout (109B MoE)", "params_b": 109.0, "ollama": "llama4:scout", "hf": "meta-llama/Llama-4-Scout-17B-16E-Instruct", "ctx": 131072},
50
+ {"name": "OpenAI gpt-oss-120b", "params_b": 120.0, "ollama": "gpt-oss:120b", "hf": "openai/gpt-oss-120b", "ctx": 131072},
51
+ {"name": "Mistral Large 123B", "params_b": 123.0, "ollama": "mistral-large:123b", "hf": "mistralai/Mistral-Large-Instruct-2411", "ctx": 131072},
52
+ {"name": "Qwen3 235B A22B (MoE)", "params_b": 235.0, "ollama": "qwen3:235b-a22b", "hf": "Qwen/Qwen3-235B-A22B", "ctx": 131072},
53
+ {"name": "Llama 4 Maverick (400B MoE)", "params_b": 400.0, "ollama": "llama4:maverick", "hf": "meta-llama/Llama-4-Maverick-17B-128E-Instruct", "ctx": 131072},
54
+ {"name": "DeepSeek V3 (671B MoE)", "params_b": 671.0, "ollama": "deepseek-v3:671b", "hf": "deepseek-ai/DeepSeek-V3", "ctx": 163840},
55
+ {"name": "DeepSeek R1 (671B MoE)", "params_b": 671.0, "ollama": "deepseek-r1:671b", "hf": "deepseek-ai/DeepSeek-R1-0528", "ctx": 163840},
56
+ ]
57
+
58
+
59
+ def _configure_stdio():
60
+ for stream in (sys.stdout, sys.stderr):
61
+ if hasattr(stream, "reconfigure"):
62
+ try:
63
+ stream.reconfigure(encoding="utf-8", errors="replace")
64
+ except Exception:
65
+ pass
66
+
67
+
68
+ def detect_hardware():
69
+ """Detect local GPU VRAM (NVIDIA, Apple Silicon Unified Memory, or Windows GPU fallback)."""
70
+ # 1. Try nvidia-smi (Linux / Windows with NVIDIA driver)
71
+ try:
72
+ proc = subprocess.run(
73
+ ["nvidia-smi", "--query-gpu=name,memory.total", "--format=csv,noheader,nounits"],
74
+ capture_output=True,
75
+ text=True,
76
+ timeout=5,
77
+ )
78
+ if proc.returncode == 0 and proc.stdout.strip():
79
+ gpus = []
80
+ total_mb = 0.0
81
+ for line in proc.stdout.strip().splitlines():
82
+ parts = [p.strip() for p in line.split(",")]
83
+ if len(parts) >= 2:
84
+ try:
85
+ mb = float(parts[1])
86
+ gpus.append(f"{parts[0]} ({mb / 1024.0:.0f} GB)")
87
+ total_mb += mb
88
+ except ValueError:
89
+ continue
90
+ if total_mb > 0:
91
+ return round(total_mb / 1024.0, 1), f"NVIDIA GPU: {' + '.join(gpus)}", "nvidia-smi"
92
+ except (FileNotFoundError, subprocess.SubprocessError):
93
+ pass
94
+
95
+ # 2. Apple Silicon / macOS unified memory
96
+ if sys.platform == "darwin":
97
+ try:
98
+ mem_out = subprocess.check_output(["sysctl", "-n", "hw.memsize"], text=True, timeout=3).strip()
99
+ arch = platform.machine().lower()
100
+ total_gb = int(mem_out) / (1024 ** 3)
101
+ if "arm" in arch or "aarch64" in arch:
102
+ usable = round(total_gb * 0.75, 1)
103
+ return usable, f"Apple Silicon Unified Memory ({total_gb:.0f} GB RAM -> ~{usable} GB usable Metal VRAM)", "apple-sysctl"
104
+ return round(total_gb * 0.5, 1), f"macOS System Memory ({total_gb:.0f} GB RAM)", "mac-sysctl"
105
+ except Exception:
106
+ pass
107
+
108
+ # 3. Windows GPU fallback via PowerShell CIM + Registry qwMemorySize for >4GB GPUs
109
+ if sys.platform == "win32":
110
+ ps_cmd = (
111
+ "$gpus = Get-CimInstance Win32_VideoController | Select-Object Name,AdapterRAM; "
112
+ "$reg = Get-ItemProperty 'HKLM:\\SYSTEM\\ControlSet001\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\0*' "
113
+ "-ErrorAction SilentlyContinue | Select-Object DriverDesc,'HardwareInformation.qwMemorySize'; "
114
+ "@{gpus=@($gpus); reg=@($reg)} | ConvertTo-Json -Depth 3"
115
+ )
116
+ try:
117
+ proc = subprocess.run(
118
+ ["powershell", "-NoProfile", "-Command", ps_cmd],
119
+ capture_output=True,
120
+ text=True,
121
+ timeout=6,
122
+ )
123
+ if proc.returncode == 0 and proc.stdout.strip():
124
+ data = json.loads(proc.stdout)
125
+ best_bytes = 0
126
+ best_name = None
127
+ for r in data.get("reg") or []:
128
+ qw = r.get("HardwareInformation.qwMemorySize")
129
+ desc = r.get("DriverDesc")
130
+ if isinstance(qw, (int, float)) and qw > best_bytes:
131
+ best_bytes = qw
132
+ best_name = desc
133
+ if best_bytes == 0:
134
+ for g in data.get("gpus") or []:
135
+ ram = g.get("AdapterRAM")
136
+ name = g.get("Name")
137
+ if isinstance(ram, (int, float)) and ram > best_bytes:
138
+ best_bytes = ram
139
+ best_name = name
140
+ if best_bytes > 0 and best_name:
141
+ gb = round(best_bytes / (1024 ** 3), 1)
142
+ return gb, f"Windows GPU: {best_name} ({gb} GB detected)", "win32-cim"
143
+ except Exception:
144
+ pass
145
+
146
+ return 16.0, "Default fallback (16.0 GB assumed β€” pass --vram <GB> to specify yours)", "fallback"
147
+
148
+
149
+ def calc_vram(params_b, ctx):
150
+ kv_extra = max(0.0, (ctx - 8192) / 8192.0) * (params_b * 0.025)
151
+ fp16 = round((params_b * 2.2) + (kv_extra * 2.0), 1)
152
+ q8 = round((params_b * 1.15) + (kv_extra * 1.2), 1)
153
+ q4 = round((params_b * 0.65) + kv_extra, 1)
154
+ return fp16, q8, q4
155
+
156
+
157
+ def _estimate_params_b(model_id, name):
158
+ combined = f"{model_id} {name}".lower()
159
+ m_moe = re.search(r"\b(\d+)x(\d+(?:\.\d+)?)b\b", combined)
160
+ if m_moe:
161
+ return round(float(m_moe.group(1)) * float(m_moe.group(2)) * 0.8, 1)
162
+ m_tril = re.search(r"\b(\d+(?:\.\d+)?)t\b", combined)
163
+ if m_tril:
164
+ val_t = float(m_tril.group(1))
165
+ if 0.5 <= val_t <= 10:
166
+ return round(val_t * 1000.0, 1)
167
+ m_bil = re.search(r"(?<![a-z0-9])(\d+(?:\.\d+)?)b\b", combined)
168
+ if m_bil:
169
+ val = float(m_bil.group(1))
170
+ if 0.5 <= val <= 2000:
171
+ return val
172
+ if "deepseek" in combined:
173
+ if re.search(r"\b(flash|lite|mini|nano|small)\b", combined):
174
+ return 14.0
175
+ if any(k in combined for k in ["v3", "r1", "chat", "reasoner", "prover", "v4"]):
176
+ return 671.0
177
+ if "phi-4" in combined or "phi-3" in combined:
178
+ return 3.8 if re.search(r"\b(mini|small|multimodal)\b", combined) else 14.0
179
+ if "llama-4-maverick" in combined:
180
+ return 400.0
181
+ if "llama-4-scout" in combined:
182
+ return 109.0
183
+ if "mistral-large" in combined or "pixtral-large" in combined:
184
+ return 123.0
185
+ if any(k in combined for k in ["mistral-small", "devstral", "voxtral-small"]):
186
+ return 24.0
187
+ if "codestral" in combined:
188
+ return 22.0
189
+ if "mistral-nemo" in combined or "mistral-saba" in combined:
190
+ return 12.0
191
+ if "command-a" in combined:
192
+ return 111.0
193
+ if "command-r-plus" in combined:
194
+ return 104.0
195
+ if "command-r" in combined:
196
+ return 35.0
197
+ if "kimi-k2" in combined:
198
+ return 1000.0
199
+ if "glm-4.5-air" in combined:
200
+ return 106.0
201
+ if "glm-4.5" in combined or "glm-5" in combined:
202
+ return 355.0
203
+ return 32.0
204
+
205
+
206
+ def _is_open_weight(model_id, name):
207
+ mid = model_id.lower().lstrip("~")
208
+ combined = f"{mid} {name.lower()}"
209
+ if any(k in mid for k in [":batch", "-image", "-audio", "-realtime"]):
210
+ return False
211
+ if "gpt-oss" in mid:
212
+ return True
213
+ if mid.startswith(("openai/", "anthropic/", "x-ai/", "amazon/", "perplexity/", "ai21/", "inflection/", "openrouter/")):
214
+ return False
215
+ if mid.startswith("google/"):
216
+ return "gemma" in mid
217
+ if mid.startswith("meta/"):
218
+ return "open" in mid or "30b" in mid or "llama" in mid
219
+ if mid.startswith("meta-llama/"):
220
+ return True
221
+ if mid.startswith("qwen/"):
222
+ if re.search(r"\b\d+(?:\.\d+)?[bt]\b", combined) or "qwq" in mid or "qwen-2.5" in mid or "qwen2.5" in mid:
223
+ return True
224
+ if any(k in mid for k in ["max", "plus", "turbo", "flash"]):
225
+ return False
226
+ return True
227
+ if mid.startswith("mistralai/"):
228
+ return "mistral-medium" not in mid
229
+ if mid.startswith("deepseek/"):
230
+ return not (model_id.startswith("~") or "flash" in mid or "v4-pro" in mid or "pro-latest" in mid)
231
+ if mid.startswith((
232
+ "microsoft/phi", "microsoft/wizard", "nvidia/", "nousresearch/",
233
+ "cognitivecomputations/", "sao10k/", "thedrummer/", "gryphe/",
234
+ "allenai/", "ibm-granite/", "liquid/", "01-ai/", "moonshotai/kimi",
235
+ "z-ai/glm", "thudm/glm", "cohere/command-r", "cohere/command-a"
236
+ )):
237
+ return True
238
+ return bool(re.search(r"\b\d+(?:\.\d+)?b\b", combined))
239
+
240
+
241
+ def _infer_commands(model_id, name, params_b):
242
+ mid = model_id.lower()
243
+ # Map common OpenRouter IDs cleanly to Ollama tags & HF repos
244
+ if mid.startswith("meta-llama/"):
245
+ if "llama-4-maverick" in mid:
246
+ return "llama4:maverick", "meta-llama/Llama-4-Maverick-17B-128E-Instruct"
247
+ if "llama-4-scout" in mid:
248
+ return "llama4:scout", "meta-llama/Llama-4-Scout-17B-16E-Instruct"
249
+ m = re.search(r"llama-(\d+(?:\.\d+)?)-(\d+b)", mid)
250
+ if m:
251
+ ver, size = m.group(1), m.group(2)
252
+ return f"llama{ver}:{size}", f"meta-llama/Llama-{ver}-{size.upper()}-Instruct"
253
+ if mid.startswith("qwen/"):
254
+ if "coder" in mid and "32b" in mid:
255
+ return "qwen2.5-coder:32b", "Qwen/Qwen2.5-Coder-32B-Instruct"
256
+ if "2.5" in mid and "72b" in mid:
257
+ return "qwen2.5:72b", "Qwen/Qwen2.5-72B-Instruct"
258
+ m = re.search(r"qwen(\d+(?:\.\d+)?)-(\d+b)(?:-(a\d+b))?", mid)
259
+ if m:
260
+ ver, size, act = m.group(1), m.group(2), m.group(3)
261
+ tag = f"qwen{ver}:{size}" + (f"-{act}" if act else "")
262
+ hf = f"Qwen/Qwen{ver}-{size.upper()}" + (f"-{act.upper()}" if act else "")
263
+ return tag, hf
264
+ if mid.startswith("deepseek/"):
265
+ if "r1" in mid:
266
+ return f"deepseek-r1:{int(params_b)}b", "deepseek-ai/DeepSeek-R1-0528"
267
+ if "chat" in mid or "v3" in mid:
268
+ return "deepseek-v3:671b", "deepseek-ai/DeepSeek-V3"
269
+ if mid.startswith("google/gemma"):
270
+ m = re.search(r"gemma-(\d+)-(\d+b)", mid)
271
+ if m:
272
+ return f"gemma{m.group(1)}:{m.group(2)}", f"google/gemma-{m.group(1)}-{m.group(2)}-it"
273
+ if mid.startswith("microsoft/phi-4"):
274
+ return "phi4:14b", "microsoft/phi-4"
275
+ if mid.startswith("openai/gpt-oss-"):
276
+ m = re.search(r"gpt-oss-(\d+b)", mid)
277
+ if m:
278
+ return f"gpt-oss:{m.group(1)}", f"openai/gpt-oss-{m.group(1)}"
279
+ if mid.startswith("mistralai/"):
280
+ if "codestral" in mid:
281
+ return "codestral:22b", "mistralai/Codestral-22B-v0.1"
282
+ if "mistral-small" in mid:
283
+ return "mistral-small3.2:24b", "mistralai/Mistral-Small-3.2-24B-Instruct-2506"
284
+ if "mistral-large" in mid:
285
+ return "mistral-large:123b", "mistralai/Mistral-Large-Instruct-2411"
286
+ if "mixtral-8x22b" in mid:
287
+ return "mixtral:8x22b", "mistralai/Mixtral-8x22B-Instruct-v0.1"
288
+ slug_tail = model_id.split("/")[-1]
289
+ return slug_tail, model_id
290
+
291
+
292
+ def fetch_live_open_models():
293
+ url = "https://openrouter.ai/api/v1/models"
294
+ req = urllib.request.Request(url, headers={"User-Agent": f"TokenBench-CLI/{__version__}"})
295
+ with urllib.request.urlopen(req, timeout=15) as resp:
296
+ raw = json.loads(resp.read().decode("utf-8"))
297
+ results = []
298
+ seen = set()
299
+ for item in raw.get("data", []):
300
+ mid = item.get("id", "")
301
+ name = item.get("name", mid).lstrip("~").strip()
302
+ if not mid or mid in seen or mid.startswith("~"):
303
+ continue
304
+ if not _is_open_weight(mid, name):
305
+ continue
306
+ pricing = item.get("pricing") or {}
307
+ try:
308
+ in_1m = round(float(pricing.get("prompt", 0) or 0) * 1_000_000, 4)
309
+ out_1m = round(float(pricing.get("completion", 0) or 0) * 1_000_000, 4)
310
+ except (ValueError, TypeError):
311
+ in_1m, out_1m = 0.0, 0.0
312
+ if in_1m == 0 and out_1m == 0 and ":free" not in mid:
313
+ continue
314
+ seen.add(mid)
315
+ params_b = _estimate_params_b(mid, name)
316
+ ollama_tag, hf_repo = _infer_commands(mid, name, params_b)
317
+ results.append({
318
+ "id": mid,
319
+ "name": name,
320
+ "params_b": params_b,
321
+ "ollama": ollama_tag,
322
+ "hf": hf_repo,
323
+ "ctx": int(item.get("context_length") or 32768),
324
+ "in_1m": in_1m,
325
+ "out_1m": out_1m,
326
+ })
327
+ results.sort(key=lambda x: (x["params_b"], x["name"]))
328
+ return results
329
+
330
+
331
+ def evaluate_models(models, vram_gb, ctx, search_term=""):
332
+ q = search_term.lower().strip()
333
+ evaluated = []
334
+ for m in models:
335
+ if q and q not in m["name"].lower() and q not in m.get("id", "").lower() and q not in m["ollama"].lower():
336
+ continue
337
+ fp16, q8, q4 = calc_vram(m["params_b"], ctx)
338
+ if vram_gb >= fp16:
339
+ status = "FP16"
340
+ badge = "βœ… FP16"
341
+ elif vram_gb >= q8:
342
+ status = "Q8_0"
343
+ badge = "🟒 Q8_0"
344
+ elif vram_gb >= q4:
345
+ status = "Q4_K_M"
346
+ badge = "⚑ Q4_K_M"
347
+ else:
348
+ status = "CLOUD"
349
+ badge = "☁️ Cloud GPU"
350
+
351
+ tp = 1 if q4 <= 75 else (2 if q4 <= 155 else (4 if q4 <= 310 else 8))
352
+ ollama_cmd = f"ollama run {m['ollama']}"
353
+ vllm_cmd = f"vllm serve {m['hf']} --max-model-len {min(ctx, m.get('ctx', ctx))} --tensor-parallel-size {tp}"
354
+ evaluated.append({
355
+ **m,
356
+ "vram_fp16": fp16,
357
+ "vram_q8": q8,
358
+ "vram_q4": q4,
359
+ "status": status,
360
+ "badge": badge,
361
+ "ollama_cmd": ollama_cmd,
362
+ "vllm_cmd": vllm_cmd,
363
+ })
364
+ return evaluated
365
+
366
+
367
+ def main():
368
+ _configure_stdio()
369
+ parser = argparse.ArgumentParser(
370
+ prog="tokenbench",
371
+ description="Detect local GPU VRAM and check which open-weight LLMs fit in FP16 / Q8 / Q4.",
372
+ )
373
+ parser.add_argument("--vram", type=float, default=None, help="Override detected VRAM in GB (e.g. --vram 24)")
374
+ parser.add_argument("--ctx", type=int, default=8192, help="Context window tokens for KV cache sizing (default: 8192)")
375
+ parser.add_argument("--search", type=str, default="", help="Filter models by name/family (e.g. qwen, llama, deepseek)")
376
+ parser.add_argument("--live", action="store_true", help="Fetch live 130+ open-weight models from OpenRouter API")
377
+ parser.add_argument("--json", action="store_true", help="Output JSON instead of formatted table")
378
+ parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
379
+ args = parser.parse_args()
380
+
381
+ detected_vram, hw_desc, source = detect_hardware()
382
+ vram_gb = float(args.vram) if args.vram is not None else detected_vram
383
+ if args.vram is not None:
384
+ hw_desc = f"Manual Override ({vram_gb:g} GB VRAM) [detected: {hw_desc}]"
385
+
386
+ models = CURATED_OPEN_MODELS
387
+ data_source = "curated"
388
+ if args.live:
389
+ try:
390
+ models = fetch_live_open_models()
391
+ data_source = "openrouter-live"
392
+ except Exception as e:
393
+ if not args.json:
394
+ print(f"[note] Live fetch failed ({e}); using built-in model catalog.", file=sys.stderr)
395
+
396
+ results = evaluate_models(models, vram_gb, args.ctx, args.search)
397
+
398
+ if args.json:
399
+ print(json.dumps({
400
+ "vram_gb": vram_gb,
401
+ "hardware": hw_desc,
402
+ "detection_source": source,
403
+ "context_tokens": args.ctx,
404
+ "catalog_source": data_source,
405
+ "models": results,
406
+ }, indent=2))
407
+ return 0
408
+
409
+ print("")
410
+ print("⚑ TokenBench Local GPU & LLM Compatibility Checker")
411
+ print("=" * 78)
412
+ print(f" Hardware : {hw_desc}")
413
+ print(f" Usable : {vram_gb:g} GB VRAM | Context: {args.ctx:,} tokens | Catalog: {data_source}")
414
+ print("=" * 78)
415
+ print("")
416
+ print(f"{'Model':<29} {'Params':>7} {'Q4':>8} {'Q8':>8} {'FP16':>8} {'Fit':<12} {'Run Command'}")
417
+ print("-" * 78)
418
+
419
+ fit_count = 0
420
+ for r in results:
421
+ if r["status"] != "CLOUD":
422
+ fit_count += 1
423
+ cmd = r["ollama_cmd"]
424
+ else:
425
+ cmd = f"Need >= {r['vram_q4']} GB (Cloud GPU)"
426
+ print(
427
+ f"{r['name'][:28]:<29} "
428
+ f"{r['params_b']:>6g}B "
429
+ f"{r['vram_q4']:>6.1f}G "
430
+ f"{r['vram_q8']:>6.1f}G "
431
+ f"{r['vram_fp16']:>6.1f}G "
432
+ f"{r['badge']:<12} {cmd}"
433
+ )
434
+
435
+ runnable = [r for r in results if r["status"] != "CLOUD"]
436
+ if runnable:
437
+ preferred = [r for r in runnable if not any(k in r["name"].lower() for k in ("guard", "safeguard"))]
438
+ top = (preferred or runnable)[-1]
439
+ print("")
440
+ print(f"πŸ’‘ Best local pick for {vram_gb:g} GB VRAM: {top['name']} ({top['badge']})")
441
+ print(f" Ollama : {top['ollama_cmd']}")
442
+ print(f" vLLM : {top['vllm_cmd']}")
443
+
444
+ print("")
445
+ print(f"Summary: {fit_count}/{len(results)} models fit locally on {vram_gb:g} GB VRAM @ {args.ctx:,} context.")
446
+ print(f"πŸ“Š Full API Cost & Electricity Break-Even: {SITE_BASE_URL}/vram-electricity-calculator.html")
447
+ print(f"πŸš€ Batch Simulator (440+ Models): {SITE_BASE_URL}/")
448
+ print("")
449
+ return 0
450
+
451
+
452
+ if __name__ == "__main__":
453
+ raise SystemExit(main())