gemmadecision 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 (52) hide show
  1. gemmadecision-0.1.0/.gitignore +22 -0
  2. gemmadecision-0.1.0/LICENSE +202 -0
  3. gemmadecision-0.1.0/NOTICE +16 -0
  4. gemmadecision-0.1.0/PKG-INFO +156 -0
  5. gemmadecision-0.1.0/README.md +99 -0
  6. gemmadecision-0.1.0/docs/advanced.md +174 -0
  7. gemmadecision-0.1.0/docs/measurements/PROVENANCE.json +78 -0
  8. gemmadecision-0.1.0/docs/measurements/h100-backend-compute.json +12 -0
  9. gemmadecision-0.1.0/docs/measurements/h100-backend-source-hashes.json +21 -0
  10. gemmadecision-0.1.0/docs/measurements/h100-backend.json +2246 -0
  11. gemmadecision-0.1.0/docs/measurements/h100-http-compute.json +11 -0
  12. gemmadecision-0.1.0/docs/measurements/h100-http-source-hashes.json +21 -0
  13. gemmadecision-0.1.0/docs/measurements/h100-http.json +292 -0
  14. gemmadecision-0.1.0/docs/measurements/vllm-compute.json +12 -0
  15. gemmadecision-0.1.0/docs/measurements/vllm-h100-backend.json +2868 -0
  16. gemmadecision-0.1.0/docs/measurements/vllm-h100-http.json +298 -0
  17. gemmadecision-0.1.0/docs/measurements/vllm-runtime-notes.json +32 -0
  18. gemmadecision-0.1.0/docs/measurements/vllm-source-hashes.json +21 -0
  19. gemmadecision-0.1.0/docs/performance.md +262 -0
  20. gemmadecision-0.1.0/docs/pydantic_ai.md +154 -0
  21. gemmadecision-0.1.0/docs/releasing.md +87 -0
  22. gemmadecision-0.1.0/docs/vllm.md +110 -0
  23. gemmadecision-0.1.0/examples/pydantic_ai_router.py +34 -0
  24. gemmadecision-0.1.0/pyproject.toml +52 -0
  25. gemmadecision-0.1.0/python/gemmadecision/__init__.py +42 -0
  26. gemmadecision-0.1.0/python/gemmadecision/_clm_schema.py +166 -0
  27. gemmadecision-0.1.0/python/gemmadecision/backends/__init__.py +1 -0
  28. gemmadecision-0.1.0/python/gemmadecision/backends/torch.py +266 -0
  29. gemmadecision-0.1.0/python/gemmadecision/backends/vllm.py +144 -0
  30. gemmadecision-0.1.0/python/gemmadecision/batching.py +145 -0
  31. gemmadecision-0.1.0/python/gemmadecision/cli.py +73 -0
  32. gemmadecision-0.1.0/python/gemmadecision/client.py +114 -0
  33. gemmadecision-0.1.0/python/gemmadecision/constants.py +6 -0
  34. gemmadecision-0.1.0/python/gemmadecision/engine.py +244 -0
  35. gemmadecision-0.1.0/python/gemmadecision/export_vllm.py +121 -0
  36. gemmadecision-0.1.0/python/gemmadecision/integrations/__init__.py +1 -0
  37. gemmadecision-0.1.0/python/gemmadecision/integrations/pydantic_ai.py +331 -0
  38. gemmadecision-0.1.0/python/gemmadecision/model.py +16 -0
  39. gemmadecision-0.1.0/python/gemmadecision/py.typed +0 -0
  40. gemmadecision-0.1.0/python/gemmadecision/server.py +119 -0
  41. gemmadecision-0.1.0/python/gemmadecision/simple.py +17 -0
  42. gemmadecision-0.1.0/python/gemmadecision/types.py +102 -0
  43. gemmadecision-0.1.0/scripts/benchmark_backends.py +366 -0
  44. gemmadecision-0.1.0/scripts/benchmark_server.py +383 -0
  45. gemmadecision-0.1.0/tests/test_audit_regressions.py +71 -0
  46. gemmadecision-0.1.0/tests/test_cli.py +56 -0
  47. gemmadecision-0.1.0/tests/test_engine_client.py +366 -0
  48. gemmadecision-0.1.0/tests/test_pydantic_ai.py +424 -0
  49. gemmadecision-0.1.0/tests/test_server_batching.py +331 -0
  50. gemmadecision-0.1.0/tests/test_simple_api.py +71 -0
  51. gemmadecision-0.1.0/tests/test_torch_backend.py +159 -0
  52. gemmadecision-0.1.0/tests/test_vllm.py +111 -0
