gridbook 0.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.
Files changed (66) hide show
  1. gridbook-0.1.0/LICENSE +201 -0
  2. gridbook-0.1.0/MANIFEST.in +33 -0
  3. gridbook-0.1.0/PKG-INFO +353 -0
  4. gridbook-0.1.0/README.md +318 -0
  5. gridbook-0.1.0/ROADMAP.md +158 -0
  6. gridbook-0.1.0/docs/BENCHMARKS.md +326 -0
  7. gridbook-0.1.0/docs/CONTAINER.md +561 -0
  8. gridbook-0.1.0/docs/INSTALL.md +314 -0
  9. gridbook-0.1.0/docs/KERNELS.md +210 -0
  10. gridbook-0.1.0/docs/MOTIVATION.md +143 -0
  11. gridbook-0.1.0/docs/PLUGIN.md +230 -0
  12. gridbook-0.1.0/docs/RELEASING.md +298 -0
  13. gridbook-0.1.0/docs/SPEC.md +488 -0
  14. gridbook-0.1.0/docs/TROUBLESHOOTING.md +400 -0
  15. gridbook-0.1.0/gridbook/__init__.py +18 -0
  16. gridbook-0.1.0/gridbook/codec.py +145 -0
  17. gridbook-0.1.0/gridbook/config.py +425 -0
  18. gridbook-0.1.0/gridbook/csrc/cb_fused_gemm.cu +734 -0
  19. gridbook-0.1.0/gridbook/csrc/cb_gemv.cu +1905 -0
  20. gridbook-0.1.0/gridbook/csrc/cb_persistent_prefill.cu +201 -0
  21. gridbook-0.1.0/gridbook/csrc/cb_persistent_tc.cu +353 -0
  22. gridbook-0.1.0/gridbook/csrc/cutlass_fork/sm120_cb_fused_mma.hpp +670 -0
  23. gridbook-0.1.0/gridbook/csrc/cutlass_fork/sm120_cb_mma_tma.hpp +613 -0
  24. gridbook-0.1.0/gridbook/csrc/cutlass_fork/sm120_cb_persistent_mma.hpp +197 -0
  25. gridbook-0.1.0/gridbook/csrc/cutlass_fork/sm120_expert_row_broadcast.hpp +344 -0
  26. gridbook-0.1.0/gridbook/csrc/cutlass_fork/sm120_mma_tma_orig.hpp +587 -0
  27. gridbook-0.1.0/gridbook/csrc/sm120_fp8_gemm.cu +131 -0
  28. gridbook-0.1.0/gridbook/csrc/smem_probe_tilem.cu +163 -0
  29. gridbook-0.1.0/gridbook/csrc/toolchain_probe.cu +30 -0
  30. gridbook-0.1.0/gridbook/cuda_ext.py +250 -0
  31. gridbook-0.1.0/gridbook/expand.py +402 -0
  32. gridbook-0.1.0/gridbook/kernels.py +230 -0
  33. gridbook-0.1.0/gridbook/linear.py +492 -0
  34. gridbook-0.1.0/gridbook/moe.py +1988 -0
  35. gridbook-0.1.0/gridbook/moe_autotune.py +157 -0
  36. gridbook-0.1.0/gridbook/moe_l2.py +211 -0
  37. gridbook-0.1.0/gridbook/moe_routing.py +78 -0
  38. gridbook-0.1.0/gridbook/moe_toplevel_loader.py +598 -0
  39. gridbook-0.1.0/gridbook/ops.py +303 -0
  40. gridbook-0.1.0/gridbook/plugin.py +143 -0
  41. gridbook-0.1.0/gridbook.egg-info/PKG-INFO +353 -0
  42. gridbook-0.1.0/gridbook.egg-info/SOURCES.txt +64 -0
  43. gridbook-0.1.0/gridbook.egg-info/dependency_links.txt +1 -0
  44. gridbook-0.1.0/gridbook.egg-info/entry_points.txt +2 -0
  45. gridbook-0.1.0/gridbook.egg-info/requires.txt +10 -0
  46. gridbook-0.1.0/gridbook.egg-info/top_level.txt +1 -0
  47. gridbook-0.1.0/pyproject.toml +85 -0
  48. gridbook-0.1.0/setup.cfg +4 -0
  49. gridbook-0.1.0/tests/bench_cuda_gemv.py +104 -0
  50. gridbook-0.1.0/tests/bench_r2_terms.py +239 -0
  51. gridbook-0.1.0/tests/test_cb_kernels.py +202 -0
  52. gridbook-0.1.0/tests/test_cuda_gemv.py +846 -0
  53. gridbook-0.1.0/tests/test_delegation.py +125 -0
  54. gridbook-0.1.0/tests/test_fused_prefill.py +250 -0
  55. gridbook-0.1.0/tests/test_moe_batched_prefill.py +344 -0
  56. gridbook-0.1.0/tests/test_moe_grouped_fused.py +696 -0
  57. gridbook-0.1.0/tests/test_moe_l2_pipeline.py +370 -0
  58. gridbook-0.1.0/tests/test_moe_stacked.py +98 -0
  59. gridbook-0.1.0/tests/test_moe_stock_prefill.py +385 -0
  60. gridbook-0.1.0/tests/test_persistent_prefill.py +100 -0
  61. gridbook-0.1.0/tests/test_persistent_tc.py +124 -0
  62. gridbook-0.1.0/tests/test_target_namespace_compat.py +377 -0
  63. gridbook-0.1.0/tests/test_toplevel_loader.py +738 -0
  64. gridbook-0.1.0/tests/test_transient_fp8.py +275 -0
  65. gridbook-0.1.0/tests/test_two_tier_v2.py +129 -0
  66. gridbook-0.1.0/tests/test_weight_residency.py +232 -0
