seldon-runtime 0.1.1.dev0__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. seldon_runtime-0.1.1.dev0/LICENSE +202 -0
  2. seldon_runtime-0.1.1.dev0/MANIFEST.in +2 -0
  3. seldon_runtime-0.1.1.dev0/NOTICE +9 -0
  4. seldon_runtime-0.1.1.dev0/PKG-INFO +178 -0
  5. seldon_runtime-0.1.1.dev0/README.md +155 -0
  6. seldon_runtime-0.1.1.dev0/pyproject.toml +39 -0
  7. seldon_runtime-0.1.1.dev0/runtime_modules.txt +21 -0
  8. seldon_runtime-0.1.1.dev0/seldon_runtime/__init__.py +3 -0
  9. seldon_runtime-0.1.1.dev0/seldon_runtime/attempt_bound.py +35 -0
  10. seldon_runtime-0.1.1.dev0/seldon_runtime/components.py +316 -0
  11. seldon_runtime-0.1.1.dev0/seldon_runtime/conditional.py +277 -0
  12. seldon_runtime-0.1.1.dev0/seldon_runtime/contract_versions.py +15 -0
  13. seldon_runtime-0.1.1.dev0/seldon_runtime/contracts.py +859 -0
  14. seldon_runtime-0.1.1.dev0/seldon_runtime/deadline.py +51 -0
  15. seldon_runtime-0.1.1.dev0/seldon_runtime/executor.py +852 -0
  16. seldon_runtime-0.1.1.dev0/seldon_runtime/gliner_normalize.py +274 -0
  17. seldon_runtime-0.1.1.dev0/seldon_runtime/instruction_envelope.py +57 -0
  18. seldon_runtime-0.1.1.dev0/seldon_runtime/json_pointer.py +26 -0
  19. seldon_runtime-0.1.1.dev0/seldon_runtime/local.py +173 -0
  20. seldon_runtime-0.1.1.dev0/seldon_runtime/local_models.py +27 -0
  21. seldon_runtime-0.1.1.dev0/seldon_runtime/local_telemetry.py +108 -0
  22. seldon_runtime-0.1.1.dev0/seldon_runtime/native_schema.py +33 -0
  23. seldon_runtime-0.1.1.dev0/seldon_runtime/output_budget.py +166 -0
  24. seldon_runtime-0.1.1.dev0/seldon_runtime/program_validation.py +137 -0
  25. seldon_runtime-0.1.1.dev0/seldon_runtime/provider_error.py +42 -0
  26. seldon_runtime-0.1.1.dev0/seldon_runtime/research_kernels.py +77 -0
  27. seldon_runtime-0.1.1.dev0/seldon_runtime/runner.py +544 -0
  28. seldon_runtime-0.1.1.dev0/seldon_runtime/semantic.py +684 -0
  29. seldon_runtime-0.1.1.dev0/seldon_runtime/telemetry.py +197 -0
  30. seldon_runtime-0.1.1.dev0/seldon_runtime/templates.py +109 -0
  31. seldon_runtime-0.1.1.dev0/seldon_runtime/tool_wire.py +116 -0
  32. seldon_runtime-0.1.1.dev0/seldon_runtime.egg-info/PKG-INFO +178 -0
  33. seldon_runtime-0.1.1.dev0/seldon_runtime.egg-info/SOURCES.txt +50 -0
  34. seldon_runtime-0.1.1.dev0/seldon_runtime.egg-info/dependency_links.txt +1 -0
  35. seldon_runtime-0.1.1.dev0/seldon_runtime.egg-info/requires.txt +12 -0
  36. seldon_runtime-0.1.1.dev0/seldon_runtime.egg-info/top_level.txt +1 -0
  37. seldon_runtime-0.1.1.dev0/setup.cfg +4 -0
  38. seldon_runtime-0.1.1.dev0/tests/fixtures/digest_goldens.json +128 -0
  39. seldon_runtime-0.1.1.dev0/tests/fixtures/local_gliner_raw.json +97 -0
  40. seldon_runtime-0.1.1.dev0/tests/fixtures/serving_compat/function-plan-v1.json +23 -0
  41. seldon_runtime-0.1.1.dev0/tests/fixtures/serving_compat/function-plan-v2.json +55 -0
  42. seldon_runtime-0.1.1.dev0/tests/fixtures/serving_compat/function-plan-v3.json +192 -0
  43. seldon_runtime-0.1.1.dev0/tests/fixtures/serving_compat/function-plan-v4.json +106 -0
  44. seldon_runtime-0.1.1.dev0/tests/fixtures/serving_compat/function-plan-v5.json +128 -0
  45. seldon_runtime-0.1.1.dev0/tests/installed_local_probe.py +56 -0
  46. seldon_runtime-0.1.1.dev0/tests/test_contracts.py +41 -0
  47. seldon_runtime-0.1.1.dev0/tests/test_gliner_normalize.py +27 -0
  48. seldon_runtime-0.1.1.dev0/tests/test_import_closure.py +34 -0
  49. seldon_runtime-0.1.1.dev0/tests/test_install.py +54 -0
  50. seldon_runtime-0.1.1.dev0/tests/test_local.py +681 -0
  51. seldon_runtime-0.1.1.dev0/tests/test_runner.py +1220 -0
  52. seldon_runtime-0.1.1.dev0/tests/wheel_probe.py +45 -0
