inference-control-plane 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 (27) hide show
  1. inference_control_plane-0.1.0/LICENSE +207 -0
  2. inference_control_plane-0.1.0/MANIFEST.in +4 -0
  3. inference_control_plane-0.1.0/PKG-INFO +140 -0
  4. inference_control_plane-0.1.0/README.md +102 -0
  5. inference_control_plane-0.1.0/pyproject.toml +76 -0
  6. inference_control_plane-0.1.0/setup.cfg +4 -0
  7. inference_control_plane-0.1.0/src/inference_control_plane/__init__.py +49 -0
  8. inference_control_plane-0.1.0/src/inference_control_plane/models.py +83 -0
  9. inference_control_plane-0.1.0/src/inference_control_plane/pool_status.py +41 -0
  10. inference_control_plane-0.1.0/src/inference_control_plane/recommendations.py +112 -0
  11. inference_control_plane-0.1.0/src/inference_control_plane/timeutil.py +6 -0
  12. inference_control_plane-0.1.0/src/inference_control_plane/vllm.py +387 -0
  13. inference_control_plane-0.1.0/src/inference_control_plane/workload/__init__.py +5 -0
  14. inference_control_plane-0.1.0/src/inference_control_plane/workload/adapter_base.py +145 -0
  15. inference_control_plane-0.1.0/src/inference_control_plane/workload/adapters.py +40 -0
  16. inference_control_plane-0.1.0/src/inference_control_plane/workload/analysis.py +162 -0
  17. inference_control_plane-0.1.0/src/inference_control_plane/workload/errors.py +10 -0
  18. inference_control_plane-0.1.0/src/inference_control_plane/workload/event_utils.py +43 -0
  19. inference_control_plane-0.1.0/src/inference_control_plane/workload/helicone.py +141 -0
  20. inference_control_plane-0.1.0/src/inference_control_plane/workload/langfuse.py +111 -0
  21. inference_control_plane-0.1.0/src/inference_control_plane/workload/otlp.py +137 -0
  22. inference_control_plane-0.1.0/src/inference_control_plane/workload/sample_data.py +150 -0
  23. inference_control_plane-0.1.0/src/inference_control_plane.egg-info/PKG-INFO +140 -0
  24. inference_control_plane-0.1.0/src/inference_control_plane.egg-info/SOURCES.txt +25 -0
  25. inference_control_plane-0.1.0/src/inference_control_plane.egg-info/dependency_links.txt +1 -0
  26. inference_control_plane-0.1.0/src/inference_control_plane.egg-info/requires.txt +10 -0
  27. inference_control_plane-0.1.0/src/inference_control_plane.egg-info/top_level.txt +1 -0