gridbook-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Robert Tand
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,33 @@
1
+ # Sdist contents beyond the package itself. Release artifacts are built from
2
+ # THIS tree (the public repo), so the sdist gets the full public README, the
3
+ # docs/ set and the roadmap; the in-tree plugin has none of those.
4
+ #
5
+ # The runtime CUDA sources need no rule here: they live inside the package
6
+ # (gridbook/csrc) and are declared as [tool.setuptools.package-data] in
7
+ # pyproject.toml, which setuptools also honours when building the sdist.
8
+ #
9
+ # LICENSE / NOTICE need no rule either: setuptools' default `license-files`
10
+ # globs (LICEN[CS]E*, COPYING*, NOTICE*, AUTHORS*) put them in both the sdist
11
+ # and the wheel's .dist-info/licenses/.
12
+ include ROADMAP.md
13
+ graft docs
14
+ recursive-include tests *.py
15
+
16
+ # ...but `graft docs` is indiscriminate, and two things under docs/ are internal
17
+ # working material, not documentation for someone who ran `pip install gridbook`.
18
+ # A published sdist is permanent (a PyPI file cannot be re-uploaded), so these
19
+ # are excluded at the source rather than trimmed later:
20
+ #
21
+ # docs/DISTRIBUTION.md the distribution decision record -- internal machine
22
+ # paths, internal task numbers, and a not-yet-executed
23
+ # launch plan. Reaches the public via the GitHub repo,
24
+ # which is a revisable surface; it has no business in an
25
+ # immutable release artifact.
26
+ # docs/hf-cards/ staged HuggingFace card edits that have not been
27
+ # applied yet, each carrying its own APPLY GATE. Shipping
28
+ # un-applied drafts inside the wheel's own sdist invites
29
+ # someone to read them as the current cards.
30
+ exclude docs/DISTRIBUTION.md
31
+ prune docs/hf-cards
32
+
33
+ global-exclude *.py[cod]
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: gridbook
3
+ Version: 0.1.0
4
+ Summary: vLLM plugin for the NVFP4-CB / FP8-CB product-codebook weight formats: 2-6 bit-per-weight LLM quantization served by dedicated CUDA decode and prefill kernels.
5
+ Author-email: Robert Tand <robert.tand@icloud.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/RobTand/gridbook
8
+ Project-URL: Repository, https://github.com/RobTand/gridbook
9
+ Project-URL: Issues, https://github.com/RobTand/gridbook/issues
10
+ Project-URL: Documentation, https://github.com/RobTand/gridbook/blob/master/docs/SPEC.md
11
+ Keywords: vllm,quantization,llm,inference,cuda,nvfp4,fp8,codebook,vector-quantization,blackwell
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: GPU :: NVIDIA CUDA
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: torch
27
+ Requires-Dist: triton
28
+ Requires-Dist: safetensors
29
+ Requires-Dist: huggingface-hub
30
+ Provides-Extra: serve
31
+ Requires-Dist: vllm; extra == "serve"
32
+ Provides-Extra: test
33
+ Requires-Dist: pytest; extra == "test"
34
+ Dynamic: license-file
35
+
36
+ # gridbook
37
+
38
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
39
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](docs/INSTALL.md)
40
+ [![Status](https://img.shields.io/badge/status-beta-orange.svg)](ROADMAP.md)
41
+
42
+ **Codebook-quantized LLM weights that serve at native tensor-core speed.**
43
+ `gridbook` is a **format specification** plus an **out-of-tree vLLM plugin** that
44
+ serves it: weights are stored as product-vector-quantization codebook indices
45
+ whose codebook entries lie exactly on a hardware grid (NVFP4 / FP8), so a decoded
46
+ tile *is* a native tile and feeds the same Blackwell tensor-core GEMM vLLM
47
+ already runs. No forked runtime, no patched vLLM core, no custom serving stack.
48
+
49
+ Ready-to-serve models are published on Hugging Face — [jump to the
50
+ list](#published-artifacts).
51
+
52
+ ---
53
+
54
+ ## What you need
55
+
56
+ | | Requirement |
57
+ |---|---|
58
+ | **GPU** | NVIDIA **Blackwell `sm_120` / `sm_121`** for the native-speed path (GB10 / DGX Spark is the reference; RTX 5090 is user-reported). Older NVIDIA cards partly work — read the [compatibility table](#compatibility) before assuming. |
59
+ | **CUDA toolchain** | `nvcc` on `PATH` **in the process that serves**, matching your torch build. Kernels are **JIT-compiled on first model load** (~30 s once, then cached), *not* at `pip install` time. `nvcc` 13.0 is the tested toolchain. |
60
+ | **PyTorch** | whatever build your vLLM uses (measured: `2.11.0+cu130`). |
61
+ | **vLLM** | already installed — gridbook is a plugin, not a runtime. Measured against `0.23.1rc1.dev764+g54b16d8a9`; see [compatibility](#compatibility). |
62
+ | **Parallelism** | **`tp=1` only.** The plugin has no tensor-parallel handling; multi-GPU sharding of CB weights is not implemented. |
63
+ | **Python** | ≥ 3.10 (measured on 3.12). |
64
+
65
+ Without `nvcc`, or on a non-Blackwell GPU, the plugin still loads and produces
66
+ **correct** output through fallback kernels — but they are a correctness path,
67
+ not a speed path. For dense decode the fallback is unchanged code and the gap is
68
+ measured: the Triton decode-GEMM did **4.20 tok/s** on the 27B where the CUDA
69
+ GEMV does **10.28**. For MoE the grouped CUDA GEMV is skipped entirely and the
70
+ regression is larger but artifact-dependent — that is a *historical*
71
+ before/after, not a fresh benchmark of today's fallback, and
72
+ [`BENCHMARKS.md`](docs/BENCHMARKS.md#what-the-fallback-costs) says exactly what
73
+ was and was not measured. See
74
+ [TROUBLESHOOTING](docs/TROUBLESHOOTING.md#the-cuda-extension-did-not-load-triton-fallback)
75
+ for how to tell which path you are on.
76
+
77
+ ---
78
+
79
+ ## Install
80
+
81
+ Install **into the environment that already has vLLM and torch** — gridbook does
82
+ not pin either.
83
+
84
+ ```bash
85
+ pip install git+https://github.com/RobTand/gridbook
86
+ ```
87
+
88
+ That is the only route that works today. `pip install gridbook` is **planned but
89
+ not yet published** — the PyPI name is unclaimed, so that command fails right
90
+ now. Track it on the [roadmap](ROADMAP.md#distribution).
91
+
92
+ There is nothing else to configure: the plugin registers itself through vLLM's
93
+ `vllm.general_plugins` entry point, and vLLM auto-detects a gridbook checkpoint
94
+ from its `config.json`. No `--quantization` flag.
95
+
96
+ Full matrix — toolchain versions, the three install routes, the first-run JIT
97
+ build, how to persist the build cache, and a copy-pasteable install check:
98
+ **[`docs/INSTALL.md`](docs/INSTALL.md)**. For the container route — a
99
+ [`Dockerfile`](Dockerfile) that builds vLLM + gridbook + the kernels in one
100
+ image — see **[`docs/CONTAINER.md`](docs/CONTAINER.md)**.
101
+
102
+ ---
103
+
104
+ ## Quickstart — serve a real model
105
+
106
+ ```bash
107
+ pip install git+https://github.com/RobTand/gridbook
108
+
109
+ vllm serve rdtand/Qwen3.6-27B-prismaquant-gridbook-5.5bit-vllm \
110
+ --host 0.0.0.0 --port 8000 \
111
+ --max-model-len 32768 \
112
+ --gpu-memory-utilization 0.85 \
113
+ --enforce-eager
114
+ ```
115
+
116
+ ```bash
117
+ curl -s http://localhost:8000/v1/completions \
118
+ -H 'Content-Type: application/json' \
119
+ -d '{"model": "rdtand/Qwen3.6-27B-prismaquant-gridbook-5.5bit-vllm",
120
+ "prompt": "The capital of France is", "max_tokens": 8, "temperature": 0}'
121
+ ```
122
+
123
+ **How to tell it is actually working.** The failure is silent by design (the
124
+ plugin fail-softs to Triton rather than refusing to serve), so check for the
125
+ warning rather than for a crash:
126
+
127
+ - **Bad** — a `[prismaquant-cb] WARNING:` line on stderr saying the CUDA
128
+ decode-GEMV extension could not be built means you are on the slow path.
129
+ (Grep your vLLM log for `[prismaquant-cb]`, not for `gridbook` — the runtime
130
+ log prefix still uses the project's older name.)
131
+ - **Good** — no such line, and the first model load pauses ~30 s the first time
132
+ ever on that machine (the JIT build) and not on subsequent starts.
133
+ - A definitive check that does not require serving anything is in
134
+ [`docs/INSTALL.md`](docs/INSTALL.md#verify-the-install).
135
+
136
+ Notes:
137
+
138
+ - **`--enforce-eager` is the tested configuration.** The decode dispatch branches
139
+ on the token count on the host, which is capture-hostile; naive graph capture
140
+ made decode *worse*, because vLLM pads captured decode batches past the
141
+ prefill threshold and every graphed step then took the prefill path. Details
142
+ and the exceptions: [`KERNELS.md`](docs/KERNELS.md#cuda-graph-safety-rules).
143
+ - **`--gpu-memory-utilization 0.85` is a deliberately conservative start**, not a
144
+ tuned value. On a unified-memory box (GB10 / DGX Spark) that flag does not
145
+ carve up private VRAM — it claims from the pool the host also lives in, and
146
+ 0.94/0.95 killed the whole machine under long-prefill spikes. Bring the server
147
+ up, check several GiB of `MemAvailable` remain, then raise it. On a discrete
148
+ GPU you can generally go higher. Details:
149
+ [`INSTALL.md`](docs/INSTALL.md#per-artifact-requirements) and
150
+ [`TROUBLESHOOTING.md`](docs/TROUBLESHOOTING.md#out-of-memory--box-hang-on-a-dgx-spark).
151
+ - Set `--max-model-len` to fit your KV budget. Adding `--kv-cache-dtype fp8`
152
+ roughly halves KV bytes and is what the larger artifacts were measured with.
153
+ - Serving by Hub id (as above) or from a local directory both work — the
154
+ codebook sidecar is fetched from the Hub when you pass a repo id.
155
+
156
+ ---
157
+
158
+ ## Published artifacts
159
+
160
+ All are standard Hugging Face directories (`config.json` + safetensors + the
161
+ `cb_codebooks.pqcb` codebook sidecar + tokenizer). Sizes are the sum of repo
162
+ files, read from the HF API on 2026-07-28.
163
+
164
+ | Model | Repo | Size on disk | bpp | Notes |
165
+ |---|---|---|---|---|
166
+ | Qwen3.6-27B (dense hybrid VL) | [`rdtand/Qwen3.6-27B-prismaquant-gridbook-5.5bit-vllm`](https://huggingface.co/rdtand/Qwen3.6-27B-prismaquant-gridbook-5.5bit-vllm) | 23.0 GB (21.4 GiB) | 5.5 | The measured quality result below. Vision tower is stock NVFP4 W4A16, so it needs a vLLM NVFP4 backend as well as gridbook. |
167
+ | Laguna-S-2.1 (117B sparse MoE, coding) | [`rdtand/Laguna-S-2.1-prismaquant-gridbook-6bit-vllm`](https://huggingface.co/rdtand/Laguna-S-2.1-prismaquant-gridbook-6bit-vllm) | 89.4 GB (83.2 GiB) | 6.0 | 256k context on one 128 GB box. **No quality claims** (no servable BF16 teacher at this scale). |
168
+ | Hy3-295B-A21B (295B MoE) | [`rdtand/Hy3-295B-A21B-prismaquant-gridbook-2.9bit-vllm`](https://huggingface.co/rdtand/Hy3-295B-A21B-prismaquant-gridbook-2.9bit-vllm) | 105.7 GB (98.5 GiB) | 2.9 | Serves on a **single** 128 GB box. **No quality-vs-teacher claim** at this scale. |
169
+
170
+ Each artifact needs enough memory for its weights **plus** KV cache and
171
+ activation headroom; see [`docs/INSTALL.md`](docs/INSTALL.md#per-artifact-requirements).
172
+
173
+ ---
174
+
175
+ ## Compatibility
176
+
177
+ The native path is Blackwell-targeted, but the decode kernel is *not*
178
+ arch-specific — this table separates what was **measured** from what is
179
+ **inferred from the code and untested**. Nothing here is inferred silently.
180
+
181
+ | GPU class | Decode (M ≤ 16) | Dense FP8-CB prefill | Mid-M fused prefill (16 < M ≤ 128) | Verdict |
182
+ |---|---|---|---|---|
183
+ | **GB10 / DGX Spark, `sm_121`** | CUDA GEMV | expand → stock W8A8 GEMM | CUTLASS `sm120` | **MEASURED.** Every published number comes from this box. |
184
+ | **RTX 5090, `sm_120`** | same | same | same | **USER-REPORTED** working (vLLM 0.25.1, 27B artifact, [issue #1](https://github.com/RobTand/gridbook/issues/1)) after that issue's memory patches. No speed numbers published; the exact `nvcc` arch flag (`sm_120` vs the measured `sm_121`) is untested here. |
185
+ | **H100 `sm_90`, RTX 4090 / L40S `sm_89`** | expected to work — the decode kernel contains no arch guards, no inline PTX and no `-arch` flag | expected to work (needs `sm_89+` fp8 support) | **fails, fail-softs** to the expand path with a warning (the fused kernel is `sm_120`-family only) | **INFERRED, UNTESTED.** Also gated by whatever the artifact's non-CB groups need (e.g. the 27B vision tower's NVFP4). |
186
+ | **A100 `sm_80`** | expected to work | **expected to fail**: the dense FP8-CB prefill calls `cutlass_scaled_mm` on fp8 with no capability guard and no fallback | n/a | **NOT RECOMMENDED.** The declared capability floor is 8.0, but a prompt longer than 16 tokens is expected to error. INFERRED from code; no A100 was tested. |
187
+ | **No `nvcc`, or non-NVIDIA** | Triton fallback | Triton fallback | n/a | **Correct, slow.** Use for numerics verification and CI, not for serving. |
188
+
189
+ Tested software stack (verified in-container, 2026-07-28): vLLM
190
+ `0.23.1rc1.dev764+g54b16d8a9`, torch `2.11.0+cu130`, triton `3.6.0`,
191
+ transformers `5.13.0`, CUDA `13.0.88`, Python `3.12.3`, **arm64**. vLLM `0.25.1`
192
+ and `0.23.1rc1.dev1060` are user-reported working on x86 + RTX 5090 (issue #1).
193
+ Everything else is untested. See
194
+ [`docs/INSTALL.md`](docs/INSTALL.md#tested-software-stack) for how versions can
195
+ drift and what that looks like.
196
+
197
+ ---
198
+
199
+ ## Why this exists
200
+
201
+ Below ~4 bits per weight, single-format scalar quantization loses quality fast,
202
+ and the methods that recover it (learned codebooks / vector quantization) have
203
+ historically been **slow to serve**: a VQ weight must be *decoded* before it can
204
+ be multiplied, and that decode usually runs on general CUDA cores, not tensor
205
+ cores.
206
+
207
+ Concretely, in the `llama.cpp` / GGUF ecosystem — today's most common low-bit
208
+ serving path:
209
+
210
+ - **k-quant** formats have a good fused CUDA matmul path (MMQ), so they serve
211
+ reasonably fast, but their quality rungs stop around 3–4 bits.
212
+ - **IQ** formats (the sub-3-bit "I-quant" rungs) reach much better quality, but
213
+ their decode falls to a **slower CUDA-core dequant path** — a *prefill tax* you
214
+ pay on every prompt token.
215
+
216
+ `gridbook` targets **IQ-class quality at native-kernel speed**. The dtype in each
217
+ format name is the **grid the codebook's values live on, not the storage width**:
218
+ storage is a k-bit index per 8-weight vector, so `FP8_CB_K32` is a 4.0-bit/weight
219
+ encoding whose reconstructed values are exact fp8 numbers, and `NVFP4_CB_K16` is
220
+ a ~2.3-bit/weight encoding reconstructing exact NVFP4 codes. Because a decoded CB
221
+ tile *is* an NVFP4/FP8 tile:
222
+
223
+ 1. **Decode (batch-1 / small M):** a bandwidth-bound fused GEMV streams the
224
+ packed indices, expands per group in registers, and multiplies — fewer bytes
225
+ per weight means *less* memory traffic than a wider format, so decode is at or
226
+ above native-format speed.
227
+ 2. **Prefill (large M):** the layer's weight tile is expanded **transiently** into
228
+ a scratch buffer (bounded — never a resident dense weight), then run through
229
+ the stock native GEMM.
230
+
231
+ Formats mix per-Linear with plain NVFP4, FP8 and BF16 inside one standard
232
+ `safetensors` checkpoint. See [`docs/MOTIVATION.md`](docs/MOTIVATION.md) for the
233
+ full argument and [`docs/KERNELS.md`](docs/KERNELS.md) for the kernel design.
234
+
235
+ ---
236
+
237
+ ## Headline results
238
+
239
+ Quality numbers are **at matched bits-per-weight** against a baseline quantized
240
+ to stock per-Linear NVFP4/FP8 (served natively by vLLM's `compressed-tensors`
241
+ path). Measured on a single **NVIDIA GB10 / DGX Spark** (Blackwell `sm_121`,
242
+ 128 GB unified memory, ~273 GB/s), single calibration seed. Read the caveats in
243
+ [`docs/BENCHMARKS.md`](docs/BENCHMARKS.md) — especially the ±17% measurement-
244
+ arithmetic band and the single-seed noise band.
245
+
246
+ | Model | bpp | Quality vs matched-bpp NVFP4/FP8 baseline | Serving speed |
247
+ |---|---|---|---|
248
+ | **27B dense hybrid** | 5.5 | **ALL-KL −58.3%**, confident-KL −52.9%, PPL gap to BF16 ~3× smaller | decode **at native parity** (10.3 vs 10.26 tok/s); dense prefill 1.44× the baseline's TTFT |
249
+ | **35B MoE**, 256 experts (**not published**) | 4.75 | **confident-KL −53%**, ALL-KL −43%, top-1 agreement higher on both slices | decode 32.6–33.3 tok/s — **faster than BF16** (28.4) |
250
+ | **295B MoE** (published) | 2.9 | *no quality-vs-teacher claim at this scale* | **serves on ONE DGX Spark**; prefill **~109 tok/s vs the matched-byte GGUF IQ build's 42 = ~2.6×**; base decode 14.6 tok/s (16.1 with the MTP draft) — below the GGUF build's ~18 |
251
+
252
+ - **The 27B row is the A/B build, not the published file — and the published
253
+ file's own card reports different absolute numbers.** The −58.3% comes from
254
+ the 2026-07-18 head-to-head, whose CB arm used a 4-rung menu
255
+ (`FP8_CB_K36/K40/K44/K48`). The artifact actually on the Hub is a later,
256
+ finer 8-rung ladder (`K36`–`K47`), measured in a **different** evaluation
257
+ session, and its [model
258
+ card](https://huggingface.co/rdtand/Qwen3.6-27B-prismaquant-gridbook-5.5bit-vllm)
259
+ reports ALL-KL **0.0049** and **−77%** where this table's session reads
260
+ 0.0134 and −58.3%. Both are real; **absolute KL is not comparable across
261
+ sessions** (the *same unchanged* NVFP4/FP8 baseline artifact reads 0.02407
262
+ confident-KL in one session and 0.01302 in the other), while the within-session
263
+ relative verdict — CB wins big at matched bytes — reproduces in both. The
264
+ arithmetic is worked through in
265
+ [`BENCHMARKS.md`](docs/BENCHMARKS.md#two-sessions-two-builds-why-the-model-card-says-77-and-this-page-says-583).
266
+ This page quotes the more conservative figure.
267
+ - The 35B MoE result is an internal measurement; **there is no downloadable 35B
268
+ gridbook artifact**. It is reported because it is the evidence that the format
269
+ win reproduces on Mixture-of-Experts, not as something you can reproduce
270
+ without an encoder.
271
+ - The 295B result carries **no quality-vs-teacher claim**: a 295B BF16 reference
272
+ cannot be run on a single box to compute KL against. What is validated is that
273
+ it loads, serves, and generates coherent, arithmetically-correct output on one
274
+ 128 GB box, and its speed against a matched-byte GGUF build. Tool-use
275
+ (ToolEvalBench) is **parity within the plateau band**, not a quality win: the
276
+ shipped artifact scored 88/100 (130/148) on the ship config, against 87 for the
277
+ GGUF IQ build and 86 for GGUF k-quant, with a measured single-seed churn band of
278
+ ±2–3 points across serving configs.
279
+ - **MoE prefill is solved and on by default.** Measured on Laguna-S-2.1 (117B
280
+ MoE): 293 → **1,821 tok/s** at 8k and 207 → **1,822 tok/s** at 63k after the
281
+ CUDA chunk-expander landed (commit `8829c16`); the current default is a
282
+ measured per-layer path selection. Docs that still describe MoE prefill as a
283
+ per-expert loop are stale — see [`ROADMAP.md`](ROADMAP.md) for what is actually
284
+ open.
285
+ - **Large-M dense prefill is the honest remaining gap**: ~1.44× the native GEMM's
286
+ TTFT on the 27B.
287
+
288
+ ---
289
+
290
+ ## Documentation
291
+
292
+ | Doc | What it covers |
293
+ |---|---|
294
+ | [`docs/INSTALL.md`](docs/INSTALL.md) | Hardware/toolchain matrix, the three install routes, first-run JIT build, cache persistence, install verification. |
295
+ | [`docs/TROUBLESHOOTING.md`](docs/TROUBLESHOOTING.md) | Real failure modes keyed to the exact message you see, with cause and fix. |
296
+ | [`docs/SPEC.md`](docs/SPEC.md) | **Normative format specification** — byte layout, product-VQ, v1/v2 scale coding, codebook sidecar, config vocabulary, extensibility contract. Implementation-independent, MUST/SHOULD language. |
297
+ | [`docs/MOTIVATION.md`](docs/MOTIVATION.md) | Why the 2–4 bpp regime needs codebooks, why serving has been the blocker, and an honest comparison to GGUF k-quant/IQ. |
298
+ | [`docs/KERNELS.md`](docs/KERNELS.md) | Serving kernel design: transient-expand prefill, fused act-QDQ decode GEMV, two-tier in-register scale compose, grouped MoE GEMV, Triton fallbacks, CUDA-graph rules. |
299
+ | [`docs/PLUGIN.md`](docs/PLUGIN.md) | Operator reference for the plugin itself: dispatch, kernel set, environment switches. |
300
+ | [`docs/BENCHMARKS.md`](docs/BENCHMARKS.md) | The measured results with full hardware/protocol context and caveats. |
301
+ | [`ROADMAP.md`](ROADMAP.md) | What is done, what is open, and what was measured and rejected. |
302
+ | [`CONTRIBUTING.md`](CONTRIBUTING.md) | How to run the tests, what a good bug report contains, and what is in scope. |
303
+
304
+ ---
305
+
306
+ ## Naming
307
+
308
+ One project, several strings — this trips people up when grepping logs, so here
309
+ is the whole list:
310
+
311
+ | Where | String |
312
+ |---|---|
313
+ | Repo / PyPI package / Python import | `gridbook` |
314
+ | vLLM quantization registry key | `"gridbook"` — what every published artifact carries in `config.json` |
315
+ | Legacy registry key (still accepted) | `"prismaquant"` — artifacts exported before the rename |
316
+ | Custom-op namespace | `prismaquant::` |
317
+ | Environment variables | `PRISMAQUANT_*` |
318
+ | Log/warning prefix | `[prismaquant-cb]` |
319
+
320
+ The `prismaquant`-prefixed runtime names are kept because renaming them would
321
+ break compatibility with already-published artifacts and with in-flight A/B
322
+ tooling; a rename of the *non*-load-bearing ones (build-cache directory, log
323
+ prefix) is a pre-1.0 item on the [roadmap](ROADMAP.md). **PrismaQuant** is the
324
+ separate research pipeline that *produces* gridbook artifacts —
325
+ [github.com/RobTand/prismaquant](https://github.com/RobTand/prismaquant).
326
+
327
+ ---
328
+
329
+ ## Scope and honesty notes
330
+
331
+ - The plugin **does not patch vLLM core**. It does install a thin `load_weights`
332
+ wrapper on specific *model classes* (HunYuan-V3, Laguna, Qwen3.5-MoE and their
333
+ MTP drafters) whose loaders map MoE experts at the top level and would
334
+ otherwise not recognise stacked codebook expert tensors. That wrap is inert for
335
+ non-CB checkpoints. Nothing in `vllm/` is modified.
336
+ - This repository **serves** the format; it does not yet **produce** artifacts.
337
+ A reference encoder is a roadmap item — until then, artifacts come from the
338
+ authors' pipeline, and the [spec](docs/SPEC.md) is published so an encoder can
339
+ be written independently.
340
+ - Every number in this repo comes from a measurement on the hardware named beside
341
+ it. Where something is inferred rather than measured, it says so.
342
+
343
+ ## License
344
+
345
+ Apache License 2.0 — see [`LICENSE`](LICENSE). The format specification in
346
+ [`docs/SPEC.md`](docs/SPEC.md) is published under the same license: the format is
347
+ free, open, and intended to be implemented by anyone, in any runtime, without
348
+ permission.
349
+
350
+ ## Citation and attribution
351
+
352
+ Robert Tand — <robert.tand@icloud.com>. Machine-readable metadata in
353
+ [`CITATION.cff`](CITATION.cff).