@@ -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,2 @@
1
+ include LICENSE NOTICE README.md runtime_modules.txt
2
+ recursive-include tests *.py *.json
@@ -0,0 +1,9 @@
1
+ Seldon Runtime
2
+ Copyright 2026 Deep Insight Labs
3
+
4
+ This Apache-2.0 distribution contains the standalone Function interpreter and
5
+ local execution client. The Seldon service, optimizer, billing, orchestration,
6
+ infrastructure and dashboard are not part of this distribution.
7
+
8
+ Optional GLiNER2 code and downloaded model weights remain under their respective
9
+ upstream licenses. Their licenses are not replaced by this project license.
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: seldon-runtime
3
+ Version: 0.1.1.dev0
4
+ Summary: Standalone Seldon Functions interpreter and local execution client
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Source, https://github.com/Deep-Insight-Labs/seldon-runtime
7
+ Project-URL: Issues, https://github.com/Deep-Insight-Labs/seldon-runtime/issues
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Requires-Dist: pydantic>=2.2
13
+ Requires-Dist: jsonschema>=4.21
14
+ Requires-Dist: tiktoken>=0.7
15
+ Provides-Extra: gliner
16
+ Requires-Dist: gliner2[local]~=2.1.0; extra == "gliner"
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8; extra == "dev"
19
+ Requires-Dist: ruff==0.16.4; extra == "dev"
20
+ Requires-Dist: build>=1; extra == "dev"
21
+ Requires-Dist: twine>=6; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # Seldon Runtime
25
+
26
+ `seldon-runtime` is the standalone Python interpreter and local execution client
27
+ for eligible Seldon Functions. The package name is **`seldon-runtime`**, and the
28
+ Python import is `seldon_runtime`. This project is separate from SeldonIO.
29
+
30
+ A single generic runtime executes authorized Function bundles on your hardware.
31
+ Optimization and hosted comparison happen on Seldon. The runtime contains no
32
+ optimizer, billing service, dashboard or server infrastructure. Its first local
33
+ model adapter uses pinned GLiNER2 open weights for extraction and classification.
34
+
35
+ This is a source preview. A source checkout or successful build does not establish
36
+ PyPI publication, production feature activation, or quality on your own inputs.
37
+
38
+ ## Install
39
+
40
+ Python 3.11 or later is required. The base interpreter uses Pydantic, jsonschema
41
+ and tiktoken. Local GLiNER inference additionally needs PyTorch and the model extra.
42
+ Before publication, replace the package name below with a locally built wheel.
43
+
44
+ On Linux, install CPU PyTorch explicitly to avoid downloading CUDA dependencies:
45
+
46
+ ```sh
47
+ python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
48
+ python -m pip install 'seldon-runtime[gliner]'
49
+ ```
50
+
51
+ On macOS:
52
+
53
+ ```sh
54
+ python -m pip install torch
55
+ python -m pip install 'seldon-runtime[gliner]'
56
+ ```
57
+
58
+ In a uv environment, use `uv pip install` for the same commands. In a Linux uv
59
+ project, persist the dedicated torch index:
60
+
61
+ ```sh
62
+ uv add torch --index pytorch=https://download.pytorch.org/whl/cpu
63
+ uv add 'seldon-runtime[gliner]'
64
+ ```
65
+
66
+ The model weights and tokenizer files download on first use. Cache the pinned
67
+ snapshot in advance for restricted networks. Token-chunked plans also need the
68
+ tiktoken BPE cache (`TIKTOKEN_CACHE_DIR`). Model weights are not bundled in the wheel.
69
+
70
+ ## Run a Function locally
71
+
72
+ Only activated, locally eligible v3/v4 revisions can be loaded. Hosted-only models,
73
+ reference-bound Functions and v5 plans are ineligible. Authorization uses your
74
+ workspace API key; it does not grant management access.
75
+
76
+ ```python
77
+ import asyncio
78
+ import os
79
+
80
+ from seldon_runtime.runner import Runner
81
+
82
+
83
+ async def main():
84
+ runner = await Runner.load(
85
+ "FUNCTION_UUID",
86
+ os.environ["SELDON_API_KEY"],
87
+ fallback="raise",
88
+ telemetry=False,
89
+ )
90
+ try:
91
+ result = await runner({"document": "Ada works at Acme"})
92
+ print(result["output"])
93
+ print(runner.status())
94
+ finally:
95
+ await runner.aclose()
96
+
97
+
98
+ asyncio.run(main())
99
+ ```
100
+
101
+ Use the input names from your Function contract. Each result also reports
102
+ `fallback_used` and `fallback_reason`. `LocalExecutionError.reason` is a bounded
103
+ machine-readable code; errors do not expose credentials or internal paths.
104
+
105
+ `fallback="raise"` prevents hosted inference fallback. `fallback="seldon"` sends
106
+ failed calls to Seldon and incurs ordinary hosted usage charges. An explicit
107
+ `{"endpoint": "...", "api_key": "..."}` uses your own OpenAI-compatible endpoint.
108
+ A failed initial verification raises before installing the bundle.
109
+
110
+ The [Seldon Python SDK](https://github.com/Deep-Insight-Labs/seldon-python) provides
111
+ optional typed declarations and `seldon function pull`, `verify` and `run` commands
112
+ using this runtime. It is not required for direct `Runner` use.
113
+
114
+ ## Verification and refresh
115
+
116
+ `Runner.load()` checks at least 95% exact agreement against the revision's held-out
117
+ conformance set before installing a new revision/model/runtime combination.
118
+ `await runner.verify()` reruns up to 200 local inputs and reports agreement,
119
+ sample count and p50/p95 latency. This measures agreement on that set, not business
120
+ correctness or coverage of all inputs. `allow_unverified=True` explicitly skips
121
+ verification and is not parity evidence.
122
+
123
+ Bundles are cached without API keys, revalidated at load and every 15 minutes on
124
+ a long-lived event loop. A failed refresh keeps the last validated revision for
125
+ at most 24 hours from its last successful check; expiry applies your fallback
126
+ policy. A disabled, deleted or unauthorized Function stops serving when observed.
127
+ Short-lived loops may not finish background refresh, so the 24-hour expiry is the
128
+ upper bound. Local execution still needs these control-plane calls.
129
+
130
+ `runner.status()` reads current local state without network or inference. Optional
131
+ reporting sends bounded counts, latency histograms and status outside inference;
132
+ it never sends inputs, outputs or payload hashes. `telemetry=False` disables both
133
+ usage and status reporting. Reports are best effort and are not billing authority.
134
+ Always close the runner to stop background tasks and attempt a bounded flush.
135
+
136
+ ## Development
137
+
138
+ ```sh
139
+ python -m pip install -e '.[dev]'
140
+ python -m ruff check .
141
+ python -m ruff format --check .
142
+ python -m pytest -q
143
+ python -m build
144
+ python -m twine check dist/*
145
+ python scripts/verify_artifacts.py dist/*
146
+ ```
147
+
148
+ Default tests replace model weights and HTTP at explicit runtime seams. They
149
+ exercise execution, output normalization, authorization refusals, conformance,
150
+ refresh, cache handling, fallback and reporting. Synthetic frozen plan/spec
151
+ fixtures check serialization and digest stability. No private repository or
152
+ server package is required. Run `pytest -m local_model` only after installing the
153
+ GLiNER extra; it downloads or reuses the pinned model weights.
154
+
155
+ `tests/installed_local_probe.py` verifies a real installed GLiNER runtime in a
156
+ server-free environment. Base-wheel installation alone does not qualify native
157
+ model dependencies or performance. Existing model probes cover macOS ARM64 and
158
+ Linux ARM64 CPU; other hardware and Windows are not claimed as qualified.
159
+
160
+ ## Releases
161
+
162
+ The publishing workflow is `.github/workflows/runtime-publish.yml` in
163
+ `Deep-Insight-Labs/seldon-runtime`. Register project `seldon-runtime` as a trusted
164
+ publisher on TestPyPI with environment `testpypi`, and on PyPI with environment
165
+ `pypi`. A `runtime-v<version>` tag must match `pyproject.toml` and `__version__`.
166
+
167
+ Publication is disabled unless `SELDON_RUNTIME_TESTPYPI_PUBLISH_ENABLED` and
168
+ `SELDON_RUNTIME_PUBLISH_ENABLED` are enabled separately. The workflow checks the
169
+ standalone project, builds wheel and sdist, publishes to TestPyPI, downloads and
170
+ installs that exact wheel with normal dependencies from PyPI, then publishes the
171
+ original checked artifacts to PyPI. A manual branch dispatch only builds artifacts.
172
+ No stored registry token is required. Registry versions are immutable.
173
+
174
+ ## License
175
+
176
+ Apache-2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Optional GLiNER2 code and
177
+ downloaded weights retain their own upstream licenses. The release is scoped to
178
+ this repository; it does not license the separately operated Seldon service.
@@ -0,0 +1,155 @@
1
+ # Seldon Runtime
2
+
3
+ `seldon-runtime` is the standalone Python interpreter and local execution client
4
+ for eligible Seldon Functions. The package name is **`seldon-runtime`**, and the
5
+ Python import is `seldon_runtime`. This project is separate from SeldonIO.
6
+
7
+ A single generic runtime executes authorized Function bundles on your hardware.
8
+ Optimization and hosted comparison happen on Seldon. The runtime contains no
9
+ optimizer, billing service, dashboard or server infrastructure. Its first local
10
+ model adapter uses pinned GLiNER2 open weights for extraction and classification.
11
+
12
+ This is a source preview. A source checkout or successful build does not establish
13
+ PyPI publication, production feature activation, or quality on your own inputs.
14
+
15
+ ## Install
16
+
17
+ Python 3.11 or later is required. The base interpreter uses Pydantic, jsonschema
18
+ and tiktoken. Local GLiNER inference additionally needs PyTorch and the model extra.
19
+ Before publication, replace the package name below with a locally built wheel.
20
+
21
+ On Linux, install CPU PyTorch explicitly to avoid downloading CUDA dependencies:
22
+
23
+ ```sh
24
+ python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
25
+ python -m pip install 'seldon-runtime[gliner]'
26
+ ```
27
+
28
+ On macOS:
29
+
30
+ ```sh
31
+ python -m pip install torch
32
+ python -m pip install 'seldon-runtime[gliner]'
33
+ ```
34
+
35
+ In a uv environment, use `uv pip install` for the same commands. In a Linux uv
36
+ project, persist the dedicated torch index:
37
+
38
+ ```sh
39
+ uv add torch --index pytorch=https://download.pytorch.org/whl/cpu
40
+ uv add 'seldon-runtime[gliner]'
41
+ ```
42
+
43
+ The model weights and tokenizer files download on first use. Cache the pinned
44
+ snapshot in advance for restricted networks. Token-chunked plans also need the
45
+ tiktoken BPE cache (`TIKTOKEN_CACHE_DIR`). Model weights are not bundled in the wheel.
46
+
47
+ ## Run a Function locally
48
+
49
+ Only activated, locally eligible v3/v4 revisions can be loaded. Hosted-only models,
50
+ reference-bound Functions and v5 plans are ineligible. Authorization uses your
51
+ workspace API key; it does not grant management access.
52
+
53
+ ```python
54
+ import asyncio
55
+ import os
56
+
57
+ from seldon_runtime.runner import Runner
58
+
59
+
60
+ async def main():
61
+ runner = await Runner.load(
62
+ "FUNCTION_UUID",
63
+ os.environ["SELDON_API_KEY"],
64
+ fallback="raise",
65
+ telemetry=False,
66
+ )
67
+ try:
68
+ result = await runner({"document": "Ada works at Acme"})
69
+ print(result["output"])
70
+ print(runner.status())
71
+ finally:
72
+ await runner.aclose()
73
+
74
+
75
+ asyncio.run(main())
76
+ ```
77
+
78
+ Use the input names from your Function contract. Each result also reports
79
+ `fallback_used` and `fallback_reason`. `LocalExecutionError.reason` is a bounded
80
+ machine-readable code; errors do not expose credentials or internal paths.
81
+
82
+ `fallback="raise"` prevents hosted inference fallback. `fallback="seldon"` sends
83
+ failed calls to Seldon and incurs ordinary hosted usage charges. An explicit
84
+ `{"endpoint": "...", "api_key": "..."}` uses your own OpenAI-compatible endpoint.
85
+ A failed initial verification raises before installing the bundle.
86
+
87
+ The [Seldon Python SDK](https://github.com/Deep-Insight-Labs/seldon-python) provides
88
+ optional typed declarations and `seldon function pull`, `verify` and `run` commands
89
+ using this runtime. It is not required for direct `Runner` use.
90
+
91
+ ## Verification and refresh
92
+
93
+ `Runner.load()` checks at least 95% exact agreement against the revision's held-out
94
+ conformance set before installing a new revision/model/runtime combination.
95
+ `await runner.verify()` reruns up to 200 local inputs and reports agreement,
96
+ sample count and p50/p95 latency. This measures agreement on that set, not business
97
+ correctness or coverage of all inputs. `allow_unverified=True` explicitly skips
98
+ verification and is not parity evidence.
99
+
100
+ Bundles are cached without API keys, revalidated at load and every 15 minutes on
101
+ a long-lived event loop. A failed refresh keeps the last validated revision for
102
+ at most 24 hours from its last successful check; expiry applies your fallback
103
+ policy. A disabled, deleted or unauthorized Function stops serving when observed.
104
+ Short-lived loops may not finish background refresh, so the 24-hour expiry is the
105
+ upper bound. Local execution still needs these control-plane calls.
106
+
107
+ `runner.status()` reads current local state without network or inference. Optional
108
+ reporting sends bounded counts, latency histograms and status outside inference;
109
+ it never sends inputs, outputs or payload hashes. `telemetry=False` disables both
110
+ usage and status reporting. Reports are best effort and are not billing authority.
111
+ Always close the runner to stop background tasks and attempt a bounded flush.
112
+
113
+ ## Development
114
+
115
+ ```sh
116
+ python -m pip install -e '.[dev]'
117
+ python -m ruff check .
118
+ python -m ruff format --check .
119
+ python -m pytest -q
120
+ python -m build
121
+ python -m twine check dist/*
122
+ python scripts/verify_artifacts.py dist/*
123
+ ```
124
+
125
+ Default tests replace model weights and HTTP at explicit runtime seams. They
126
+ exercise execution, output normalization, authorization refusals, conformance,
127
+ refresh, cache handling, fallback and reporting. Synthetic frozen plan/spec
128
+ fixtures check serialization and digest stability. No private repository or
129
+ server package is required. Run `pytest -m local_model` only after installing the
130
+ GLiNER extra; it downloads or reuses the pinned model weights.
131
+
132
+ `tests/installed_local_probe.py` verifies a real installed GLiNER runtime in a
133
+ server-free environment. Base-wheel installation alone does not qualify native
134
+ model dependencies or performance. Existing model probes cover macOS ARM64 and
135
+ Linux ARM64 CPU; other hardware and Windows are not claimed as qualified.
136
+
137
+ ## Releases
138
+
139
+ The publishing workflow is `.github/workflows/runtime-publish.yml` in
140
+ `Deep-Insight-Labs/seldon-runtime`. Register project `seldon-runtime` as a trusted
141
+ publisher on TestPyPI with environment `testpypi`, and on PyPI with environment
142
+ `pypi`. A `runtime-v<version>` tag must match `pyproject.toml` and `__version__`.
143
+
144
+ Publication is disabled unless `SELDON_RUNTIME_TESTPYPI_PUBLISH_ENABLED` and
145
+ `SELDON_RUNTIME_PUBLISH_ENABLED` are enabled separately. The workflow checks the
146
+ standalone project, builds wheel and sdist, publishes to TestPyPI, downloads and
147
+ installs that exact wheel with normal dependencies from PyPI, then publishes the
148
+ original checked artifacts to PyPI. A manual branch dispatch only builds artifacts.
149
+ No stored registry token is required. Registry versions are immutable.
150
+
151
+ ## License
152
+
153
+ Apache-2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE). Optional GLiNER2 code and
154
+ downloaded weights retain their own upstream licenses. The release is scoped to
155
+ this repository; it does not license the separately operated Seldon service.
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "seldon-runtime"
7
+ version = "0.1.1.dev0"
8
+ description = "Standalone Seldon Functions interpreter and local execution client"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ requires-python = ">=3.11"
13
+ dependencies = ["pydantic>=2.2", "jsonschema>=4.21", "tiktoken>=0.7"]
14
+
15
+ [project.urls]
16
+ Source = "https://github.com/Deep-Insight-Labs/seldon-runtime"
17
+ Issues = "https://github.com/Deep-Insight-Labs/seldon-runtime/issues"
18
+
19
+ [project.optional-dependencies]
20
+ gliner = ["gliner2[local]~=2.1.0"]
21
+ dev = ["pytest>=8", "ruff==0.16.4", "build>=1", "twine>=6"]
22
+
23
+ [tool.setuptools]
24
+ packages = ["seldon_runtime"]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
28
+ markers = [
29
+ "slow: builds and installs release distributions in fresh virtualenvs; needs network",
30
+ "local_model: runs pinned GLiNER weights; needs torch, gliner2 and network or cached weights",
31
+ ]
32
+ addopts = "-m 'not slow and not local_model'"
33
+
34
+ [tool.ruff]
35
+ line-length = 100
36
+ target-version = "py311"
37
+
38
+ [tool.ruff.lint]
39
+ select = ["E", "F", "I"]
@@ -0,0 +1,21 @@
1
+ # Public interpreter modules, owned by this repository.
2
+ contracts
3
+ templates
4
+ tool_wire
5
+ conditional
6
+ semantic
7
+ executor
8
+ components
9
+ research_kernels
10
+ provider_error
11
+ deadline
12
+ attempt_bound
13
+ contract_versions
14
+ native_schema
15
+ json_pointer
16
+ program_validation
17
+ gliner_normalize
18
+ output_budget
19
+ instruction_envelope
20
+ local_models
21
+ local_telemetry
@@ -0,0 +1,3 @@
1
+ """Standalone Seldon Functions interpreter and local execution client."""
2
+
3
+ __version__ = "0.1.1.dev0"
@@ -0,0 +1,35 @@
1
+ """Per-step and whole-program provider-attempt bounds for a plan."""
2
+
3
+
4
+ def _step_attempts(step, version):
5
+ paid = (
6
+ 3
7
+ if step.op == "choice" and step.config.get("mode") == "pairs"
8
+ else int(step.op in {"llm", "choice", "extract"})
9
+ )
10
+ if version == "function-plan-v4" and step.over:
11
+ chunks = step.max_chunks or 16
12
+ if not 1 <= chunks <= 16:
13
+ raise ValueError("chunk_limit")
14
+ return paid * chunks
15
+ return paid
16
+
17
+
18
+ def program_attempt_bound(plan, spec):
19
+ if plan.version == "function-plan-v5":
20
+ from .conditional import max_path
21
+
22
+ primary = max_path(plan, lambda step: _step_attempts(step, plan.version))
23
+ else:
24
+ primary = sum(_step_attempts(step, plan.version) for step in plan.steps)
25
+ fallback = len(spec.calls) if plan.fallback else 0
26
+ bound = primary + fallback
27
+ if plan.version == "function-plan-v4":
28
+ if primary > 40:
29
+ raise ValueError("call_limit")
30
+ return bound
31
+ if bound > (8 if plan.version in {"function-plan-v3", "function-plan-v5"} else 6):
32
+ raise ValueError("call_limit")
33
+ if plan.version in {"function-plan-v3", "function-plan-v5"} and primary > 5:
34
+ raise ValueError("call_limit")
35
+ return bound