@@ -0,0 +1,207 @@
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.
203
+
204
+ Copyright inference-control-plane contributors
205
+
206
+ Licensed under the Apache License, Version 2.0 (the "License");
207
+ you may not use this file except in compliance with the License.
@@ -0,0 +1,4 @@
1
+ global-exclude *.py[cod]
2
+ global-exclude __pycache__
3
+ prune tests
4
+ prune .github
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: inference-control-plane
3
+ Version: 0.1.0
4
+ Summary: Reusable inference observability and optimization control plane
5
+ Author: inference-control-plane contributors
6
+ Maintainer: inference-control-plane contributors
7
+ License: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/yavuzhansarmaz/inference-control-plane
9
+ Project-URL: Repository, https://github.com/yavuzhansarmaz/inference-control-plane
10
+ Project-URL: Issues, https://github.com/yavuzhansarmaz/inference-control-plane/issues
11
+ Project-URL: Changelog, https://github.com/yavuzhansarmaz/inference-control-plane/blob/main/CHANGELOG.md
12
+ Project-URL: Documentation, https://github.com/yavuzhansarmaz/inference-control-plane#readme
13
+ Keywords: llm,inference,vllm,observability,monitoring,optimization,helicone,langfuse,opentelemetry
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: System :: Monitoring
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: httpx>=0.26.0
29
+ Requires-Dist: pydantic>=2.5.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
32
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.8.0; extra == "dev"
35
+ Requires-Dist: build>=1.0; extra == "dev"
36
+ Requires-Dist: twine>=5.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # Inference Control Plane
40
+
41
+ Reusable, open-source inference observability and optimization control plane. It lets you connect, inspect, and optimize existing inference pipelines (Helicone, Langfuse, OpenTelemetry, vLLM) from a host application without moving that logic into the host.
42
+
43
+ ## About Freuron
44
+
45
+ [Freuron](https://freuron.com) is an AI platform where teams train, fine-tune, and serve their own language models. Inference observability — understanding what a model costs, how fast it answers, and where capacity is wasted — is a core part of that platform.
46
+
47
+ This repository is the open-source edition of an important part of Freuron: the inference control plane that runs in production inside Freuron to inspect and optimize inference workloads. We use this same package ourselves, and we are releasing it so anyone can connect, inspect, and optimize their existing inference pipelines — with vLLM, Langfuse, Helicone, or OpenTelemetry — without adopting the rest of Freuron.
48
+
49
+ ## What it does
50
+
51
+ - Provider adapters for Helicone, Langfuse, and OpenTelemetry (OTLP) that pull and normalize inference events.
52
+ - Deterministic workload analysis: scoring, cost/latency/quality projections against a managed target rate, and migration-candidate detection.
53
+ - Read-only vLLM monitoring via Prometheus `/metrics` and `/health` (GET only).
54
+ - Evidence-based recommendations and measured-vs-estimated comparisons between a current endpoint and a managed serving pool.
55
+ - Sample-data generation for evaluating the analysis without real provider data.
56
+
57
+ The package is stateless. The host application owns authentication, persistence, pricing configuration, and credential storage, and injects them as arguments. See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
58
+
59
+ ## Install
60
+
61
+ ```bash
62
+ pip install inference-control-plane
63
+ # local development against a checkout:
64
+ pip install -e ./inference-control-plane
65
+ ```
66
+
67
+
68
+ ## Quick start (vLLM, read-only)
69
+
70
+ ```python
71
+ from inference_control_plane import EndpointConfig, VllmClient
72
+ from inference_control_plane.recommendations import recommend_from_snapshot
73
+
74
+ client = VllmClient(EndpointConfig(base_url="https://my-vllm.example.com"))
75
+ snapshot = await client.collect() # GET /metrics only; failures -> status="unreachable"
76
+ print(snapshot) # missing metrics are None, never 0
77
+ print(recommend_from_snapshot(snapshot)) # evidence-based, review-only
78
+ ```
79
+
80
+ Private/self-hosted endpoints require `allow_private_endpoints=True` (explicit opt-in; the SSRF guard otherwise rejects non-global addresses, credentials in URLs, and non-HTTPS).
81
+
82
+ ## Capabilities probe
83
+
84
+ `VllmClient.capabilities()` probes `/health`, `/v1/models`, and `/metrics` with GET only and never raises: failures become notes in `EndpointCapabilities.errors`. It reports `health_ok`, the served `models`, and `metrics_ok`. Use it to check an endpoint before trusting a snapshot.
85
+
86
+ ## Derived rates
87
+
88
+ `derive_rates(prev, curr)` is a pure function over two `MetricSnapshot`s. It returns `DerivedRates` (`tokens_per_second`, `generation_tokens_per_second`, `prompt_tokens_per_second`, `requests_per_second`). A missing counter, a non-positive window, or a rewound counter yields `None` for that rate — rates are never fabricated.
89
+
90
+ ## Cost estimate
91
+
92
+ `estimate_effective_cost(snapshot, gpu_hourly_usd, tokens_per_second=None)` returns `None` when no GPU hourly price is supplied. Otherwise it returns an `EffectiveCost` with `hourly_cost_usd`, `effective_cost_per_utilized_hour_usd` (hourly price spread over the utilized GPU fraction; `None` when utilization is unknown or zero), and `cost_per_million_generation_tokens_usd`. The result always carries `kind="user_assumption"`: the price is asserted by the user, not measured, so every figure is an estimate, not a bill.
93
+
94
+ ## Comparison and `kind` labels
95
+
96
+ `compare_snapshots(current, managed_snapshot=..., managed_kind=...)` returns `ComparisonRow`s (`metric`, `current`, `managed`, `unit`, `kind`, `notes`). Every row is labelled by provenance via `kind`:
97
+
98
+ - `measured` — read from a live endpoint or a ready managed serving-pool replica.
99
+ - `estimated` — derived from measured inputs (for example a rate or a pool side whose status is not `ok`).
100
+ - `user_assumption` — computed from a user-supplied input such as `gpu_hourly_usd`.
101
+
102
+ `snapshot_from_pool_status(pool_payload)` converts a generic serving-pool payload (including per-replica `resources`) into a `MetricSnapshot` so it can be compared with an external vLLM snapshot. Missing metrics stay `None`, never `0`.
103
+
104
+ ## Workload analysis
105
+
106
+ ```python
107
+ from inference_control_plane.workload.analysis import analyze_events
108
+
109
+ summary, opportunities, assumptions = analyze_events(
110
+ events,
111
+ window_days=30,
112
+ managed_rate_usd_per_million=1.0,
113
+ ttft_ms=200.0,
114
+ output_tokens_per_second=50.0,
115
+ )
116
+ ```
117
+
118
+ `managed_rate_usd_per_million` is the host-supplied target rate used for cost projections. The package ships no pricing of its own.
119
+
120
+ ## Known limitations
121
+
122
+ - Serving-pool payloads without measured per-replica `resources` read as `None` for those fields.
123
+ - No snapshot history or polling: `collect()` is a single point-in-time read. Callers that need rates call `derive_rates` on two snapshots they collected themselves.
124
+ - Host-application telemetry, persistence, and billing are not part of this package; see `docs/ARCHITECTURE.md`.
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ pip install -e '.[dev]'
130
+ python -m pytest
131
+ python -m ruff check src tests
132
+ ```
133
+
134
+ ## Releasing / rollback
135
+
136
+ See [docs/RELEASING.md](docs/RELEASING.md). Consumers pin an exact version; rollback is pinning the previous version and redeploying — no data migration is involved.
137
+
138
+ ## License
139
+
140
+ Apache License 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,102 @@
1
+ # Inference Control Plane
2
+
3
+ Reusable, open-source inference observability and optimization control plane. It lets you connect, inspect, and optimize existing inference pipelines (Helicone, Langfuse, OpenTelemetry, vLLM) from a host application without moving that logic into the host.
4
+
5
+ ## About Freuron
6
+
7
+ [Freuron](https://freuron.com) is an AI platform where teams train, fine-tune, and serve their own language models. Inference observability — understanding what a model costs, how fast it answers, and where capacity is wasted — is a core part of that platform.
8
+
9
+ This repository is the open-source edition of an important part of Freuron: the inference control plane that runs in production inside Freuron to inspect and optimize inference workloads. We use this same package ourselves, and we are releasing it so anyone can connect, inspect, and optimize their existing inference pipelines — with vLLM, Langfuse, Helicone, or OpenTelemetry — without adopting the rest of Freuron.
10
+
11
+ ## What it does
12
+
13
+ - Provider adapters for Helicone, Langfuse, and OpenTelemetry (OTLP) that pull and normalize inference events.
14
+ - Deterministic workload analysis: scoring, cost/latency/quality projections against a managed target rate, and migration-candidate detection.
15
+ - Read-only vLLM monitoring via Prometheus `/metrics` and `/health` (GET only).
16
+ - Evidence-based recommendations and measured-vs-estimated comparisons between a current endpoint and a managed serving pool.
17
+ - Sample-data generation for evaluating the analysis without real provider data.
18
+
19
+ The package is stateless. The host application owns authentication, persistence, pricing configuration, and credential storage, and injects them as arguments. See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install inference-control-plane
25
+ # local development against a checkout:
26
+ pip install -e ./inference-control-plane
27
+ ```
28
+
29
+
30
+ ## Quick start (vLLM, read-only)
31
+
32
+ ```python
33
+ from inference_control_plane import EndpointConfig, VllmClient
34
+ from inference_control_plane.recommendations import recommend_from_snapshot
35
+
36
+ client = VllmClient(EndpointConfig(base_url="https://my-vllm.example.com"))
37
+ snapshot = await client.collect() # GET /metrics only; failures -> status="unreachable"
38
+ print(snapshot) # missing metrics are None, never 0
39
+ print(recommend_from_snapshot(snapshot)) # evidence-based, review-only
40
+ ```
41
+
42
+ Private/self-hosted endpoints require `allow_private_endpoints=True` (explicit opt-in; the SSRF guard otherwise rejects non-global addresses, credentials in URLs, and non-HTTPS).
43
+
44
+ ## Capabilities probe
45
+
46
+ `VllmClient.capabilities()` probes `/health`, `/v1/models`, and `/metrics` with GET only and never raises: failures become notes in `EndpointCapabilities.errors`. It reports `health_ok`, the served `models`, and `metrics_ok`. Use it to check an endpoint before trusting a snapshot.
47
+
48
+ ## Derived rates
49
+
50
+ `derive_rates(prev, curr)` is a pure function over two `MetricSnapshot`s. It returns `DerivedRates` (`tokens_per_second`, `generation_tokens_per_second`, `prompt_tokens_per_second`, `requests_per_second`). A missing counter, a non-positive window, or a rewound counter yields `None` for that rate — rates are never fabricated.
51
+
52
+ ## Cost estimate
53
+
54
+ `estimate_effective_cost(snapshot, gpu_hourly_usd, tokens_per_second=None)` returns `None` when no GPU hourly price is supplied. Otherwise it returns an `EffectiveCost` with `hourly_cost_usd`, `effective_cost_per_utilized_hour_usd` (hourly price spread over the utilized GPU fraction; `None` when utilization is unknown or zero), and `cost_per_million_generation_tokens_usd`. The result always carries `kind="user_assumption"`: the price is asserted by the user, not measured, so every figure is an estimate, not a bill.
55
+
56
+ ## Comparison and `kind` labels
57
+
58
+ `compare_snapshots(current, managed_snapshot=..., managed_kind=...)` returns `ComparisonRow`s (`metric`, `current`, `managed`, `unit`, `kind`, `notes`). Every row is labelled by provenance via `kind`:
59
+
60
+ - `measured` — read from a live endpoint or a ready managed serving-pool replica.
61
+ - `estimated` — derived from measured inputs (for example a rate or a pool side whose status is not `ok`).
62
+ - `user_assumption` — computed from a user-supplied input such as `gpu_hourly_usd`.
63
+
64
+ `snapshot_from_pool_status(pool_payload)` converts a generic serving-pool payload (including per-replica `resources`) into a `MetricSnapshot` so it can be compared with an external vLLM snapshot. Missing metrics stay `None`, never `0`.
65
+
66
+ ## Workload analysis
67
+
68
+ ```python
69
+ from inference_control_plane.workload.analysis import analyze_events
70
+
71
+ summary, opportunities, assumptions = analyze_events(
72
+ events,
73
+ window_days=30,
74
+ managed_rate_usd_per_million=1.0,
75
+ ttft_ms=200.0,
76
+ output_tokens_per_second=50.0,
77
+ )
78
+ ```
79
+
80
+ `managed_rate_usd_per_million` is the host-supplied target rate used for cost projections. The package ships no pricing of its own.
81
+
82
+ ## Known limitations
83
+
84
+ - Serving-pool payloads without measured per-replica `resources` read as `None` for those fields.
85
+ - No snapshot history or polling: `collect()` is a single point-in-time read. Callers that need rates call `derive_rates` on two snapshots they collected themselves.
86
+ - Host-application telemetry, persistence, and billing are not part of this package; see `docs/ARCHITECTURE.md`.
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ pip install -e '.[dev]'
92
+ python -m pytest
93
+ python -m ruff check src tests
94
+ ```
95
+
96
+ ## Releasing / rollback
97
+
98
+ See [docs/RELEASING.md](docs/RELEASING.md). Consumers pin an exact version; rollback is pinning the previous version and redeploying — no data migration is involved.
99
+
100
+ ## License
101
+
102
+ Apache License 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,76 @@
1
+ [project]
2
+ name = "inference-control-plane"
3
+ version = "0.1.0"
4
+ description = "Reusable inference observability and optimization control plane"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = { text = "Apache-2.0" }
8
+ authors = [
9
+ { name = "inference-control-plane contributors" },
10
+ ]
11
+ maintainers = [
12
+ { name = "inference-control-plane contributors" },
13
+ ]
14
+ keywords = [
15
+ "llm",
16
+ "inference",
17
+ "vllm",
18
+ "observability",
19
+ "monitoring",
20
+ "optimization",
21
+ "helicone",
22
+ "langfuse",
23
+ "opentelemetry",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 3 - Alpha",
27
+ "Intended Audience :: Developers",
28
+ "License :: OSI Approved :: Apache Software License",
29
+ "Operating System :: OS Independent",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3 :: Only",
34
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
35
+ "Topic :: Software Development :: Libraries :: Python Modules",
36
+ "Topic :: System :: Monitoring",
37
+ ]
38
+ dependencies = ["httpx>=0.26.0", "pydantic>=2.5.0"]
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/yavuzhansarmaz/inference-control-plane"
42
+ Repository = "https://github.com/yavuzhansarmaz/inference-control-plane"
43
+ Issues = "https://github.com/yavuzhansarmaz/inference-control-plane/issues"
44
+ Changelog = "https://github.com/yavuzhansarmaz/inference-control-plane/blob/main/CHANGELOG.md"
45
+ Documentation = "https://github.com/yavuzhansarmaz/inference-control-plane#readme"
46
+
47
+ [project.optional-dependencies]
48
+ dev = ["pytest>=7.4.0", "pytest-asyncio>=0.21.0", "pytest-cov>=5.0", "ruff>=0.8.0", "build>=1.0", "twine>=5.0"]
49
+
50
+ [build-system]
51
+ requires = ["setuptools>=77.0"]
52
+ build-backend = "setuptools.build_meta"
53
+
54
+ [tool.setuptools.packages.find]
55
+ where = ["src"]
56
+
57
+ [tool.pytest.ini_options]
58
+ asyncio_mode = "auto"
59
+ testpaths = ["tests"]
60
+ addopts = "--cov=inference_control_plane --cov-report=term-missing"
61
+
62
+ [tool.coverage.run]
63
+ source = ["inference_control_plane"]
64
+ branch = true
65
+
66
+ [tool.coverage.report]
67
+ fail_under = 75
68
+ show_missing = true
69
+
70
+ [tool.ruff]
71
+ line-length = 100
72
+ target-version = "py311"
73
+
74
+ [tool.ruff.lint]
75
+ select = ["E", "F", "W", "I"]
76
+ ignore = ["E501"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,49 @@
1
+ """Inference Control Plane — reusable inference observability."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ from inference_control_plane.models import (
6
+ ComparisonRow,
7
+ DerivedRates,
8
+ EffectiveCost,
9
+ EndpointCapabilities,
10
+ EndpointConfig,
11
+ MetricSnapshot,
12
+ Recommendation,
13
+ )
14
+ from inference_control_plane.pool_status import snapshot_from_pool_status
15
+ from inference_control_plane.recommendations import (
16
+ compare_snapshots,
17
+ recommend_from_snapshot,
18
+ )
19
+ from inference_control_plane.vllm import (
20
+ VllmClient,
21
+ derive_rates,
22
+ estimate_effective_cost,
23
+ parse_prometheus,
24
+ snapshot_from_metrics,
25
+ )
26
+
27
+ try:
28
+ __version__ = version("inference-control-plane")
29
+ except PackageNotFoundError: # source checkout without install
30
+ __version__ = "0.0.0+unknown"
31
+
32
+ __all__ = [
33
+ "ComparisonRow",
34
+ "DerivedRates",
35
+ "EffectiveCost",
36
+ "EndpointCapabilities",
37
+ "EndpointConfig",
38
+ "MetricSnapshot",
39
+ "Recommendation",
40
+ "VllmClient",
41
+ "__version__",
42
+ "compare_snapshots",
43
+ "derive_rates",
44
+ "estimate_effective_cost",
45
+ "parse_prometheus",
46
+ "recommend_from_snapshot",
47
+ "snapshot_from_metrics",
48
+ "snapshot_from_pool_status",
49
+ ]
@@ -0,0 +1,83 @@
1
+ """Public domain models. Missing metrics are None, never fabricated zero."""
2
+ from __future__ import annotations
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+
7
+ def as_ratio(value: float | None) -> float | None:
8
+ """Normalize a percent-form value (>1) to a 0..1 ratio."""
9
+ return value / 100.0 if value is not None and value > 1.0 else value
10
+
11
+
12
+ class EndpointConfig(BaseModel):
13
+ provider: str = "vllm"
14
+ base_url: str
15
+ metrics_url: str | None = None
16
+ model: str | None = None
17
+ gpu_hourly_usd: float | None = Field(default=None, ge=0)
18
+
19
+ class MetricSnapshot(BaseModel):
20
+ provider: str
21
+ status: str # ok | degraded | unreachable
22
+ collected_at: str
23
+ source: str
24
+ errors: list[str] = Field(default_factory=list)
25
+ requests_running: float | None = None
26
+ requests_waiting: float | None = None
27
+ kv_cache_usage_ratio: float | None = None # 0..1 when known
28
+ gpu_utilization_ratio: float | None = None
29
+ prompt_tokens_total: float | None = None
30
+ generation_tokens_total: float | None = None
31
+ request_success_total: float | None = None
32
+ request_failure_total: float | None = None
33
+ error_rate: float | None = None
34
+ ttft_p95_seconds: float | None = None
35
+ e2e_latency_p95_seconds: float | None = None
36
+ tokens_per_second: float | None = None # only if caller supplies a window rate
37
+
38
+ class EndpointCapabilities(BaseModel):
39
+ """Best-effort, GET-only capability probe. Failures are notes, never exceptions."""
40
+
41
+ health_ok: bool = False
42
+ models: list[str] = Field(default_factory=list)
43
+ metrics_ok: bool = False
44
+ errors: list[str] = Field(default_factory=list)
45
+ checked_at: str = ""
46
+
47
+
48
+ class DerivedRates(BaseModel):
49
+ """Rates derived from two counter snapshots; unknown rates stay None."""
50
+
51
+ elapsed_seconds: float | None = None
52
+ tokens_per_second: float | None = None
53
+ generation_tokens_per_second: float | None = None
54
+ prompt_tokens_per_second: float | None = None
55
+ requests_per_second: float | None = None
56
+
57
+
58
+ class EffectiveCost(BaseModel):
59
+ """Cost estimate from a user-supplied GPU price; kind is always user_assumption."""
60
+
61
+ kind: str = "user_assumption"
62
+ gpu_hourly_usd: float
63
+ hourly_cost_usd: float
64
+ utilization_ratio: float | None = None
65
+ effective_cost_per_utilized_hour_usd: float | None = None
66
+ cost_per_million_generation_tokens_usd: float | None = None
67
+ notes: str = ""
68
+
69
+
70
+ class Recommendation(BaseModel):
71
+ code: str
72
+ title: str
73
+ evidence: str
74
+ assumptions: list[str] = Field(default_factory=list)
75
+ confidence: str = "low"
76
+
77
+ class ComparisonRow(BaseModel):
78
+ metric: str
79
+ current: float | None = None
80
+ managed: float | None = None
81
+ unit: str
82
+ kind: str # measured | estimated | user_assumption
83
+ notes: str = ""