plumbify 0.2.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 (46) hide show
  1. plumbify-0.2.0/LICENSE +202 -0
  2. plumbify-0.2.0/PKG-INFO +212 -0
  3. plumbify-0.2.0/README.md +171 -0
  4. plumbify-0.2.0/plumbify/__init__.py +20 -0
  5. plumbify-0.2.0/plumbify/artifact.py +102 -0
  6. plumbify-0.2.0/plumbify/branch.py +370 -0
  7. plumbify-0.2.0/plumbify/calibration.py +109 -0
  8. plumbify-0.2.0/plumbify/cli.py +61 -0
  9. plumbify-0.2.0/plumbify/core/__init__.py +6 -0
  10. plumbify-0.2.0/plumbify/core/answers.py +75 -0
  11. plumbify-0.2.0/plumbify/core/decision_head.py +178 -0
  12. plumbify-0.2.0/plumbify/core/render.py +107 -0
  13. plumbify-0.2.0/plumbify/core/row.py +45 -0
  14. plumbify-0.2.0/plumbify/core/suffix_lora.py +124 -0
  15. plumbify-0.2.0/plumbify/core/taps.py +83 -0
  16. plumbify-0.2.0/plumbify/core/targets.py +161 -0
  17. plumbify-0.2.0/plumbify/core/tool.py +61 -0
  18. plumbify-0.2.0/plumbify/metrics.py +73 -0
  19. plumbify-0.2.0/plumbify/plumbed.py +390 -0
  20. plumbify-0.2.0/plumbify/py.typed +0 -0
  21. plumbify-0.2.0/plumbify/serving/__init__.py +1 -0
  22. plumbify-0.2.0/plumbify/serving/vllm/__init__.py +89 -0
  23. plumbify-0.2.0/plumbify/serving/vllm/client.py +419 -0
  24. plumbify-0.2.0/plumbify/serving/vllm/decisions.py +103 -0
  25. plumbify-0.2.0/plumbify/serving/vllm/hooks.py +78 -0
  26. plumbify-0.2.0/plumbify/serving/vllm/model.py +364 -0
  27. plumbify-0.2.0/plumbify/serving/vllm/openai.py +384 -0
  28. plumbify-0.2.0/plumbify/system1.py +277 -0
  29. plumbify-0.2.0/plumbify/training/__init__.py +1 -0
  30. plumbify-0.2.0/plumbify/training/data.py +37 -0
  31. plumbify-0.2.0/plumbify/training/eval_head.py +142 -0
  32. plumbify-0.2.0/plumbify/training/train.py +84 -0
  33. plumbify-0.2.0/plumbify/training/train_head.py +264 -0
  34. plumbify-0.2.0/plumbify.egg-info/PKG-INFO +212 -0
  35. plumbify-0.2.0/plumbify.egg-info/SOURCES.txt +44 -0
  36. plumbify-0.2.0/plumbify.egg-info/dependency_links.txt +1 -0
  37. plumbify-0.2.0/plumbify.egg-info/entry_points.txt +5 -0
  38. plumbify-0.2.0/plumbify.egg-info/requires.txt +17 -0
  39. plumbify-0.2.0/plumbify.egg-info/top_level.txt +1 -0
  40. plumbify-0.2.0/pyproject.toml +66 -0
  41. plumbify-0.2.0/setup.cfg +4 -0
  42. plumbify-0.2.0/tests/test_branch.py +197 -0
  43. plumbify-0.2.0/tests/test_calibration.py +125 -0
  44. plumbify-0.2.0/tests/test_plumbed.py +146 -0
  45. plumbify-0.2.0/tests/test_suffix_lora.py +94 -0
  46. plumbify-0.2.0/tests/test_system1.py +159 -0