@@ -0,0 +1,22 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .mypy_cache/
5
+ .ruff_cache/
6
+ .coverage
7
+ htmlcov/
8
+ dist/
9
+ build/
10
+ *.egg-info/
11
+ .venv/
12
+ venv/
13
+ .DS_Store
14
+ .env
15
+ .env.*
16
+ !.env.example
17
+ hf_token*
18
+ *.safetensors
19
+ *.bin
20
+ models/
21
+ .cache/
22
+ *.log
@@ -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,16 @@
1
+ GemmaDecision serving package
2
+ Copyright 2026 Rajan Shukla
3
+
4
+ python/gemmadecision/_clm_schema.py is derived from Contrastive-LM/CLM,
5
+ revision e939398d4556fcd9400c76fa8c5a513202f42b0a, Apache License 2.0.
6
+ https://github.com/Contrastive-LM/CLM
7
+ Other serving code is original to this package.
8
+
9
+ Granian supplies the Rust HTTP server (BSD-3-Clause); Pydantic Core supplies
10
+ Rust-backed data validation (MIT). PyTorch/vLLM execute model tensor operations.
11
+ Dependencies retain their respective licenses. This package is not an all-Rust
12
+ model implementation and does not claim endorsement by upstream projects.
13
+
14
+ Model weights are downloaded separately from rajan2k/GemmaDecision-270M.
15
+ They are modified Google Gemma weights governed by the Gemma terms and
16
+ Prohibited Use Policy in that repository, not this package's code license.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: gemmadecision
3
+ Version: 0.1.0
4
+ Summary: Typed local decisions for PydanticAI, with Rust HTTP serving and batched Gemma inference
5
+ Project-URL: Homepage, https://github.com/rjn32s/gemmadecision
6
+ Project-URL: Repository, https://github.com/rjn32s/gemmadecision
7
+ Project-URL: Issues, https://github.com/rjn32s/gemmadecision/issues
8
+ Project-URL: Model, https://huggingface.co/rajan2k/GemmaDecision-270M
9
+ Author: Rajan Shukla
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: decision-model,gemma,granian,pydantic-ai,vllm
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: fastapi<0.137,>=0.133
21
+ Requires-Dist: granian<3,>=2.8
22
+ Requires-Dist: httpx<1,>=0.28
23
+ Requires-Dist: huggingface-hub<2,>=1.33
24
+ Requires-Dist: numpy<3,>=2
25
+ Requires-Dist: pydantic-ai-slim<3,>=2.51
26
+ Requires-Dist: pydantic<3,>=2.12
27
+ Requires-Dist: safetensors<1,>=0.8
28
+ Requires-Dist: torch<2.15,>=2.13
29
+ Requires-Dist: transformers<6,>=5.17
30
+ Provides-Extra: http
31
+ Requires-Dist: fastapi<0.137,>=0.133; extra == 'http'
32
+ Requires-Dist: granian<3,>=2.8; extra == 'http'
33
+ Provides-Extra: pydantic-ai
34
+ Requires-Dist: pydantic-ai-slim<3,>=2.51; extra == 'pydantic-ai'
35
+ Provides-Extra: serve
36
+ Requires-Dist: fastapi<0.137,>=0.133; extra == 'serve'
37
+ Requires-Dist: granian<3,>=2.8; extra == 'serve'
38
+ Requires-Dist: huggingface-hub<2,>=1.33; extra == 'serve'
39
+ Requires-Dist: numpy<3,>=2; extra == 'serve'
40
+ Requires-Dist: safetensors<1,>=0.8; extra == 'serve'
41
+ Requires-Dist: torch<2.15,>=2.13; extra == 'serve'
42
+ Requires-Dist: transformers<6,>=5.17; extra == 'serve'
43
+ Provides-Extra: test
44
+ Requires-Dist: asgi-lifespan<3,>=2; extra == 'test'
45
+ Requires-Dist: build<2,>=1; extra == 'test'
46
+ Requires-Dist: fastapi<0.137,>=0.133; extra == 'test'
47
+ Requires-Dist: granian<3,>=2.8; extra == 'test'
48
+ Requires-Dist: pytest-asyncio<2,>=1; extra == 'test'
49
+ Requires-Dist: pytest<10,>=8; extra == 'test'
50
+ Requires-Dist: twine<7,>=6; extra == 'test'
51
+ Provides-Extra: vllm
52
+ Requires-Dist: fastapi<0.137,>=0.133; extra == 'vllm'
53
+ Requires-Dist: granian<3,>=2.8; extra == 'vllm'
54
+ Requires-Dist: transformers<6,>=5.17; extra == 'vllm'
55
+ Requires-Dist: vllm==0.30.0; extra == 'vllm'
56
+ Description-Content-Type: text/markdown
57
+
58
+ # gemmadecision
59
+
60
+ Small, local decisions in one Python call. Powered by
61
+ [GemmaDecision-270M](https://huggingface.co/rajan2k/GemmaDecision-270M).
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install gemmadecision
67
+ ```
68
+
69
+ Python 3.11+. No API key or server needed. The first call downloads the model
70
+ (about 0.5 GB); later calls reuse it. CPU, NVIDIA CUDA and Apple Silicon are
71
+ selected automatically. After downloading, inference runs locally.
72
+
73
+ ## Use it in your code
74
+
75
+ ```python
76
+ from gemmadecision import decide
77
+
78
+ team = decide("I was charged twice", choices=["billing", "technical"])
79
+ print(team) # selected choice, as a string
80
+ ```
81
+
82
+ For more specific decisions, give each choice a description:
83
+
84
+ ```python
85
+ team = decide(
86
+ "The same payment appears twice on my statement.",
87
+ choices={
88
+ "billing": "Handle charges, payments and refunds",
89
+ "technical": "Handle crashes, login errors and app problems",
90
+ },
91
+ question="Which support team should handle this request?",
92
+ )
93
+ ```
94
+
95
+ Need the full ranking? Use `rank(...)` with the same arguments. It returns
96
+ ordered candidates, scores and derived probabilities.
97
+
98
+ ## PydanticAI
99
+
100
+ ```python
101
+ from typing import Literal
102
+ from pydantic_ai import Agent
103
+ from gemmadecision import GemmaDecisionModel
104
+
105
+ agent = Agent(
106
+ GemmaDecisionModel.local(),
107
+ output_type=Literal["billing", "technical"],
108
+ )
109
+ result = agent.run_sync("I was charged twice")
110
+ print(result.output)
111
+ ```
112
+
113
+ This uses PydanticAI's native decision-model interface. Boolean, enum, rubric
114
+ and finite Pydantic fields are supported.
115
+ [More PydanticAI examples](https://github.com/rjn32s/gemmadecision/blob/main/docs/pydantic_ai.md).
116
+
117
+ ## Serve it
118
+
119
+ ```bash
120
+ gemmadecision serve
121
+ ```
122
+
123
+ That starts the Rust-powered Granian HTTP server at `http://127.0.0.1:8700`.
124
+ Interactive API documentation is available at `/docs`.
125
+
126
+ ```python
127
+ from gemmadecision import DecisionClient
128
+
129
+ with DecisionClient() as client:
130
+ result = client.decide(
131
+ "I was charged twice",
132
+ candidates={"billing": "Payments and refunds", "technical": "App problems"},
133
+ )
134
+ print(result.choice)
135
+ ```
136
+
137
+ `AsyncDecisionClient` works with `await`. To connect PydanticAI to the server,
138
+ use `GemmaDecisionModel()` instead of `.local()`.
139
+
140
+ ## More control when you need it
141
+
142
+ - [Hardware settings, offline use, HTTP API and batching](https://github.com/rjn32s/gemmadecision/blob/main/docs/advanced.md)
143
+ - [vLLM backend for Linux/CUDA](https://github.com/rjn32s/gemmadecision/blob/main/docs/vllm.md)
144
+ - [Performance measurements and reproduction](https://github.com/rjn32s/gemmadecision/blob/main/docs/performance.md)
145
+ - [Docker and releases](https://github.com/rjn32s/gemmadecision/blob/main/docs/releasing.md)
146
+
147
+ The default uses batched PyTorch for model computation and Rust for HTTP
148
+ serving. vLLM is optional; no Rust compiler is needed to install the package.
149
+
150
+ This model chooses among supplied options; it does not generate open-ended
151
+ text. Its scores are rankings, and the derived probabilities are not a guarantee
152
+ of correctness. Maximums are 2,048 state/question tokens, 768 tokens per choice
153
+ and 64 choices. See the [model card](https://huggingface.co/rajan2k/GemmaDecision-270M)
154
+ for evaluation and limitations.
155
+
156
+ Code: Apache-2.0. Model weights: separate Gemma terms. See [NOTICE](https://github.com/rjn32s/gemmadecision/blob/main/NOTICE).
@@ -0,0 +1,99 @@
1
+ # gemmadecision
2
+
3
+ Small, local decisions in one Python call. Powered by
4
+ [GemmaDecision-270M](https://huggingface.co/rajan2k/GemmaDecision-270M).
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pip install gemmadecision
10
+ ```
11
+
12
+ Python 3.11+. No API key or server needed. The first call downloads the model
13
+ (about 0.5 GB); later calls reuse it. CPU, NVIDIA CUDA and Apple Silicon are
14
+ selected automatically. After downloading, inference runs locally.
15
+
16
+ ## Use it in your code
17
+
18
+ ```python
19
+ from gemmadecision import decide
20
+
21
+ team = decide("I was charged twice", choices=["billing", "technical"])
22
+ print(team) # selected choice, as a string
23
+ ```
24
+
25
+ For more specific decisions, give each choice a description:
26
+
27
+ ```python
28
+ team = decide(
29
+ "The same payment appears twice on my statement.",
30
+ choices={
31
+ "billing": "Handle charges, payments and refunds",
32
+ "technical": "Handle crashes, login errors and app problems",
33
+ },
34
+ question="Which support team should handle this request?",
35
+ )
36
+ ```
37
+
38
+ Need the full ranking? Use `rank(...)` with the same arguments. It returns
39
+ ordered candidates, scores and derived probabilities.
40
+
41
+ ## PydanticAI
42
+
43
+ ```python
44
+ from typing import Literal
45
+ from pydantic_ai import Agent
46
+ from gemmadecision import GemmaDecisionModel
47
+
48
+ agent = Agent(
49
+ GemmaDecisionModel.local(),
50
+ output_type=Literal["billing", "technical"],
51
+ )
52
+ result = agent.run_sync("I was charged twice")
53
+ print(result.output)
54
+ ```
55
+
56
+ This uses PydanticAI's native decision-model interface. Boolean, enum, rubric
57
+ and finite Pydantic fields are supported.
58
+ [More PydanticAI examples](https://github.com/rjn32s/gemmadecision/blob/main/docs/pydantic_ai.md).
59
+
60
+ ## Serve it
61
+
62
+ ```bash
63
+ gemmadecision serve
64
+ ```
65
+
66
+ That starts the Rust-powered Granian HTTP server at `http://127.0.0.1:8700`.
67
+ Interactive API documentation is available at `/docs`.
68
+
69
+ ```python
70
+ from gemmadecision import DecisionClient
71
+
72
+ with DecisionClient() as client:
73
+ result = client.decide(
74
+ "I was charged twice",
75
+ candidates={"billing": "Payments and refunds", "technical": "App problems"},
76
+ )
77
+ print(result.choice)
78
+ ```
79
+
80
+ `AsyncDecisionClient` works with `await`. To connect PydanticAI to the server,
81
+ use `GemmaDecisionModel()` instead of `.local()`.
82
+
83
+ ## More control when you need it
84
+
85
+ - [Hardware settings, offline use, HTTP API and batching](https://github.com/rjn32s/gemmadecision/blob/main/docs/advanced.md)
86
+ - [vLLM backend for Linux/CUDA](https://github.com/rjn32s/gemmadecision/blob/main/docs/vllm.md)
87
+ - [Performance measurements and reproduction](https://github.com/rjn32s/gemmadecision/blob/main/docs/performance.md)
88
+ - [Docker and releases](https://github.com/rjn32s/gemmadecision/blob/main/docs/releasing.md)
89
+
90
+ The default uses batched PyTorch for model computation and Rust for HTTP
91
+ serving. vLLM is optional; no Rust compiler is needed to install the package.
92
+
93
+ This model chooses among supplied options; it does not generate open-ended
94
+ text. Its scores are rankings, and the derived probabilities are not a guarantee
95
+ of correctness. Maximums are 2,048 state/question tokens, 768 tokens per choice
96
+ and 64 choices. See the [model card](https://huggingface.co/rajan2k/GemmaDecision-270M)
97
+ for evaluation and limitations.
98
+
99
+ Code: Apache-2.0. Model weights: separate Gemma terms. See [NOTICE](https://github.com/rjn32s/gemmadecision/blob/main/NOTICE).
@@ -0,0 +1,174 @@
1
+ # gemmadecision
2
+
3
+ Typed local decisions for Python and PydanticAI. One command serves the complete
4
+ [GemmaDecision-270M](https://huggingface.co/rajan2k/GemmaDecision-270M) model with
5
+ Granian's **Rust HTTP runtime**, bounded request queues and batched inference.
6
+ Importing the client does not load PyTorch or download weights.
7
+
8
+ ```sh
9
+ pip install gemmadecision
10
+ gemmadecision serve
11
+ ```
12
+
13
+ The first server start downloads the pinned public model (about 0.5 GB). Subsequent
14
+ starts use the cache. CPU, CUDA and Apple MPS are selected automatically; override
15
+ with `--device cpu`, `--device cuda`, or `--device mps`. Model inference stays local.
16
+ The client and native PydanticAI integration work without an external LLM API key.
17
+
18
+ ## Python
19
+
20
+ ```python
21
+ from gemmadecision import DecisionClient
22
+
23
+ with DecisionClient() as client:
24
+ answer = client.decide(
25
+ "The same card payment appears twice on my statement.",
26
+ candidates={
27
+ "billing": "Investigate duplicate payments, charges and refunds.",
28
+ "technical": "Investigate app crashes and login errors.",
29
+ },
30
+ question="Which support team should handle this request?",
31
+ )
32
+ print(answer.choice)
33
+ print(answer.probabilities)
34
+ ```
35
+
36
+ Use `AsyncDecisionClient` with `async with` and `await` in async applications.
37
+ Clients reuse HTTP connections and do not retry decisions automatically. Set
38
+ `base_url`, `api_key` and `timeout` explicitly or use `GEMMADECISION_BASE_URL` and
39
+ `GEMMADECISION_API_KEY`. The standard install includes the local runtime; importing only the client stays lightweight.
40
+
41
+ ## PydanticAI, directly
42
+
43
+ PydanticAI has a native decision-model interface: no chatbot shim is needed.
44
+
45
+ ```python
46
+ import asyncio
47
+ from typing import Literal
48
+ from pydantic import BaseModel, Field
49
+ from pydantic_ai import Agent
50
+ from gemmadecision.integrations.pydantic_ai import GemmaDecisionModel
51
+
52
+ class Route(BaseModel):
53
+ department: Literal["billing", "technical"] = Field(
54
+ description="Team responsible for this request: billing handles payments; technical handles app failures."
55
+ )
56
+
57
+ async def main():
58
+ async with GemmaDecisionModel() as model:
59
+ agent = Agent(model, output_type=Route)
60
+ result = await agent.run("The same card payment appears twice on my statement.")
61
+ print(result.output)
62
+
63
+ asyncio.run(main())
64
+ ```
65
+
66
+ Finite `Literal`, `Enum`, boolean and rubric outputs are supported. This model
67
+ selects among supplied alternatives; it does not generate arbitrary prose,
68
+ extract unrestricted strings or replace a general language model. See
69
+ [PydanticAI integration](pydantic_ai.md) for routing, rubrics and fallbacks.
70
+
71
+ ## Several typed decisions in one request
72
+
73
+ ```python
74
+ from gemmadecision import DecisionClient, Choice, Noul, Score
75
+
76
+ with DecisionClient() as client:
77
+ result = client.system_one(
78
+ state="The app crashed three times today and I cannot sign in.",
79
+ questions={
80
+ "team": Choice(instructions="Who should handle this?", criteria={
81
+ "technical": "App crashes and login problems", "billing": "Charges and refunds"}),
82
+ "needs_help": Noul(instructions="Does this customer need assistance?"),
83
+ "urgency": Score(instructions="How urgent is the request?",
84
+ criteria=["Can wait", "Needs attention", "Blocked and needs prompt help"]),
85
+ },
86
+ )
87
+ print(result.answers)
88
+ ```
89
+
90
+ `client.rank(state, candidates, question=...)` exposes raw scores and their fixed
91
+ softmax transformation. For in-process inference use
92
+ `DecisionEngine.from_pretrained(device="auto")` with the same `decide`, `rank` and
93
+ `system_one` methods. It loads only when explicitly constructed.
94
+
95
+ ## Serving choices
96
+
97
+ - **Default:** Granian Rust HTTP + batched PyTorch. Length-bucketed candidate
98
+ batches, bounded cross-request microbatching, one model process, no generation.
99
+ - **Reference:** `gemmadecision serve --strict --batch-wait-ms 0` scores each
100
+ candidate separately, matching the published numerical execution shape.
101
+ - **vLLM:** `pip install 'gemmadecision[vllm]'` in a separate Linux CUDA environment,
102
+ then `gemmadecision serve --backend vllm --device cuda`. See the exact dependency
103
+ pins and evaluation status in [vLLM setup](vllm.md).
104
+ - **Offline:** `gemmadecision download --output ./model`, then
105
+ `gemmadecision serve --model-path ./model --offline`.
106
+ - **Docker:** see [release and container instructions](releasing.md).
107
+
108
+ The serving process uses Rust for HTTP transport and Rust-backed Pydantic
109
+ validation. Model tensor operations use PyTorch or vLLM's native CUDA kernels;
110
+ this is not an all-Rust reimplementation of Gemma. Granian supplies maintained
111
+ binary wheels so users do not need to compile a new bespoke Rust server.
112
+
113
+ CLM's vLLM encoder/API design inspired this separation. This model is a **joint
114
+ ranker**: the entire state, question and candidate must be encoded together.
115
+ Caching independent action embeddings would change its predictions. Optional
116
+ `--cache-size 1024` caches only exact full-input scores in memory; it is off by
117
+ default. Cache keys are SHA256 digests, and no persistent prompt cache is written.
118
+
119
+ `--max-batch-tokens`, `--max-batch-size`, `--batch-wait-ms` and `--queue-size`
120
+ control memory and throughput. Start with the defaults. Batching can introduce
121
+ small numerical differences, especially near ties; see [performance notes](performance.md).
122
+ No universal speed multiplier or JEV-equivalent accuracy is claimed.
123
+
124
+ ## HTTP interface
125
+
126
+ `POST /v1/systemone`, `POST /v1/rank`, `GET /v1/models`, `GET /health`, `GET /ready`.
127
+ Interactive OpenAPI documentation is at `http://127.0.0.1:8700/docs`.
128
+ The default bind address is loopback. To expose on a private network, set
129
+ `GEMMADECISION_API_KEY` and use `--host 0.0.0.0`. Put a TLS reverse proxy in front
130
+ of any internet-facing deployment. An explicit `--allow-unauthenticated` flag
131
+ exists for controlled deployments. HTTP request-content logs are disabled.
132
+
133
+ Maximum input: 2,048 state/question tokens; 768 tokens per candidate; 2–64
134
+ distinct candidates per question; 32 questions and 256 total pairs per request;
135
+ 2 MiB request body. Inputs are refused with HTTP 422 rather than silently
136
+ truncated. Overload returns 503; queue timeout returns 504. Health is independent
137
+ of inference authorization and includes no request text. There is one bounded
138
+ inference queue and one model instance per process.
139
+
140
+ ## Model identity and limitations
141
+
142
+ Package version `0.1.0` is separate from model version `v0.4.0`. Every backend
143
+ uses immutable model revision `785d530221c990671f29976902540101bb9c7647` and verifies
144
+ the encoder/head/config hashes. No executable Hugging Face code is downloaded
145
+ or enabled. The encoder was trained jointly with a scalar head; using stock
146
+ Gemma token-generation logits would not serve this model.
147
+
148
+ Probabilities are `softmax(raw_scores / 4.136820402388508)`, using a temperature
149
+ previously fitted on 300 banking/NLI examples. `confidence` is the largest
150
+ derived probability, not a guarantee of correctness or general calibration.
151
+ On the author's public JevBench diagnostic the frozen model achieved 110/231
152
+ (47.62%), including 36 context-limit refusals. It is most relevant to small
153
+ closed-choice tasks; evaluate it on your own use case before routing important
154
+ actions. [Model evaluation and provenance](https://huggingface.co/rajan2k/GemmaDecision-270M).
155
+
156
+ ## Develop
157
+
158
+ ```sh
159
+ git clone https://github.com/rjn32s/gemmadecision.git
160
+ cd gemmadecision
161
+ pip install -e '.[test,pydantic-ai]'
162
+ pytest
163
+ python -m build
164
+ twine check dist/*
165
+ ```
166
+
167
+ Tests use synthetic tensors, stub encoders and actual PydanticAI agents with
168
+ mock HTTP; they do not download or train a model. GPU performance measurements
169
+ are separate reproducible artifacts. `gemmadecision doctor` reports installed
170
+ backends without loading weights.
171
+
172
+ Code: Apache-2.0. Weights: separate Gemma terms. Dependency licenses and CLM schema
173
+ attribution are in [NOTICE](../NOTICE). This package is not affiliated with Google,
174
+ PydanticAI, vLLM, Granian, CLM or the JevBench maintainers.