vahana 1.0.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.
Files changed (96) hide show
  1. vahana-1.0.0/LICENSE +202 -0
  2. vahana-1.0.0/NOTICE +4 -0
  3. vahana-1.0.0/PKG-INFO +144 -0
  4. vahana-1.0.0/README.md +108 -0
  5. vahana-1.0.0/pyproject.toml +58 -0
  6. vahana-1.0.0/setup.cfg +4 -0
  7. vahana-1.0.0/setup.py +45 -0
  8. vahana-1.0.0/src/vahana/__init__.py +86 -0
  9. vahana-1.0.0/src/vahana/_kernel.py +341 -0
  10. vahana-1.0.0/src/vahana/_triton.py +58 -0
  11. vahana-1.0.0/src/vahana/ansplane.py +314 -0
  12. vahana-1.0.0/src/vahana/attention.py +184 -0
  13. vahana-1.0.0/src/vahana/batch.py +89 -0
  14. vahana-1.0.0/src/vahana/cache.py +293 -0
  15. vahana-1.0.0/src/vahana/cli.py +162 -0
  16. vahana-1.0.0/src/vahana/colprofile.py +91 -0
  17. vahana-1.0.0/src/vahana/colres.py +493 -0
  18. vahana-1.0.0/src/vahana/columns.py +62 -0
  19. vahana-1.0.0/src/vahana/cpu_moe_block.py +186 -0
  20. vahana-1.0.0/src/vahana/csrc/build.py +73 -0
  21. vahana-1.0.0/src/vahana/csrc/build_kernel.sh +10 -0
  22. vahana-1.0.0/src/vahana/csrc/cpu_moe.cpp +1659 -0
  23. vahana-1.0.0/src/vahana/csrc/pool.h +224 -0
  24. vahana-1.0.0/src/vahana/csrc/vt.h +138 -0
  25. vahana-1.0.0/src/vahana/decode.py +195 -0
  26. vahana-1.0.0/src/vahana/directory.py +96 -0
  27. vahana-1.0.0/src/vahana/doctor.py +257 -0
  28. vahana-1.0.0/src/vahana/dynamic_cache.py +654 -0
  29. vahana-1.0.0/src/vahana/engine.py +558 -0
  30. vahana-1.0.0/src/vahana/experts.py +146 -0
  31. vahana-1.0.0/src/vahana/feasibility.py +171 -0
  32. vahana-1.0.0/src/vahana/fused.py +124 -0
  33. vahana-1.0.0/src/vahana/golden_tiny.json +28 -0
  34. vahana-1.0.0/src/vahana/groupcol.py +173 -0
  35. vahana-1.0.0/src/vahana/grouped.py +304 -0
  36. vahana-1.0.0/src/vahana/hook.py +435 -0
  37. vahana-1.0.0/src/vahana/hostreg.py +260 -0
  38. vahana-1.0.0/src/vahana/hwprobe.py +130 -0
  39. vahana-1.0.0/src/vahana/hybrid.py +301 -0
  40. vahana-1.0.0/src/vahana/inspector.py +118 -0
  41. vahana-1.0.0/src/vahana/interface.py +228 -0
  42. vahana-1.0.0/src/vahana/introspect.py +581 -0
  43. vahana-1.0.0/src/vahana/invariant.py +267 -0
  44. vahana-1.0.0/src/vahana/loader.py +388 -0
  45. vahana-1.0.0/src/vahana/loading.py +295 -0
  46. vahana-1.0.0/src/vahana/matrix.py +169 -0
  47. vahana-1.0.0/src/vahana/mla_cache.py +291 -0
  48. vahana-1.0.0/src/vahana/modelspec.py +108 -0
  49. vahana-1.0.0/src/vahana/offload.py +305 -0
  50. vahana-1.0.0/src/vahana/osl.py +67 -0
  51. vahana-1.0.0/src/vahana/placement.py +953 -0
  52. vahana-1.0.0/src/vahana/predictor.py +150 -0
  53. vahana-1.0.0/src/vahana/refill.py +175 -0
  54. vahana-1.0.0/src/vahana/remote.py +315 -0
  55. vahana-1.0.0/src/vahana/rowsplit.py +64 -0
  56. vahana-1.0.0/src/vahana/runinfo.py +74 -0
  57. vahana-1.0.0/src/vahana/runtime.py +276 -0
  58. vahana-1.0.0/src/vahana/sa_ffn.py +69 -0
  59. vahana-1.0.0/src/vahana/saffn.py +120 -0
  60. vahana-1.0.0/src/vahana/selftest.py +144 -0
  61. vahana-1.0.0/src/vahana/serve.py +700 -0
  62. vahana-1.0.0/src/vahana/server.py +230 -0
  63. vahana-1.0.0/src/vahana/spec.py +149 -0
  64. vahana-1.0.0/src/vahana/speculative.py +182 -0
  65. vahana-1.0.0/src/vahana/timing.py +86 -0
  66. vahana-1.0.0/src/vahana/tmath.py +861 -0
  67. vahana-1.0.0/src/vahana/twin_act.py +83 -0
  68. vahana-1.0.0/src/vahana/twinlin.py +303 -0
  69. vahana-1.0.0/src/vahana.egg-info/PKG-INFO +144 -0
  70. vahana-1.0.0/src/vahana.egg-info/SOURCES.txt +94 -0
  71. vahana-1.0.0/src/vahana.egg-info/dependency_links.txt +1 -0
  72. vahana-1.0.0/src/vahana.egg-info/entry_points.txt +2 -0
  73. vahana-1.0.0/src/vahana.egg-info/requires.txt +16 -0
  74. vahana-1.0.0/src/vahana.egg-info/top_level.txt +1 -0
  75. vahana-1.0.0/tests/test_attention.py +43 -0
  76. vahana-1.0.0/tests/test_colres.py +237 -0
  77. vahana-1.0.0/tests/test_doctor.py +28 -0
  78. vahana-1.0.0/tests/test_dtypes.py +19 -0
  79. vahana-1.0.0/tests/test_feasibility.py +83 -0
  80. vahana-1.0.0/tests/test_groupcol.py +82 -0
  81. vahana-1.0.0/tests/test_grouped.py +174 -0
  82. vahana-1.0.0/tests/test_hostreg_select.py +51 -0
  83. vahana-1.0.0/tests/test_inspector.py +95 -0
  84. vahana-1.0.0/tests/test_interface.py +258 -0
  85. vahana-1.0.0/tests/test_loading.py +145 -0
  86. vahana-1.0.0/tests/test_matrix.py +94 -0
  87. vahana-1.0.0/tests/test_measurement.py +64 -0
  88. vahana-1.0.0/tests/test_mla_cache.py +138 -0
  89. vahana-1.0.0/tests/test_modelspec.py +80 -0
  90. vahana-1.0.0/tests/test_placement.py +264 -0
  91. vahana-1.0.0/tests/test_plan.py +79 -0
  92. vahana-1.0.0/tests/test_remote.py +208 -0
  93. vahana-1.0.0/tests/test_rowsplit.py +47 -0
  94. vahana-1.0.0/tests/test_serve.py +240 -0
  95. vahana-1.0.0/tests/test_shardmap_alignment.py +47 -0
  96. vahana-1.0.0/tests/test_twin.py +88 -0