plumbify-0.2.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.
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.4
2
+ Name: plumbify
3
+ Version: 0.2.0
4
+ Summary: Give an open LLM a fast, calibrated decision path and serve it natively with vLLM.
5
+ Author: Naveenraj Kamalakannan
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/therealnaveenkamal/plumbify
8
+ Project-URL: Documentation, https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md
9
+ Project-URL: Repository, https://github.com/therealnaveenkamal/plumbify
10
+ Project-URL: Issues, https://github.com/therealnaveenkamal/plumbify/issues
11
+ Project-URL: Changelog, https://github.com/therealnaveenkamal/plumbify/blob/main/CHANGELOG.md
12
+ Keywords: vllm,vllm-plugin,llm,lora,decision-making,calibration,inference
13
+ Classifier: Development Status :: 4 - Beta
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: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: torch>=2.6
26
+ Requires-Dist: transformers>=5.17
27
+ Requires-Dist: peft>=0.21
28
+ Requires-Dist: accelerate>=1.9
29
+ Requires-Dist: huggingface_hub>=0.30
30
+ Requires-Dist: safetensors
31
+ Requires-Dist: sentencepiece
32
+ Provides-Extra: vllm
33
+ Requires-Dist: vllm==0.30.0; extra == "vllm"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest; extra == "dev"
36
+ Requires-Dist: ruff; extra == "dev"
37
+ Requires-Dist: pre-commit; extra == "dev"
38
+ Requires-Dist: fastapi>=0.115; extra == "dev"
39
+ Requires-Dist: httpx>=0.27; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ <div align="center">
43
+
44
+ # Plumbify
45
+
46
+ **Give an open LLM a fast decision path, then serve it with vLLM.**
47
+
48
+ [![CI](https://github.com/therealnaveenkamal/plumbify/actions/workflows/ci.yml/badge.svg)](https://github.com/therealnaveenkamal/plumbify/actions/workflows/ci.yml)
49
+ [![PyPI](https://img.shields.io/pypi/v/plumbify.svg)](https://pypi.org/project/plumbify/)
50
+ [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://github.com/therealnaveenkamal/plumbify/blob/main/LICENSE)
51
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://github.com/therealnaveenkamal/plumbify/blob/main/pyproject.toml)
52
+ [![vLLM](https://img.shields.io/badge/vLLM-0.30.0-purple.svg)](https://github.com/vllm-project/vllm)
53
+
54
+ [Guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) · [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) · [Recipes](https://github.com/therealnaveenkamal/plumbify/tree/main/recipes) · [Results](#results) ·
55
+ [Changelog](https://github.com/therealnaveenkamal/plumbify/blob/main/CHANGELOG.md)
56
+
57
+ </div>
58
+
59
+ Language models are slow and inconsistent at the small judgements that fill real conversations: which team gets
60
+ this ticket, is this refund allowed, how urgent is it. Thinking helps, at the cost of seconds per decision.
61
+
62
+ Plumbify trains a small decision head, a **plumb**, onto an open model without changing its weights. With the
63
+ plugin installed, `vllm serve` loads the result like any other model. The model generates as usual, and when a
64
+ conversation reaches a decision, the plumb answers it in one forward pass, reading the KV cache the conversation
65
+ already filled, with a calibrated probability for every option.
66
+
67
+ **Faster, with thinking on.**
68
+
69
+ ![A refund case: the normal model and the plumbed model side by side, thinking on](docs/assets/refund.gif)
70
+
71
+ *Qwen3.5-35B-A3B, one server, real time, thinking on in both panes. A support case asks for two decisions: approve
72
+ the refund, and escalate to a manager. The normal model reasons both out in its thinking. The plumbed model hands
73
+ them to its plumb, which reads the conversation from the KV cache (the escalation call takes 116 ms and reuses 1,056
74
+ cached tokens). Both plumb answers come back with two options in their conformal set, which marks them as unsure, so
75
+ the model checks each one briefly before it replies. Both panes reach the same answer: approve, don't escalate. The
76
+ plumbed model finishes in 10.5 s, the normal model in 32.6 s, 3.1× faster. [Video (MP4)](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/assets/refund.mp4)*
77
+
78
+ **More accurate, with thinking off.**
79
+
80
+ ![An exam item: the normal model and the plumbed model side by side, thinking off](docs/assets/accuracy-thinking-off.gif)
81
+
82
+ *Qwen3.5-35B-A3B, thinking off in both panes. A grading item states a decision: what is the correct answer, given a
83
+ student's working? The normal model agrees with the student's wrong answer, d ($278.40). The plumb picks b
84
+ ($290.00), the correct answer, with probability 0.995 in 220 ms, and the model answers b. Both take under a
85
+ second. [Video (MP4)](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/assets/accuracy-thinking-off.mp4)*
86
+
87
+ **A plumb is a Jev model built into the LLM.** It answers the same kind of typed decision as a Jev-style decision
88
+ model such as TypeSafe's Jev: pick one of these options, yes or no, or a score on a scale. The difference is that it
89
+ is not a second model next to the LLM. It is a Jev decision head inside the model, sharing its weights and its KV
90
+ cache, so plumbifying a model is jevifying it.
91
+
92
+ ## Quickstart
93
+
94
+ Plumbify needs Linux, an NVIDIA GPU and Python 3.10 or later. The `vllm` extra installs vLLM 0.30.0, the version the
95
+ plugin is tested against.
96
+
97
+ ```bash
98
+ pip install "plumbify[vllm]"
99
+ ```
100
+
101
+ Train a plumb on a frozen base model, then serve the result:
102
+
103
+ ```bash
104
+ plumbify train --base Qwen/Qwen3.5-9B \
105
+ --rows train.jsonl --dev dev.jsonl --out plumbed-qwen3.5-9b
106
+ vllm serve plumbed-qwen3.5-9b
107
+ ```
108
+
109
+ Ask it a decision through the standard OpenAI API:
110
+
111
+ ```bash
112
+ curl -s localhost:8000/v1/chat/completions \
113
+ -H 'content-type: application/json' \
114
+ -d '{"model": "plumbed-qwen3.5-9b",
115
+ "messages": [{"role": "user", "content":
116
+ "Charged twice.\n\nWhich team?\n- billing\n- technical\n- sales"}]}' \
117
+ | jq -c .plumb.answer
118
+ ```
119
+
120
+ The response is a normal chat completion with an extra `plumb` field. Its `answer` says which option won, who
121
+ decided (`system1` is the plumb), and with what probability:
122
+
123
+ ```json
124
+ {"choice":"billing","by":"system1","p":0.973}
125
+ ```
126
+
127
+ The [guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) covers the training data format, the request options and the response fields.
128
+ `python scripts/demo_chat.py` opens a live chat that shows each decision as the model hands it off.
129
+
130
+ ## Results
131
+
132
+ The same model alone and with its plumb, on one vLLM server, over 447 held-out decisions (task families and
133
+ templates no model trained on). Each prompt states a decision: context, question, bulleted options.
134
+
135
+ | Model | No thinking: alone → plumbed | Thinking: alone → plumbed | Thinking latency p50: alone → plumbed |
136
+ | --------------------- | ---------------------------- | ------------------------- | ------------------------------------- |
137
+ | Qwen3.5-27B | 0.732 → **0.839** | 0.866 → **0.875** | 26.6 s → 17.1 s (1.6× faster) |
138
+ | Qwen3.5-35B-A3B (MoE) | 0.720 → **0.810** | 0.852 → **0.875** | 6.8 s → 2.8 s (2.4× faster) |
139
+ | Gemma 4 12B | 0.736 → **0.826** | 0.770 → **0.872** | 24.1 s → 5.0 s (4.8× faster) |
140
+ | Qwen3.5-9B | 0.696 → **0.779** | 0.808 → **0.846** | 28.0 s → 5.7 s (4.9× faster) |
141
+ | Qwen3.5-4B | 0.667 → **0.801** | **0.841** → 0.826 | 12.0 s → 3.8 s (3.1× faster) |
142
+ | Qwen3-1.7B | 0.570 → **0.658** | 0.642 → **0.707** | 3.9 s → 3.1 s (1.2× faster) |
143
+
144
+ Without thinking, the plumb adds 8 to 13 points on every model. With thinking, the plumbed model is at least as
145
+ accurate on five of six models (Qwen3.5-4B is within noise) and answers 1.2 to 4.9 times faster, because it thinks
146
+ 30 to 75% less: it hands the decision to the plumb instead of reasoning it all out. It also always answers, where
147
+ the model alone runs out of tokens or gives no clear answer on 5 to 15% of decisions when thinking. With 447
148
+ decisions, one standard error is about 2 points.
149
+
150
+ With thinking on, the model alone is scored in its better setup. These models think much less when their prompt
151
+ lists a tool (the plumbed model's prompt always lists `plumb_decide`), which is often but not always more accurate,
152
+ so each model alone gets whichever prompt, with or without a tool, scores higher. Settings, training time and
153
+ serving memory for each run are in [recipes/](https://github.com/therealnaveenkamal/plumbify/tree/main/recipes); the benchmark is
154
+ [`scripts/bench_s1_vs_s2.py`](https://github.com/therealnaveenkamal/plumbify/blob/main/scripts/bench_s1_vs_s2.py).
155
+
156
+ ## How it works
157
+
158
+ Take a support chat that reaches a decision: *which team should handle this ticket: billing, technical or sales?*
159
+
160
+ 1. **The question is added to the conversation.** The question and the three options are appended, written like a
161
+ normal message to the model.
162
+ 2. **The model reads only the new part.** It has already read the conversation, and that work is cached, so only the
163
+ few words of the question are processed.
164
+ 3. **The plumb scores the options.** It looks at what the model computed while reading the question and turns that
165
+ into a probability per option: billing 0.97, technical 0.02, sales 0.01.
166
+ 4. **The model carries on.** No text was generated for the decision. The model uses the answer and continues its
167
+ reply.
168
+
169
+ ```
170
+ conversation so far (cached) + "Which team? billing / technical / sales" → plumb → billing 0.97
171
+ ```
172
+
173
+ Training adds two small pieces and nothing else: the plumb itself, and an adapter that switches on only while the
174
+ model reads a decision question. The model's own weights never change, so everything else it does (chat, reasoning,
175
+ tools) works exactly as before. [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) explains each piece and where it lives in the
176
+ code.
177
+
178
+ ## Documentation
179
+
180
+ | Document | Covers |
181
+ | ----------------------------------------- | ------------------------------------------------------------------------- |
182
+ | [Guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) | Install, training data, the `plumbify` commands, the serving API, limits |
183
+ | [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) | How training and serving fit together, the invariants, a map of the code |
184
+ | [Recipes](https://github.com/therealnaveenkamal/plumbify/blob/main/recipes/README.md) | Tested settings and measured results for each model |
185
+ | [Scripts](https://github.com/therealnaveenkamal/plumbify/blob/main/scripts/README.md) | Benchmark, vLLM parity check, live chat |
186
+ | [Contributing](https://github.com/therealnaveenkamal/plumbify/blob/main/CONTRIBUTING.md) | Development setup, tests, conventions |
187
+
188
+ ## Development
189
+
190
+ ```bash
191
+ pip install -e ".[dev]" && pre-commit install
192
+ pytest -q tests
193
+ ruff check . && ruff format --check .
194
+ ```
195
+
196
+ The tests run on CPU in seconds with a tiny random model and don't need vLLM. See [CONTRIBUTING.md](https://github.com/therealnaveenkamal/plumbify/blob/main/CONTRIBUTING.md).
197
+
198
+ ## Citation
199
+
200
+ ```bibtex
201
+ @misc{plumbify2026,
202
+ title = {Plumbify: a System 1 decision branch for open
203
+ language models},
204
+ author = {Kamalakannan, Naveenraj},
205
+ year = {2026},
206
+ url = {https://github.com/therealnaveenkamal/plumbify}
207
+ }
208
+ ```
209
+
210
+ ## License
211
+
212
+ [Apache-2.0](https://github.com/therealnaveenkamal/plumbify/blob/main/LICENSE).
@@ -0,0 +1,171 @@
1
+ <div align="center">
2
+
3
+ # Plumbify
4
+
5
+ **Give an open LLM a fast decision path, then serve it with vLLM.**
6
+
7
+ [![CI](https://github.com/therealnaveenkamal/plumbify/actions/workflows/ci.yml/badge.svg)](https://github.com/therealnaveenkamal/plumbify/actions/workflows/ci.yml)
8
+ [![PyPI](https://img.shields.io/pypi/v/plumbify.svg)](https://pypi.org/project/plumbify/)
9
+ [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://github.com/therealnaveenkamal/plumbify/blob/main/LICENSE)
10
+ [![Python](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://github.com/therealnaveenkamal/plumbify/blob/main/pyproject.toml)
11
+ [![vLLM](https://img.shields.io/badge/vLLM-0.30.0-purple.svg)](https://github.com/vllm-project/vllm)
12
+
13
+ [Guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) · [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) · [Recipes](https://github.com/therealnaveenkamal/plumbify/tree/main/recipes) · [Results](#results) ·
14
+ [Changelog](https://github.com/therealnaveenkamal/plumbify/blob/main/CHANGELOG.md)
15
+
16
+ </div>
17
+
18
+ Language models are slow and inconsistent at the small judgements that fill real conversations: which team gets
19
+ this ticket, is this refund allowed, how urgent is it. Thinking helps, at the cost of seconds per decision.
20
+
21
+ Plumbify trains a small decision head, a **plumb**, onto an open model without changing its weights. With the
22
+ plugin installed, `vllm serve` loads the result like any other model. The model generates as usual, and when a
23
+ conversation reaches a decision, the plumb answers it in one forward pass, reading the KV cache the conversation
24
+ already filled, with a calibrated probability for every option.
25
+
26
+ **Faster, with thinking on.**
27
+
28
+ ![A refund case: the normal model and the plumbed model side by side, thinking on](docs/assets/refund.gif)
29
+
30
+ *Qwen3.5-35B-A3B, one server, real time, thinking on in both panes. A support case asks for two decisions: approve
31
+ the refund, and escalate to a manager. The normal model reasons both out in its thinking. The plumbed model hands
32
+ them to its plumb, which reads the conversation from the KV cache (the escalation call takes 116 ms and reuses 1,056
33
+ cached tokens). Both plumb answers come back with two options in their conformal set, which marks them as unsure, so
34
+ the model checks each one briefly before it replies. Both panes reach the same answer: approve, don't escalate. The
35
+ plumbed model finishes in 10.5 s, the normal model in 32.6 s, 3.1× faster. [Video (MP4)](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/assets/refund.mp4)*
36
+
37
+ **More accurate, with thinking off.**
38
+
39
+ ![An exam item: the normal model and the plumbed model side by side, thinking off](docs/assets/accuracy-thinking-off.gif)
40
+
41
+ *Qwen3.5-35B-A3B, thinking off in both panes. A grading item states a decision: what is the correct answer, given a
42
+ student's working? The normal model agrees with the student's wrong answer, d ($278.40). The plumb picks b
43
+ ($290.00), the correct answer, with probability 0.995 in 220 ms, and the model answers b. Both take under a
44
+ second. [Video (MP4)](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/assets/accuracy-thinking-off.mp4)*
45
+
46
+ **A plumb is a Jev model built into the LLM.** It answers the same kind of typed decision as a Jev-style decision
47
+ model such as TypeSafe's Jev: pick one of these options, yes or no, or a score on a scale. The difference is that it
48
+ is not a second model next to the LLM. It is a Jev decision head inside the model, sharing its weights and its KV
49
+ cache, so plumbifying a model is jevifying it.
50
+
51
+ ## Quickstart
52
+
53
+ Plumbify needs Linux, an NVIDIA GPU and Python 3.10 or later. The `vllm` extra installs vLLM 0.30.0, the version the
54
+ plugin is tested against.
55
+
56
+ ```bash
57
+ pip install "plumbify[vllm]"
58
+ ```
59
+
60
+ Train a plumb on a frozen base model, then serve the result:
61
+
62
+ ```bash
63
+ plumbify train --base Qwen/Qwen3.5-9B \
64
+ --rows train.jsonl --dev dev.jsonl --out plumbed-qwen3.5-9b
65
+ vllm serve plumbed-qwen3.5-9b
66
+ ```
67
+
68
+ Ask it a decision through the standard OpenAI API:
69
+
70
+ ```bash
71
+ curl -s localhost:8000/v1/chat/completions \
72
+ -H 'content-type: application/json' \
73
+ -d '{"model": "plumbed-qwen3.5-9b",
74
+ "messages": [{"role": "user", "content":
75
+ "Charged twice.\n\nWhich team?\n- billing\n- technical\n- sales"}]}' \
76
+ | jq -c .plumb.answer
77
+ ```
78
+
79
+ The response is a normal chat completion with an extra `plumb` field. Its `answer` says which option won, who
80
+ decided (`system1` is the plumb), and with what probability:
81
+
82
+ ```json
83
+ {"choice":"billing","by":"system1","p":0.973}
84
+ ```
85
+
86
+ The [guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) covers the training data format, the request options and the response fields.
87
+ `python scripts/demo_chat.py` opens a live chat that shows each decision as the model hands it off.
88
+
89
+ ## Results
90
+
91
+ The same model alone and with its plumb, on one vLLM server, over 447 held-out decisions (task families and
92
+ templates no model trained on). Each prompt states a decision: context, question, bulleted options.
93
+
94
+ | Model | No thinking: alone → plumbed | Thinking: alone → plumbed | Thinking latency p50: alone → plumbed |
95
+ | --------------------- | ---------------------------- | ------------------------- | ------------------------------------- |
96
+ | Qwen3.5-27B | 0.732 → **0.839** | 0.866 → **0.875** | 26.6 s → 17.1 s (1.6× faster) |
97
+ | Qwen3.5-35B-A3B (MoE) | 0.720 → **0.810** | 0.852 → **0.875** | 6.8 s → 2.8 s (2.4× faster) |
98
+ | Gemma 4 12B | 0.736 → **0.826** | 0.770 → **0.872** | 24.1 s → 5.0 s (4.8× faster) |
99
+ | Qwen3.5-9B | 0.696 → **0.779** | 0.808 → **0.846** | 28.0 s → 5.7 s (4.9× faster) |
100
+ | Qwen3.5-4B | 0.667 → **0.801** | **0.841** → 0.826 | 12.0 s → 3.8 s (3.1× faster) |
101
+ | Qwen3-1.7B | 0.570 → **0.658** | 0.642 → **0.707** | 3.9 s → 3.1 s (1.2× faster) |
102
+
103
+ Without thinking, the plumb adds 8 to 13 points on every model. With thinking, the plumbed model is at least as
104
+ accurate on five of six models (Qwen3.5-4B is within noise) and answers 1.2 to 4.9 times faster, because it thinks
105
+ 30 to 75% less: it hands the decision to the plumb instead of reasoning it all out. It also always answers, where
106
+ the model alone runs out of tokens or gives no clear answer on 5 to 15% of decisions when thinking. With 447
107
+ decisions, one standard error is about 2 points.
108
+
109
+ With thinking on, the model alone is scored in its better setup. These models think much less when their prompt
110
+ lists a tool (the plumbed model's prompt always lists `plumb_decide`), which is often but not always more accurate,
111
+ so each model alone gets whichever prompt, with or without a tool, scores higher. Settings, training time and
112
+ serving memory for each run are in [recipes/](https://github.com/therealnaveenkamal/plumbify/tree/main/recipes); the benchmark is
113
+ [`scripts/bench_s1_vs_s2.py`](https://github.com/therealnaveenkamal/plumbify/blob/main/scripts/bench_s1_vs_s2.py).
114
+
115
+ ## How it works
116
+
117
+ Take a support chat that reaches a decision: *which team should handle this ticket: billing, technical or sales?*
118
+
119
+ 1. **The question is added to the conversation.** The question and the three options are appended, written like a
120
+ normal message to the model.
121
+ 2. **The model reads only the new part.** It has already read the conversation, and that work is cached, so only the
122
+ few words of the question are processed.
123
+ 3. **The plumb scores the options.** It looks at what the model computed while reading the question and turns that
124
+ into a probability per option: billing 0.97, technical 0.02, sales 0.01.
125
+ 4. **The model carries on.** No text was generated for the decision. The model uses the answer and continues its
126
+ reply.
127
+
128
+ ```
129
+ conversation so far (cached) + "Which team? billing / technical / sales" → plumb → billing 0.97
130
+ ```
131
+
132
+ Training adds two small pieces and nothing else: the plumb itself, and an adapter that switches on only while the
133
+ model reads a decision question. The model's own weights never change, so everything else it does (chat, reasoning,
134
+ tools) works exactly as before. [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) explains each piece and where it lives in the
135
+ code.
136
+
137
+ ## Documentation
138
+
139
+ | Document | Covers |
140
+ | ----------------------------------------- | ------------------------------------------------------------------------- |
141
+ | [Guide](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/guide.md) | Install, training data, the `plumbify` commands, the serving API, limits |
142
+ | [Architecture](https://github.com/therealnaveenkamal/plumbify/blob/main/docs/architecture.md) | How training and serving fit together, the invariants, a map of the code |
143
+ | [Recipes](https://github.com/therealnaveenkamal/plumbify/blob/main/recipes/README.md) | Tested settings and measured results for each model |
144
+ | [Scripts](https://github.com/therealnaveenkamal/plumbify/blob/main/scripts/README.md) | Benchmark, vLLM parity check, live chat |
145
+ | [Contributing](https://github.com/therealnaveenkamal/plumbify/blob/main/CONTRIBUTING.md) | Development setup, tests, conventions |
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ pip install -e ".[dev]" && pre-commit install
151
+ pytest -q tests
152
+ ruff check . && ruff format --check .
153
+ ```
154
+
155
+ The tests run on CPU in seconds with a tiny random model and don't need vLLM. See [CONTRIBUTING.md](https://github.com/therealnaveenkamal/plumbify/blob/main/CONTRIBUTING.md).
156
+
157
+ ## Citation
158
+
159
+ ```bibtex
160
+ @misc{plumbify2026,
161
+ title = {Plumbify: a System 1 decision branch for open
162
+ language models},
163
+ author = {Kamalakannan, Naveenraj},
164
+ year = {2026},
165
+ url = {https://github.com/therealnaveenkamal/plumbify}
166
+ }
167
+ ```
168
+
169
+ ## License
170
+
171
+ [Apache-2.0](https://github.com/therealnaveenkamal/plumbify/blob/main/LICENSE).
@@ -0,0 +1,20 @@
1
+ """Plumbify: a fast decision path (System 1) for open language models, served natively by vLLM.
2
+
3
+ plumbify train --base Qwen/Qwen3.5-9B --rows train.jsonl --dev dev.jsonl --out plumbed-qwen3.5-9b
4
+ vllm serve plumbed-qwen3.5-9b
5
+
6
+ In Python, ``System1`` runs a plumb with transformers (training, evaluation, the reference implementation).
7
+ """
8
+
9
+ __version__ = "0.2.0"
10
+
11
+
12
+ def __getattr__(name): # System1 pulls in torch and transformers: load it on first use
13
+ if name == "System1":
14
+ from .system1 import System1
15
+
16
+ return System1
17
+ raise AttributeError(name)
18
+
19
+
20
+ __all__ = ["System1", "__version__"]