vahana-1.0.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
vahana-1.0.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Vahana
2
+ Copyright 2026 Aditya Sai Teja B
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
vahana-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: vahana
3
+ Version: 1.0.0
4
+ Summary: Exact, bit-reproducible inference and serving for Mixture-of-Experts models too big for your GPU
5
+ Author: Aditya Sai Teja B
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/vahana-ai/Vahana
8
+ Project-URL: Source, https://github.com/vahana-ai/Vahana
9
+ Project-URL: Changelog, https://github.com/vahana-ai/Vahana/blob/main/CHANGELOG.md
10
+ Keywords: llm,inference,mixture-of-experts,moe,deterministic,reproducible,serving
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: C++
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Intended Audience :: Science/Research
19
+ Classifier: Intended Audience :: Developers
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ Requires-Dist: torch>=2.4
26
+ Requires-Dist: transformers<5.14,>=5.12
27
+ Requires-Dist: accelerate>=1.0
28
+ Requires-Dist: safetensors>=0.4
29
+ Requires-Dist: numpy>=1.24
30
+ Provides-Extra: gpu
31
+ Requires-Dist: triton>=3.0; platform_system == "Linux" and extra == "gpu"
32
+ Requires-Dist: triton-windows>=3.2; platform_system == "Windows" and extra == "gpu"
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest>=8; extra == "test"
35
+ Dynamic: license-file
36
+
37
+ # Vahana
38
+
39
+ **Exact inference and serving for Mixture-of-Experts models too big for your GPU.**
40
+
41
+ Vahana (Sanskrit: *carrier*) runs Mixture-of-Experts language models on the hardware you have, from an H100 server down to a laptop with a 4 GB GPU:
42
+ - the GPU runs attention, routing and everything else, plus a cache of the most-used experts;
43
+ - the remaining experts run on an exact CPU kernel, from RAM or streamed from disk when they do not fit.
44
+
45
+ Its answers are **bit-identical** wherever and however the work runs. The same tokens and the same logits come out regardless of:
46
+ - **the machine:** a CPU-only laptop and an H100 agree bit for bit, on Linux, Windows and macOS, on AVX-512, AVX2, ARM NEON or plain C;
47
+ - **where the weights live:** GPU, GPU expert cache, RAM, or disk;
48
+ - **what else is running:** batching, continuous batching in the server, padding, speculative decoding, or prefill vs decode.
49
+
50
+ Other engines change a request's output when the batch around it changes. In Vahana, a request served alongside 63 others gives exactly the bits it gives alone, and that is measured, not assumed ([benchmarks](docs/benchmarks.md)).
51
+
52
+ > **Status: 1.0 (beta).** The exactness guarantee is stable and validated on real checkpoints up to DeepSeek-V2 236B, with 18 model families in the selftest. Expect rough edges outside the tested setups below; please open an issue.
53
+ > Every claim here comes from a pre-registered experiment in [`experiments/`](experiments), including the bars it missed.
54
+ > See the [changelog](CHANGELOG.md).
55
+
56
+ ## Quick start
57
+ ```bash
58
+ pip install torch # the build for your machine (CUDA or CPU), from pytorch.org
59
+ pip install "vahana[gpu]" # [gpu] adds Triton for NVIDIA GPUs (triton-windows on Windows); omit it for CPU-only
60
+ vahana selftest # does this machine give the reference bits? (18 tiny models, about a minute)
61
+ vahana doctor /models/Qwen3-30B-A3B # what this machine runs, where the weights go; add --measure to time it
62
+
63
+ vahana run /models/Qwen3-30B-A3B --prompt "Explain mixture-of-experts in one paragraph." --chat
64
+ vahana serve /models/Qwen3-30B-A3B --slots 32 --port 8000 # OpenAI-compatible, continuous batching
65
+ vahana run /models/OLMoE-1B-7B-0924 --device cpu --prompt "Hello" # no GPU: the same tokens, slower
66
+ ```
67
+ From source: `pip install -e .` then `python src/vahana/csrc/build.py` (needs a C++20 compiler; no torch headers).
68
+
69
+ ```python
70
+ import vahana
71
+ model, info = vahana.load("/models/Qwen3-30B-A3B", gpu_cache_gb="auto") # or gpu_budget_gb=4, device="cpu"
72
+ out = vahana.generate(model, input_ids, max_new_tokens=128) # greedy; ids, logits, per-step timings
73
+ batch = vahana.generate_batch(model, [ids_a, ids_b, ids_c], 64) # each row == its solo run, bit for bit
74
+ spec = vahana.generate_spec(model, input_ids, 64, k=4) # exact speculative decoding
75
+ ```
76
+ The server speaks the OpenAI API:
77
+ - `GET /health`, `GET /v1/models`;
78
+ - `POST /v1/completions` and `POST /v1/chat/completions`, with `stream`, `max_tokens`, `temperature`, `top_p`, `seed` and `stop`.
79
+
80
+ Concurrent requests share decode steps (continuous batching), and every response equals the same request run alone. Greedy decoding is bit-exact. Sampling is reproducible: tokens are drawn on the host from fp32 logits with a generator seeded by `seed`.
81
+
82
+ ## Results
83
+ Full tables, the machines used, and the misses are in **[docs/benchmarks.md](docs/benchmarks.md)**. Highlights (H100 NVL server, and a laptop with an RTX 3050 Ti 4 GB and 15 GB of RAM):
84
+
85
+ | | Result |
86
+ |---|---|
87
+ | DeepSeek-Coder-V2 236B (438 GB), 16 GB GPU budget | 7.49 tok/s |
88
+ | Qwen3-30B-A3B served to 64 requests at once (18 GB of experts on the GPU, the rest on the CPU) | 130 tok/s aggregate, every request bit-identical to running alone |
89
+ | OLMoE-1B-7B, 64 requests at once | 1,016 tok/s aggregate |
90
+ | Continuous batching (128 requests, 32 slots) | the throughput of a static batch, 7.4× one at a time |
91
+ | Qwen3.5-35B-A3B (Gated DeltaNet hybrid), batched | 4.35× one at a time, bit-identical |
92
+ | Qwen3-30B (57 GB) on the 15 GB laptop, streamed from NVMe | about 1 tok/s, the H100's logits bit for bit |
93
+ | Cost of exactness | +1.8% per GPU decode step |
94
+
95
+ ## Supported models
96
+ Vahana finds the experts by structure (transformers' `experts(hidden, indices, weights)` modules) instead of hard-coding families, and fails loudly on anything it does not recognise.
97
+
98
+ | Status | Families |
99
+ |---|---|
100
+ | **Real checkpoints validated** (exact + quality) | Mixtral, DeepSeek-V2 (Lite and 236B), Qwen1.5-MoE (Qwen2-MoE), Qwen3-MoE, OLMoE |
101
+ | **Validated on the real architecture, tiny random weights** (exact, batch-invariant, graph decode) | DeepSeek-V3, GLM-4-MoE (+Lite), MiniMax-M2, Hunyuan-MoE, Ernie-4.5-MoE, Cohere2-MoE, Exaone-MoE, AFMoE, gpt-oss (BF16 experts) |
102
+ | **Real checkpoint validated, eager decode** | Qwen3.5-MoE (Gated DeltaNet; Qwen3.5-35B-A3B batched and served exactly) |
103
+ | **Exact, eager decode only** (tiny random weights) | MiniMax (lightning attention), Phi-MoE (host-side RoPE) |
104
+ | **Not yet** | gpt-oss MXFP4 checkpoints, FP8 checkpoints (DeepSeek-V3/R1), Llama 4, Granite-MoE, JetMoE, DBRX, encoder-decoder MoE |
105
+
106
+ ## How it is exact
107
+ - **Twin arithmetic.** CPU and GPU kernels evaluate every dot product in the same order (16 fp32 FMA lanes, a fixed reduction tree) with the same BF16 rounding points. An expert or linear layer gives the same bits on either device.
108
+ - **Batch-invariant kernels.** The `vahana` attention function and the linear and norm kernels reduce each row in a fixed order that depends only on that row. Batch neighbours, padding and prefill-vs-decode cannot change it.
109
+ - **NX12.** A lossless 12-bit encoding of BF16 expert weights (75% of the size) that the CPU kernel decodes at memory bandwidth.
110
+ - **One CUDA graph per decode step,** with the CPU jobs reached through a GPU↔CPU mailbox, for any model.
111
+ - **Batching without changing bits.** Every kernel computes each row on its own, and attention is anchored at each query's first key, so batch neighbours and padding never move a rounding. The continuous-batching engine only copies KV; recurrent layers never see padding.
112
+ - **Twin arithmetic for everything else (v0.2 P2).**
113
+ - Attention has a CPU twin of the GPU kernel: the same blocks, Vahana's own `exp` and fixed reduction trees.
114
+ - Every remaining operation is written only in IEEE-exact steps: norms, rotary embeddings, router softmax and top-k, activations, small matmuls.
115
+ - Two notable cases:
116
+ - PyTorch's CUDA `sqrt` is not correctly rounded, so Vahana's sqrt is.
117
+ - CUDA divides by a scalar via its reciprocal, so Vahana divides by a device tensor.
118
+ - **Result:** the whole model gives the same bits on any CPU or GPU.
119
+ - **Cost:** +1.8% per GPU decode step.
120
+
121
+ ## Requirements and limits
122
+ - **Python 3.10+, PyTorch 2.4+, transformers 5.12–5.13.** Vahana runs transformers' own model code, and later releases changed some models' definitions (Qwen3.5-MoE from 5.14, gpt-oss from 5.19), which moves their outputs off the selftest reference. CI's `compat` job tracks every release; the range widens as versions are validated. NVIDIA GPUs need Triton (`vahana[gpu]`). CPU-only works everywhere.
123
+ - **RAM:**
124
+ - **Fast:** room for the experts, plus page cache.
125
+ - **Less RAM still works, exactly:** experts stream from disk at disk speed. A saturated NVMe caps decode; for example Qwen3-30B on a 15 GB laptop runs at about 1 tok/s.
126
+ - **One NVIDIA GPU, or none.** Multi-GPU is not supported.
127
+ - **CPU:** x86-64 (AVX-512 fastest, AVX2, or plain) and ARM64 (NEON). Wheels: Linux x86-64 / arm64, Windows x86-64, macOS arm64. CI runs the selftest on each, under every instruction set.
128
+ - **Checkpoints:** BF16. FP8 and MXFP4 checkpoints are not yet supported.
129
+ - **Hybrid linear-attention models** decode eagerly (no CUDA graph).
130
+ - **Speculative decoding is exact but rarely faster for batch-1 MoE:** each drafted token routes to new experts ([why](docs/benchmarks.md#what-did-not-work)).
131
+ - **Prefill on very large models is slow** when many linears sit in CPU RAM: 38 s for a 236B prompt.
132
+
133
+ ## Layout
134
+ - **Engine:** `src/vahana/`:
135
+ - `loader`, `modelspec`, `experts`, `runtime` (GPU↔CPU mailbox), `cache` (GPU expert cache);
136
+ - `attention`, `twinlin`, `fused`, `tmath` (twin arithmetic);
137
+ - `decode`, `batch`, `speculative`, `engine` (continuous batching);
138
+ - `server`, `cli`, `doctor`, `selftest`.
139
+ - **CPU kernel:** `src/vahana/csrc/`: `cpu_moe.cpp`, `vt.h`, `pool.h`, `build.py`. A plain shared library with a C ABI, loaded through `_kernel.py`. `osl.py` holds the OS-specific calls.
140
+ - **Earlier research modules** (column tiers, ANS plane, tiered serving) are kept for reference and are not on the default path.
141
+ - **Design:** `docs/design/`. **Evidence:** `experiments/` (M0–M5, P1–P4, v0.3-a … v0.5).
142
+
143
+ ## License
144
+ Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Copyright 2026 Aditya Sai Teja B.
vahana-1.0.0/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # Vahana
2
+
3
+ **Exact inference and serving for Mixture-of-Experts models too big for your GPU.**
4
+
5
+ Vahana (Sanskrit: *carrier*) runs Mixture-of-Experts language models on the hardware you have, from an H100 server down to a laptop with a 4 GB GPU:
6
+ - the GPU runs attention, routing and everything else, plus a cache of the most-used experts;
7
+ - the remaining experts run on an exact CPU kernel, from RAM or streamed from disk when they do not fit.
8
+
9
+ Its answers are **bit-identical** wherever and however the work runs. The same tokens and the same logits come out regardless of:
10
+ - **the machine:** a CPU-only laptop and an H100 agree bit for bit, on Linux, Windows and macOS, on AVX-512, AVX2, ARM NEON or plain C;
11
+ - **where the weights live:** GPU, GPU expert cache, RAM, or disk;
12
+ - **what else is running:** batching, continuous batching in the server, padding, speculative decoding, or prefill vs decode.
13
+
14
+ Other engines change a request's output when the batch around it changes. In Vahana, a request served alongside 63 others gives exactly the bits it gives alone, and that is measured, not assumed ([benchmarks](docs/benchmarks.md)).
15
+
16
+ > **Status: 1.0 (beta).** The exactness guarantee is stable and validated on real checkpoints up to DeepSeek-V2 236B, with 18 model families in the selftest. Expect rough edges outside the tested setups below; please open an issue.
17
+ > Every claim here comes from a pre-registered experiment in [`experiments/`](experiments), including the bars it missed.
18
+ > See the [changelog](CHANGELOG.md).
19
+
20
+ ## Quick start
21
+ ```bash
22
+ pip install torch # the build for your machine (CUDA or CPU), from pytorch.org
23
+ pip install "vahana[gpu]" # [gpu] adds Triton for NVIDIA GPUs (triton-windows on Windows); omit it for CPU-only
24
+ vahana selftest # does this machine give the reference bits? (18 tiny models, about a minute)
25
+ vahana doctor /models/Qwen3-30B-A3B # what this machine runs, where the weights go; add --measure to time it
26
+
27
+ vahana run /models/Qwen3-30B-A3B --prompt "Explain mixture-of-experts in one paragraph." --chat
28
+ vahana serve /models/Qwen3-30B-A3B --slots 32 --port 8000 # OpenAI-compatible, continuous batching
29
+ vahana run /models/OLMoE-1B-7B-0924 --device cpu --prompt "Hello" # no GPU: the same tokens, slower
30
+ ```
31
+ From source: `pip install -e .` then `python src/vahana/csrc/build.py` (needs a C++20 compiler; no torch headers).
32
+
33
+ ```python
34
+ import vahana
35
+ model, info = vahana.load("/models/Qwen3-30B-A3B", gpu_cache_gb="auto") # or gpu_budget_gb=4, device="cpu"
36
+ out = vahana.generate(model, input_ids, max_new_tokens=128) # greedy; ids, logits, per-step timings
37
+ batch = vahana.generate_batch(model, [ids_a, ids_b, ids_c], 64) # each row == its solo run, bit for bit
38
+ spec = vahana.generate_spec(model, input_ids, 64, k=4) # exact speculative decoding
39
+ ```
40
+ The server speaks the OpenAI API:
41
+ - `GET /health`, `GET /v1/models`;
42
+ - `POST /v1/completions` and `POST /v1/chat/completions`, with `stream`, `max_tokens`, `temperature`, `top_p`, `seed` and `stop`.
43
+
44
+ Concurrent requests share decode steps (continuous batching), and every response equals the same request run alone. Greedy decoding is bit-exact. Sampling is reproducible: tokens are drawn on the host from fp32 logits with a generator seeded by `seed`.
45
+
46
+ ## Results
47
+ Full tables, the machines used, and the misses are in **[docs/benchmarks.md](docs/benchmarks.md)**. Highlights (H100 NVL server, and a laptop with an RTX 3050 Ti 4 GB and 15 GB of RAM):
48
+
49
+ | | Result |
50
+ |---|---|
51
+ | DeepSeek-Coder-V2 236B (438 GB), 16 GB GPU budget | 7.49 tok/s |
52
+ | Qwen3-30B-A3B served to 64 requests at once (18 GB of experts on the GPU, the rest on the CPU) | 130 tok/s aggregate, every request bit-identical to running alone |
53
+ | OLMoE-1B-7B, 64 requests at once | 1,016 tok/s aggregate |
54
+ | Continuous batching (128 requests, 32 slots) | the throughput of a static batch, 7.4× one at a time |
55
+ | Qwen3.5-35B-A3B (Gated DeltaNet hybrid), batched | 4.35× one at a time, bit-identical |
56
+ | Qwen3-30B (57 GB) on the 15 GB laptop, streamed from NVMe | about 1 tok/s, the H100's logits bit for bit |
57
+ | Cost of exactness | +1.8% per GPU decode step |
58
+
59
+ ## Supported models
60
+ Vahana finds the experts by structure (transformers' `experts(hidden, indices, weights)` modules) instead of hard-coding families, and fails loudly on anything it does not recognise.
61
+
62
+ | Status | Families |
63
+ |---|---|
64
+ | **Real checkpoints validated** (exact + quality) | Mixtral, DeepSeek-V2 (Lite and 236B), Qwen1.5-MoE (Qwen2-MoE), Qwen3-MoE, OLMoE |
65
+ | **Validated on the real architecture, tiny random weights** (exact, batch-invariant, graph decode) | DeepSeek-V3, GLM-4-MoE (+Lite), MiniMax-M2, Hunyuan-MoE, Ernie-4.5-MoE, Cohere2-MoE, Exaone-MoE, AFMoE, gpt-oss (BF16 experts) |
66
+ | **Real checkpoint validated, eager decode** | Qwen3.5-MoE (Gated DeltaNet; Qwen3.5-35B-A3B batched and served exactly) |
67
+ | **Exact, eager decode only** (tiny random weights) | MiniMax (lightning attention), Phi-MoE (host-side RoPE) |
68
+ | **Not yet** | gpt-oss MXFP4 checkpoints, FP8 checkpoints (DeepSeek-V3/R1), Llama 4, Granite-MoE, JetMoE, DBRX, encoder-decoder MoE |
69
+
70
+ ## How it is exact
71
+ - **Twin arithmetic.** CPU and GPU kernels evaluate every dot product in the same order (16 fp32 FMA lanes, a fixed reduction tree) with the same BF16 rounding points. An expert or linear layer gives the same bits on either device.
72
+ - **Batch-invariant kernels.** The `vahana` attention function and the linear and norm kernels reduce each row in a fixed order that depends only on that row. Batch neighbours, padding and prefill-vs-decode cannot change it.
73
+ - **NX12.** A lossless 12-bit encoding of BF16 expert weights (75% of the size) that the CPU kernel decodes at memory bandwidth.
74
+ - **One CUDA graph per decode step,** with the CPU jobs reached through a GPU↔CPU mailbox, for any model.
75
+ - **Batching without changing bits.** Every kernel computes each row on its own, and attention is anchored at each query's first key, so batch neighbours and padding never move a rounding. The continuous-batching engine only copies KV; recurrent layers never see padding.
76
+ - **Twin arithmetic for everything else (v0.2 P2).**
77
+ - Attention has a CPU twin of the GPU kernel: the same blocks, Vahana's own `exp` and fixed reduction trees.
78
+ - Every remaining operation is written only in IEEE-exact steps: norms, rotary embeddings, router softmax and top-k, activations, small matmuls.
79
+ - Two notable cases:
80
+ - PyTorch's CUDA `sqrt` is not correctly rounded, so Vahana's sqrt is.
81
+ - CUDA divides by a scalar via its reciprocal, so Vahana divides by a device tensor.
82
+ - **Result:** the whole model gives the same bits on any CPU or GPU.
83
+ - **Cost:** +1.8% per GPU decode step.
84
+
85
+ ## Requirements and limits
86
+ - **Python 3.10+, PyTorch 2.4+, transformers 5.12–5.13.** Vahana runs transformers' own model code, and later releases changed some models' definitions (Qwen3.5-MoE from 5.14, gpt-oss from 5.19), which moves their outputs off the selftest reference. CI's `compat` job tracks every release; the range widens as versions are validated. NVIDIA GPUs need Triton (`vahana[gpu]`). CPU-only works everywhere.
87
+ - **RAM:**
88
+ - **Fast:** room for the experts, plus page cache.
89
+ - **Less RAM still works, exactly:** experts stream from disk at disk speed. A saturated NVMe caps decode; for example Qwen3-30B on a 15 GB laptop runs at about 1 tok/s.
90
+ - **One NVIDIA GPU, or none.** Multi-GPU is not supported.
91
+ - **CPU:** x86-64 (AVX-512 fastest, AVX2, or plain) and ARM64 (NEON). Wheels: Linux x86-64 / arm64, Windows x86-64, macOS arm64. CI runs the selftest on each, under every instruction set.
92
+ - **Checkpoints:** BF16. FP8 and MXFP4 checkpoints are not yet supported.
93
+ - **Hybrid linear-attention models** decode eagerly (no CUDA graph).
94
+ - **Speculative decoding is exact but rarely faster for batch-1 MoE:** each drafted token routes to new experts ([why](docs/benchmarks.md#what-did-not-work)).
95
+ - **Prefill on very large models is slow** when many linears sit in CPU RAM: 38 s for a 236B prompt.
96
+
97
+ ## Layout
98
+ - **Engine:** `src/vahana/`:
99
+ - `loader`, `modelspec`, `experts`, `runtime` (GPU↔CPU mailbox), `cache` (GPU expert cache);
100
+ - `attention`, `twinlin`, `fused`, `tmath` (twin arithmetic);
101
+ - `decode`, `batch`, `speculative`, `engine` (continuous batching);
102
+ - `server`, `cli`, `doctor`, `selftest`.
103
+ - **CPU kernel:** `src/vahana/csrc/`: `cpu_moe.cpp`, `vt.h`, `pool.h`, `build.py`. A plain shared library with a C ABI, loaded through `_kernel.py`. `osl.py` holds the OS-specific calls.
104
+ - **Earlier research modules** (column tiers, ANS plane, tiered serving) are kept for reference and are not on the default path.
105
+ - **Design:** `docs/design/`. **Evidence:** `experiments/` (M0–M5, P1–P4, v0.3-a … v0.5).
106
+
107
+ ## License
108
+ Apache License 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Copyright 2026 Aditya Sai Teja B.
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vahana"
7
+ version = "1.0.0"
8
+ description = "Exact, bit-reproducible inference and serving for Mixture-of-Experts models too big for your GPU"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [{ name = "Aditya Sai Teja B" }]
12
+ license = { text = "Apache-2.0" }
13
+ keywords = ["llm", "inference", "mixture-of-experts", "moe", "deterministic", "reproducible", "serving"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "License :: OSI Approved :: Apache Software License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: C++",
19
+ "Operating System :: POSIX :: Linux",
20
+ "Operating System :: Microsoft :: Windows",
21
+ "Operating System :: MacOS",
22
+ "Intended Audience :: Science/Research",
23
+ "Intended Audience :: Developers",
24
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
25
+ ]
26
+
27
+ dependencies = [
28
+ "torch>=2.4",
29
+ "transformers>=5.12,<5.14", # the versions every real checkpoint and the selftest reference were validated on (see CI `compat`)
30
+ "accelerate>=1.0",
31
+ "safetensors>=0.4",
32
+ "numpy>=1.24",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/vahana-ai/Vahana"
37
+ Source = "https://github.com/vahana-ai/Vahana"
38
+ Changelog = "https://github.com/vahana-ai/Vahana/blob/main/CHANGELOG.md"
39
+
40
+ [project.scripts]
41
+ vahana = "vahana.cli:main"
42
+
43
+ [project.optional-dependencies]
44
+ gpu = [ # NVIDIA GPUs: Triton on Linux, triton-windows on Windows
45
+ "triton>=3.0; platform_system == 'Linux'",
46
+ "triton-windows>=3.2; platform_system == 'Windows'",
47
+ ]
48
+ test = ["pytest>=8"]
49
+
50
+ [tool.setuptools.packages.find]
51
+ where = ["src"]
52
+
53
+ [tool.setuptools.package-data]
54
+ # the CPU kernel, one library per instruction set (built by setup.py / csrc/build.py), and the selftest reference
55
+ vahana = ["_build/*/vahana_kernel.so", "_build/*/vahana_kernel.dll", "_build/*/vahana_kernel.dylib", "golden_tiny.json", "csrc/*.cpp", "csrc/*.h", "csrc/*.py", "csrc/*.sh"]
56
+
57
+ [tool.pytest.ini_options]
58
+ testpaths = ["tests"]
vahana-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
vahana-1.0.0/setup.py ADDED
@@ -0,0 +1,45 @@
1
+ """Builds the CPU kernel libraries into the wheel (one per instruction set; see src/vahana/csrc/build.py).
2
+
3
+ The libraries have a C ABI and no Python or torch dependency, so the wheel is tagged py3-none-<platform>: one wheel
4
+ per OS / architecture serves every Python >= 3.10 and every torch >= 2.4.
5
+ VAHANA_ISAS="avx2 scalar" limits the builds; VAHANA_SKIP_KERNEL=1 skips them (then build them yourself).
6
+ """
7
+ import os
8
+ import subprocess
9
+ import sys
10
+
11
+ from setuptools import Distribution, setup
12
+ from setuptools.command.build_py import build_py
13
+
14
+ try:
15
+ from setuptools.command.bdist_wheel import bdist_wheel
16
+ except ImportError: # setuptools < 70
17
+ from wheel.bdist_wheel import bdist_wheel
18
+
19
+
20
+ class BuildKernel(build_py):
21
+ def run(self):
22
+ if os.environ.get("VAHANA_SKIP_KERNEL") != "1":
23
+ here = os.path.dirname(os.path.abspath(__file__))
24
+ isas = os.environ.get("VAHANA_ISAS", "").split()
25
+ subprocess.run([sys.executable, os.path.join(here, "src", "vahana", "csrc", "build.py"), *isas], check=True)
26
+ self.data_files = self._get_data_files() # include the libraries just built
27
+ super().run()
28
+
29
+
30
+ class BinaryDistribution(Distribution):
31
+ def has_ext_modules(self): # the kernel libraries are binaries: platform wheel, files in platlib
32
+ return True
33
+
34
+
35
+ class PlatformWheel(bdist_wheel):
36
+ def finalize_options(self):
37
+ super().finalize_options()
38
+ self.root_is_pure = False
39
+
40
+ def get_tag(self):
41
+ _, _, plat = super().get_tag()
42
+ return "py3", "none", plat
43
+
44
+
45
+ setup(distclass=BinaryDistribution, cmdclass={"build_py": BuildKernel, "bdist_wheel": PlatformWheel})