adaptive-serve 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.
- adaptive_serve-0.1.0/LICENSE +21 -0
- adaptive_serve-0.1.0/PKG-INFO +176 -0
- adaptive_serve-0.1.0/README.md +152 -0
- adaptive_serve-0.1.0/pyproject.toml +48 -0
- adaptive_serve-0.1.0/setup.cfg +4 -0
- adaptive_serve-0.1.0/src/adaptive_serve/__init__.py +194 -0
- adaptive_serve-0.1.0/src/adaptive_serve/backends.py +84 -0
- adaptive_serve-0.1.0/src/adaptive_serve/calibration.py +190 -0
- adaptive_serve-0.1.0/src/adaptive_serve/cli.py +168 -0
- adaptive_serve-0.1.0/src/adaptive_serve/cloud_http.py +73 -0
- adaptive_serve-0.1.0/src/adaptive_serve/demo.py +245 -0
- adaptive_serve-0.1.0/src/adaptive_serve/orchestrator.py +208 -0
- adaptive_serve-0.1.0/src/adaptive_serve/pipeline.py +69 -0
- adaptive_serve-0.1.0/src/adaptive_serve/profiler.py +206 -0
- adaptive_serve-0.1.0/src/adaptive_serve/registry.py +287 -0
- adaptive_serve-0.1.0/src/adaptive_serve/router.py +183 -0
- adaptive_serve-0.1.0/src/adaptive_serve/runtime.py +139 -0
- adaptive_serve-0.1.0/src/adaptive_serve/safety.py +146 -0
- adaptive_serve-0.1.0/src/adaptive_serve/scaling.py +385 -0
- adaptive_serve-0.1.0/src/adaptive_serve/serving.py +158 -0
- adaptive_serve-0.1.0/src/adaptive_serve/taxonomy.py +213 -0
- adaptive_serve-0.1.0/src/adaptive_serve/telemetry.py +199 -0
- adaptive_serve-0.1.0/src/adaptive_serve/torch_backend.py +96 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/PKG-INFO +176 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/SOURCES.txt +45 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/dependency_links.txt +1 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/entry_points.txt +2 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/requires.txt +7 -0
- adaptive_serve-0.1.0/src/adaptive_serve.egg-info/top_level.txt +1 -0
- adaptive_serve-0.1.0/tests/test_backends.py +66 -0
- adaptive_serve-0.1.0/tests/test_calibration.py +183 -0
- adaptive_serve-0.1.0/tests/test_cli.py +77 -0
- adaptive_serve-0.1.0/tests/test_cloud_http.py +90 -0
- adaptive_serve-0.1.0/tests/test_measured_registry.py +82 -0
- adaptive_serve-0.1.0/tests/test_orchestrator.py +157 -0
- adaptive_serve-0.1.0/tests/test_pipeline.py +25 -0
- adaptive_serve-0.1.0/tests/test_profiler.py +104 -0
- adaptive_serve-0.1.0/tests/test_registry.py +134 -0
- adaptive_serve-0.1.0/tests/test_router.py +146 -0
- adaptive_serve-0.1.0/tests/test_runtime.py +149 -0
- adaptive_serve-0.1.0/tests/test_safety.py +152 -0
- adaptive_serve-0.1.0/tests/test_scaling.py +221 -0
- adaptive_serve-0.1.0/tests/test_serving.py +130 -0
- adaptive_serve-0.1.0/tests/test_smoke.py +6 -0
- adaptive_serve-0.1.0/tests/test_taxonomy.py +121 -0
- adaptive_serve-0.1.0/tests/test_telemetry.py +154 -0
- adaptive_serve-0.1.0/tests/test_torch_backend.py +160 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mandar Wagh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adaptive-serve
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Adaptive cloud-to-robot serving layer that scales robotics model quality to fit device, power, latency, and bandwidth constraints.
|
|
5
|
+
Author: Mandar Wagh
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mandarwagh9/adaptive-serve
|
|
8
|
+
Project-URL: Repository, https://github.com/mandarwagh9/adaptive-serve
|
|
9
|
+
Keywords: robotics,serving,inference,edge,vla,adaptive,cloud
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
20
|
+
Requires-Dist: ruff>=0.11; extra == "dev"
|
|
21
|
+
Provides-Extra: torch
|
|
22
|
+
Requires-Dist: torch>=2.0; extra == "torch"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<img src="https://raw.githubusercontent.com/mandarwagh9/adaptive-serve/main/assets/banner.png" alt="adaptive-serve" width="880">
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<a href="https://github.com/mandarwagh9/adaptive-serve/actions/workflows/ci.yml"><img src="https://github.com/mandarwagh9/adaptive-serve/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
31
|
+
<img src="https://img.shields.io/badge/python-3.10+-EDE8DD?style=flat-square&labelColor=0B0E14" alt="python 3.10+">
|
|
32
|
+
<img src="https://img.shields.io/badge/license-MIT-EDE8DD?style=flat-square&labelColor=0B0E14" alt="MIT">
|
|
33
|
+
<img src="https://img.shields.io/badge/lint-ruff-FFB000?style=flat-square&labelColor=0B0E14" alt="ruff">
|
|
34
|
+
<img src="https://img.shields.io/badge/tests-152_passing-FFB000?style=flat-square&labelColor=0B0E14" alt="152 tests passing">
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
# adaptive-serve
|
|
38
|
+
|
|
39
|
+
Adaptive cloud-to-robot serving layer for robotics models of all types.
|
|
40
|
+
|
|
41
|
+
It takes any trained robotics model and serves it to a robot, scaling model
|
|
42
|
+
quality up or down to fit the binding constraint: on-robot compute (TOPS/VRAM),
|
|
43
|
+
power budget, latency tolerance, and live network bandwidth. Think adaptive
|
|
44
|
+
bitrate streaming, but the renditions are model variants and the network is the
|
|
45
|
+
robot's compute and link.
|
|
46
|
+
|
|
47
|
+
The whole core runs with no GPU, no network, and no external dependencies. An
|
|
48
|
+
optional torch backend and a stdlib HTTP cloud adapter add real execution when
|
|
49
|
+
you want it.
|
|
50
|
+
|
|
51
|
+
## Why
|
|
52
|
+
|
|
53
|
+
A robot cannot round-trip to the cloud for every control step, and it must keep
|
|
54
|
+
acting if the link drops. adaptive-serve picks the right variant and serving mode
|
|
55
|
+
for the device in front of it, runs a slow cloud planner and a fast local reflex
|
|
56
|
+
loop at the same time, and degrades safely when the cloud goes away.
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install -e ".[dev]" # core plus test tooling
|
|
62
|
+
pip install -e ".[dev,torch]" # also pull torch for the real backend
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Try it
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
adaptive-serve demo # full end to end demo
|
|
69
|
+
adaptive-serve serve --model planner --vram 2 --bandwidth 200 --difficulty hard
|
|
70
|
+
adaptive-serve serve --model planner --vram 80 --bandwidth 0 --difficulty hard
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The same model adapts to the device, exactly like adaptive bitrate:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
device mode variant ~latency ms meets
|
|
77
|
+
tiny-edge-offline local planner-vlm:2B:int8 36.0 False
|
|
78
|
+
edge-weak-link split planner-vlm:7B:fp16 761.8 True
|
|
79
|
+
edge-fast-link cloud planner-vlm:7B:fp16 21.0 True
|
|
80
|
+
workstation local planner-vlm:7B:fp16 4.2 True
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
And it keeps acting through a cloud outage, degrading from NOMINAL to a latched
|
|
84
|
+
emergency stop only when the last plan is long gone:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
Multi-rate session with a cloud drop at 1000 ms:
|
|
88
|
+
reflex steps: 1200
|
|
89
|
+
plans published: 2
|
|
90
|
+
safety mode timeline: {'nominal': 200, 'degraded': 531, 'hold': 400, 'kill': 69}
|
|
91
|
+
final safety mode: kill
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Calibration: decide on real numbers, not guesses
|
|
95
|
+
|
|
96
|
+
By default the router uses portable heuristics for footprint and latency. To
|
|
97
|
+
ground its decisions in real hardware, measure actual models and route on those
|
|
98
|
+
numbers instead:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
adaptive-serve calibrate # measure real models -> calibration.json
|
|
102
|
+
adaptive-serve pipeline # calibrate -> route on measured -> run in torch
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`calibrate` records the exact parameter count, the weight memory at each
|
|
106
|
+
precision, and the measured forward latency per variant. A `ModelRegistry`
|
|
107
|
+
built with that table feeds the router measured footprints (heuristics remain the
|
|
108
|
+
fallback for any variant you have not measured), so a model that is actually small
|
|
109
|
+
gets served where the heuristic would have offloaded it.
|
|
110
|
+
|
|
111
|
+
Honest scope: weight bytes and params are device-independent and drive the VRAM
|
|
112
|
+
fit directly; latency is device-specific, so it stays informational. On a CPU box
|
|
113
|
+
the harness measures real but small reference models and INT8 via torch dynamic
|
|
114
|
+
quantization; the 7B/70B rungs and true INT4 need target hardware, which the same
|
|
115
|
+
harness supports. Requires the `torch` extra: `pip install -e ".[dev,torch]"`.
|
|
116
|
+
|
|
117
|
+
## Supported model classes
|
|
118
|
+
|
|
119
|
+
The registry and router are generic across these, never hardcoded to one:
|
|
120
|
+
|
|
121
|
+
- VLA / action policies (diffusion policies, ACT, flow-matching)
|
|
122
|
+
- world / dynamics models (Dreamer-style, latent predictors, video predictors)
|
|
123
|
+
- perception (detection, segmentation, depth, optical flow, 6DoF pose, keypoints)
|
|
124
|
+
- VLMs / high-level reasoners (planning, language grounding)
|
|
125
|
+
- state estimation / SLAM / odometry
|
|
126
|
+
- classical or learned planners and controllers
|
|
127
|
+
|
|
128
|
+
Each declares its role in the stack, native rate (Hz), latency budget, and which
|
|
129
|
+
scaling techniques it supports. Adding a new class touches no core.
|
|
130
|
+
|
|
131
|
+
## Architecture
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
DeviceProfile ---+
|
|
135
|
+
|
|
|
136
|
+
ModelSpec --> Registry: variant ladder (size x quant) per model, any class
|
|
137
|
+
|
|
|
138
|
+
v
|
|
139
|
+
Router: pick variant + quant + serving mode (local / cloud / split)
|
|
140
|
+
|
|
|
141
|
+
+--------------+--------------+
|
|
142
|
+
| |
|
|
143
|
+
Scaling strategies Orchestrator: cloud System-2 planner ~1 Hz
|
|
144
|
+
size/quant/input/exit/ + local System-1 reflex 50-1000 Hz
|
|
145
|
+
cascade/split |
|
|
146
|
+
| v
|
|
147
|
+
+---------------> Safety governor: hold / kill on loss
|
|
148
|
+
|
|
|
149
|
+
v
|
|
150
|
+
Runtime + backends: run local (stub or torch) or
|
|
151
|
+
offload over HTTP, fall back to local on failure
|
|
152
|
+
|
|
|
153
|
+
v
|
|
154
|
+
Telemetry: record every step
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Two invariants hold throughout, both covered by tests:
|
|
158
|
+
|
|
159
|
+
- **Generic across model classes.** The router and scaling cores dispatch on a
|
|
160
|
+
spec's declared role, tier, latency budget, and supported techniques, never on
|
|
161
|
+
class identity.
|
|
162
|
+
- **The robot never blocks on the cloud.** The reflex tier runs every control
|
|
163
|
+
tick. On cloud loss the planner stops publishing, the reflex keeps acting on
|
|
164
|
+
its last plan, the safety governor degrades to HOLD and latches KILL when the
|
|
165
|
+
plan is too stale, and a late or failed cloud call is dropped for a safe local
|
|
166
|
+
action rather than awaited.
|
|
167
|
+
|
|
168
|
+
## Develop
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
ruff check .
|
|
172
|
+
pytest
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See `STATUS.md` for the full component list and `PLAN.md` / `ADAPTERS_PLAN.md`
|
|
176
|
+
for the build history. MIT licensed.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/mandarwagh9/adaptive-serve/main/assets/banner.png" alt="adaptive-serve" width="880">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/mandarwagh9/adaptive-serve/actions/workflows/ci.yml"><img src="https://github.com/mandarwagh9/adaptive-serve/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
7
|
+
<img src="https://img.shields.io/badge/python-3.10+-EDE8DD?style=flat-square&labelColor=0B0E14" alt="python 3.10+">
|
|
8
|
+
<img src="https://img.shields.io/badge/license-MIT-EDE8DD?style=flat-square&labelColor=0B0E14" alt="MIT">
|
|
9
|
+
<img src="https://img.shields.io/badge/lint-ruff-FFB000?style=flat-square&labelColor=0B0E14" alt="ruff">
|
|
10
|
+
<img src="https://img.shields.io/badge/tests-152_passing-FFB000?style=flat-square&labelColor=0B0E14" alt="152 tests passing">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
# adaptive-serve
|
|
14
|
+
|
|
15
|
+
Adaptive cloud-to-robot serving layer for robotics models of all types.
|
|
16
|
+
|
|
17
|
+
It takes any trained robotics model and serves it to a robot, scaling model
|
|
18
|
+
quality up or down to fit the binding constraint: on-robot compute (TOPS/VRAM),
|
|
19
|
+
power budget, latency tolerance, and live network bandwidth. Think adaptive
|
|
20
|
+
bitrate streaming, but the renditions are model variants and the network is the
|
|
21
|
+
robot's compute and link.
|
|
22
|
+
|
|
23
|
+
The whole core runs with no GPU, no network, and no external dependencies. An
|
|
24
|
+
optional torch backend and a stdlib HTTP cloud adapter add real execution when
|
|
25
|
+
you want it.
|
|
26
|
+
|
|
27
|
+
## Why
|
|
28
|
+
|
|
29
|
+
A robot cannot round-trip to the cloud for every control step, and it must keep
|
|
30
|
+
acting if the link drops. adaptive-serve picks the right variant and serving mode
|
|
31
|
+
for the device in front of it, runs a slow cloud planner and a fast local reflex
|
|
32
|
+
loop at the same time, and degrades safely when the cloud goes away.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e ".[dev]" # core plus test tooling
|
|
38
|
+
pip install -e ".[dev,torch]" # also pull torch for the real backend
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Try it
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
adaptive-serve demo # full end to end demo
|
|
45
|
+
adaptive-serve serve --model planner --vram 2 --bandwidth 200 --difficulty hard
|
|
46
|
+
adaptive-serve serve --model planner --vram 80 --bandwidth 0 --difficulty hard
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The same model adapts to the device, exactly like adaptive bitrate:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
device mode variant ~latency ms meets
|
|
53
|
+
tiny-edge-offline local planner-vlm:2B:int8 36.0 False
|
|
54
|
+
edge-weak-link split planner-vlm:7B:fp16 761.8 True
|
|
55
|
+
edge-fast-link cloud planner-vlm:7B:fp16 21.0 True
|
|
56
|
+
workstation local planner-vlm:7B:fp16 4.2 True
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
And it keeps acting through a cloud outage, degrading from NOMINAL to a latched
|
|
60
|
+
emergency stop only when the last plan is long gone:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Multi-rate session with a cloud drop at 1000 ms:
|
|
64
|
+
reflex steps: 1200
|
|
65
|
+
plans published: 2
|
|
66
|
+
safety mode timeline: {'nominal': 200, 'degraded': 531, 'hold': 400, 'kill': 69}
|
|
67
|
+
final safety mode: kill
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Calibration: decide on real numbers, not guesses
|
|
71
|
+
|
|
72
|
+
By default the router uses portable heuristics for footprint and latency. To
|
|
73
|
+
ground its decisions in real hardware, measure actual models and route on those
|
|
74
|
+
numbers instead:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
adaptive-serve calibrate # measure real models -> calibration.json
|
|
78
|
+
adaptive-serve pipeline # calibrate -> route on measured -> run in torch
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`calibrate` records the exact parameter count, the weight memory at each
|
|
82
|
+
precision, and the measured forward latency per variant. A `ModelRegistry`
|
|
83
|
+
built with that table feeds the router measured footprints (heuristics remain the
|
|
84
|
+
fallback for any variant you have not measured), so a model that is actually small
|
|
85
|
+
gets served where the heuristic would have offloaded it.
|
|
86
|
+
|
|
87
|
+
Honest scope: weight bytes and params are device-independent and drive the VRAM
|
|
88
|
+
fit directly; latency is device-specific, so it stays informational. On a CPU box
|
|
89
|
+
the harness measures real but small reference models and INT8 via torch dynamic
|
|
90
|
+
quantization; the 7B/70B rungs and true INT4 need target hardware, which the same
|
|
91
|
+
harness supports. Requires the `torch` extra: `pip install -e ".[dev,torch]"`.
|
|
92
|
+
|
|
93
|
+
## Supported model classes
|
|
94
|
+
|
|
95
|
+
The registry and router are generic across these, never hardcoded to one:
|
|
96
|
+
|
|
97
|
+
- VLA / action policies (diffusion policies, ACT, flow-matching)
|
|
98
|
+
- world / dynamics models (Dreamer-style, latent predictors, video predictors)
|
|
99
|
+
- perception (detection, segmentation, depth, optical flow, 6DoF pose, keypoints)
|
|
100
|
+
- VLMs / high-level reasoners (planning, language grounding)
|
|
101
|
+
- state estimation / SLAM / odometry
|
|
102
|
+
- classical or learned planners and controllers
|
|
103
|
+
|
|
104
|
+
Each declares its role in the stack, native rate (Hz), latency budget, and which
|
|
105
|
+
scaling techniques it supports. Adding a new class touches no core.
|
|
106
|
+
|
|
107
|
+
## Architecture
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
DeviceProfile ---+
|
|
111
|
+
|
|
|
112
|
+
ModelSpec --> Registry: variant ladder (size x quant) per model, any class
|
|
113
|
+
|
|
|
114
|
+
v
|
|
115
|
+
Router: pick variant + quant + serving mode (local / cloud / split)
|
|
116
|
+
|
|
|
117
|
+
+--------------+--------------+
|
|
118
|
+
| |
|
|
119
|
+
Scaling strategies Orchestrator: cloud System-2 planner ~1 Hz
|
|
120
|
+
size/quant/input/exit/ + local System-1 reflex 50-1000 Hz
|
|
121
|
+
cascade/split |
|
|
122
|
+
| v
|
|
123
|
+
+---------------> Safety governor: hold / kill on loss
|
|
124
|
+
|
|
|
125
|
+
v
|
|
126
|
+
Runtime + backends: run local (stub or torch) or
|
|
127
|
+
offload over HTTP, fall back to local on failure
|
|
128
|
+
|
|
|
129
|
+
v
|
|
130
|
+
Telemetry: record every step
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Two invariants hold throughout, both covered by tests:
|
|
134
|
+
|
|
135
|
+
- **Generic across model classes.** The router and scaling cores dispatch on a
|
|
136
|
+
spec's declared role, tier, latency budget, and supported techniques, never on
|
|
137
|
+
class identity.
|
|
138
|
+
- **The robot never blocks on the cloud.** The reflex tier runs every control
|
|
139
|
+
tick. On cloud loss the planner stops publishing, the reflex keeps acting on
|
|
140
|
+
its last plan, the safety governor degrades to HOLD and latches KILL when the
|
|
141
|
+
plan is too stale, and a late or failed cloud call is dropped for a safe local
|
|
142
|
+
action rather than awaited.
|
|
143
|
+
|
|
144
|
+
## Develop
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
ruff check .
|
|
148
|
+
pytest
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
See `STATUS.md` for the full component list and `PLAN.md` / `ADAPTERS_PLAN.md`
|
|
152
|
+
for the build history. MIT licensed.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "adaptive-serve"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Adaptive cloud-to-robot serving layer that scales robotics model quality to fit device, power, latency, and bandwidth constraints."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Mandar Wagh" }]
|
|
13
|
+
keywords = ["robotics", "serving", "inference", "edge", "vla", "adaptive", "cloud"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
]
|
|
21
|
+
dependencies = []
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["pytest>=8", "ruff>=0.11"]
|
|
25
|
+
torch = ["torch>=2.0"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/mandarwagh9/adaptive-serve"
|
|
29
|
+
Repository = "https://github.com/mandarwagh9/adaptive-serve"
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
adaptive-serve = "adaptive_serve.cli:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
line-length = 100
|
|
39
|
+
src = ["src", "tests"]
|
|
40
|
+
extend-exclude = ["assets"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff.lint]
|
|
43
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
addopts = "-q"
|
|
48
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Adaptive cloud-to-robot serving layer.
|
|
2
|
+
|
|
3
|
+
Serves any trained robotics model to a robot, scaling model quality up or down
|
|
4
|
+
to fit the binding constraint: on-robot compute (TOPS/VRAM), power budget,
|
|
5
|
+
latency tolerance, and live network bandwidth.
|
|
6
|
+
|
|
7
|
+
The package is generic across model classes (action policies, world models,
|
|
8
|
+
perception, VLMs, state estimation, planners). The registry and router never
|
|
9
|
+
hardcode a single class; adding a new class must not touch the router core.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from adaptive_serve.backends import Backend, InferenceResult, LocalStubBackend
|
|
13
|
+
from adaptive_serve.calibration import CalibrationTable, Measurement, measure, run_calibration
|
|
14
|
+
from adaptive_serve.cloud_http import HttpCloudError, HttpCloudLink, HttpCloudPlanner
|
|
15
|
+
from adaptive_serve.orchestrator import (
|
|
16
|
+
AlwaysOnline,
|
|
17
|
+
CallableLink,
|
|
18
|
+
CloudLink,
|
|
19
|
+
Orchestrator,
|
|
20
|
+
OrchestratorTrace,
|
|
21
|
+
Plan,
|
|
22
|
+
PlannerRunner,
|
|
23
|
+
PlanSlot,
|
|
24
|
+
ReflexRunner,
|
|
25
|
+
ReflexStep,
|
|
26
|
+
ScheduledOutage,
|
|
27
|
+
)
|
|
28
|
+
from adaptive_serve.pipeline import PipelineResult, run_calibrated_pipeline
|
|
29
|
+
from adaptive_serve.profiler import (
|
|
30
|
+
AutoProbe,
|
|
31
|
+
BandwidthMonitor,
|
|
32
|
+
DeviceProbe,
|
|
33
|
+
DeviceProfile,
|
|
34
|
+
DeviceProfiler,
|
|
35
|
+
ReplayBandwidthMonitor,
|
|
36
|
+
StaticBandwidthMonitor,
|
|
37
|
+
StaticProbe,
|
|
38
|
+
default_profiler,
|
|
39
|
+
)
|
|
40
|
+
from adaptive_serve.registry import (
|
|
41
|
+
DEFAULT_QUANTS,
|
|
42
|
+
DEFAULT_SIZES,
|
|
43
|
+
ModelRegistry,
|
|
44
|
+
ModelVariant,
|
|
45
|
+
Quant,
|
|
46
|
+
RegisteredModel,
|
|
47
|
+
SizeTier,
|
|
48
|
+
)
|
|
49
|
+
from adaptive_serve.router import (
|
|
50
|
+
RoutingDecision,
|
|
51
|
+
ServingMode,
|
|
52
|
+
TaskDifficulty,
|
|
53
|
+
TierRouter,
|
|
54
|
+
)
|
|
55
|
+
from adaptive_serve.runtime import CloudExecutor, ExecutionResult, ServingRuntime
|
|
56
|
+
from adaptive_serve.safety import (
|
|
57
|
+
SafetyDecision,
|
|
58
|
+
SafetyGovernor,
|
|
59
|
+
SafetyMode,
|
|
60
|
+
SafetyObservation,
|
|
61
|
+
)
|
|
62
|
+
from adaptive_serve.scaling import (
|
|
63
|
+
CascadeStrategy,
|
|
64
|
+
EarlyExitStrategy,
|
|
65
|
+
InputScalingStrategy,
|
|
66
|
+
QuantLadderStrategy,
|
|
67
|
+
ScalingAction,
|
|
68
|
+
ScalingContext,
|
|
69
|
+
ScalingStrategy,
|
|
70
|
+
SizeLadderStrategy,
|
|
71
|
+
SplitInferenceStrategy,
|
|
72
|
+
StrategyRegistry,
|
|
73
|
+
default_strategy_registry,
|
|
74
|
+
estimate_latency_ms,
|
|
75
|
+
)
|
|
76
|
+
from adaptive_serve.serving import ServingLayer, ServingPlan
|
|
77
|
+
from adaptive_serve.taxonomy import (
|
|
78
|
+
ModelClass,
|
|
79
|
+
ModelSpec,
|
|
80
|
+
ScalingTechnique,
|
|
81
|
+
StackRole,
|
|
82
|
+
Tier,
|
|
83
|
+
get_model_class,
|
|
84
|
+
register_model_class,
|
|
85
|
+
registered_model_classes,
|
|
86
|
+
)
|
|
87
|
+
from adaptive_serve.telemetry import (
|
|
88
|
+
CallbackSink,
|
|
89
|
+
InMemorySink,
|
|
90
|
+
NdjsonSink,
|
|
91
|
+
NullSink,
|
|
92
|
+
TelemetryRecord,
|
|
93
|
+
TelemetryRecorder,
|
|
94
|
+
TelemetrySummary,
|
|
95
|
+
percentile,
|
|
96
|
+
)
|
|
97
|
+
from adaptive_serve.torch_backend import TorchBackend
|
|
98
|
+
|
|
99
|
+
__version__ = "0.1.0"
|
|
100
|
+
|
|
101
|
+
__all__ = [
|
|
102
|
+
# taxonomy
|
|
103
|
+
"ModelClass",
|
|
104
|
+
"ModelSpec",
|
|
105
|
+
"ScalingTechnique",
|
|
106
|
+
"StackRole",
|
|
107
|
+
"Tier",
|
|
108
|
+
"get_model_class",
|
|
109
|
+
"register_model_class",
|
|
110
|
+
"registered_model_classes",
|
|
111
|
+
# profiler
|
|
112
|
+
"AutoProbe",
|
|
113
|
+
"BandwidthMonitor",
|
|
114
|
+
"DeviceProbe",
|
|
115
|
+
"DeviceProfile",
|
|
116
|
+
"DeviceProfiler",
|
|
117
|
+
"ReplayBandwidthMonitor",
|
|
118
|
+
"StaticBandwidthMonitor",
|
|
119
|
+
"StaticProbe",
|
|
120
|
+
"default_profiler",
|
|
121
|
+
# registry
|
|
122
|
+
"DEFAULT_QUANTS",
|
|
123
|
+
"DEFAULT_SIZES",
|
|
124
|
+
"ModelRegistry",
|
|
125
|
+
"ModelVariant",
|
|
126
|
+
"Quant",
|
|
127
|
+
"RegisteredModel",
|
|
128
|
+
"SizeTier",
|
|
129
|
+
# router
|
|
130
|
+
"RoutingDecision",
|
|
131
|
+
"ServingMode",
|
|
132
|
+
"TaskDifficulty",
|
|
133
|
+
"TierRouter",
|
|
134
|
+
# scaling
|
|
135
|
+
"CascadeStrategy",
|
|
136
|
+
"EarlyExitStrategy",
|
|
137
|
+
"InputScalingStrategy",
|
|
138
|
+
"QuantLadderStrategy",
|
|
139
|
+
"ScalingAction",
|
|
140
|
+
"ScalingContext",
|
|
141
|
+
"ScalingStrategy",
|
|
142
|
+
"SizeLadderStrategy",
|
|
143
|
+
"SplitInferenceStrategy",
|
|
144
|
+
"StrategyRegistry",
|
|
145
|
+
"default_strategy_registry",
|
|
146
|
+
"estimate_latency_ms",
|
|
147
|
+
# orchestrator
|
|
148
|
+
"AlwaysOnline",
|
|
149
|
+
"CallableLink",
|
|
150
|
+
"CloudLink",
|
|
151
|
+
"Orchestrator",
|
|
152
|
+
"OrchestratorTrace",
|
|
153
|
+
"Plan",
|
|
154
|
+
"PlanSlot",
|
|
155
|
+
"PlannerRunner",
|
|
156
|
+
"ReflexRunner",
|
|
157
|
+
"ReflexStep",
|
|
158
|
+
"ScheduledOutage",
|
|
159
|
+
# safety
|
|
160
|
+
"SafetyDecision",
|
|
161
|
+
"SafetyGovernor",
|
|
162
|
+
"SafetyMode",
|
|
163
|
+
"SafetyObservation",
|
|
164
|
+
# serving facade
|
|
165
|
+
"ServingLayer",
|
|
166
|
+
"ServingPlan",
|
|
167
|
+
# telemetry
|
|
168
|
+
"CallbackSink",
|
|
169
|
+
"InMemorySink",
|
|
170
|
+
"NdjsonSink",
|
|
171
|
+
"NullSink",
|
|
172
|
+
"TelemetryRecord",
|
|
173
|
+
"TelemetryRecorder",
|
|
174
|
+
"TelemetrySummary",
|
|
175
|
+
"percentile",
|
|
176
|
+
# adapters
|
|
177
|
+
"Backend",
|
|
178
|
+
"PipelineResult",
|
|
179
|
+
"run_calibrated_pipeline",
|
|
180
|
+
"CalibrationTable",
|
|
181
|
+
"Measurement",
|
|
182
|
+
"measure",
|
|
183
|
+
"run_calibration",
|
|
184
|
+
"CloudExecutor",
|
|
185
|
+
"ExecutionResult",
|
|
186
|
+
"HttpCloudError",
|
|
187
|
+
"HttpCloudLink",
|
|
188
|
+
"HttpCloudPlanner",
|
|
189
|
+
"InferenceResult",
|
|
190
|
+
"LocalStubBackend",
|
|
191
|
+
"ServingRuntime",
|
|
192
|
+
"TorchBackend",
|
|
193
|
+
"__version__",
|
|
194
|
+
]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Inference backends.
|
|
2
|
+
|
|
3
|
+
A Backend turns a chosen ModelVariant into a runnable handle and executes it on
|
|
4
|
+
inputs, returning an InferenceResult with the output and the real measured (or
|
|
5
|
+
estimated) latency. The serving layer dispatches a ServingPlan to a backend to
|
|
6
|
+
actually run a model rather than only decide how to run it.
|
|
7
|
+
|
|
8
|
+
LocalStubBackend is a deterministic CPU backend with no ML framework dependency,
|
|
9
|
+
so the whole stack can run end to end on any machine. The torch-based backend
|
|
10
|
+
lives in its own module behind a lazy import so this one never pulls heavy deps.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import zlib
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from typing import Protocol
|
|
18
|
+
|
|
19
|
+
from adaptive_serve.profiler import DeviceProfile
|
|
20
|
+
from adaptive_serve.registry import ModelVariant
|
|
21
|
+
from adaptive_serve.scaling import estimate_latency_ms
|
|
22
|
+
|
|
23
|
+
# Latency used when no device profile is available to estimate against.
|
|
24
|
+
_DEFAULT_LATENCY_MS = 1.0
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class InferenceResult:
|
|
29
|
+
"""The output of running one variant on one set of inputs."""
|
|
30
|
+
|
|
31
|
+
output: object
|
|
32
|
+
latency_ms: float
|
|
33
|
+
variant_id: str
|
|
34
|
+
backend: str
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Backend(Protocol):
|
|
38
|
+
"""Loads and runs a model variant. The seam real engines implement."""
|
|
39
|
+
|
|
40
|
+
name: str
|
|
41
|
+
|
|
42
|
+
def load(self, variant: ModelVariant) -> object: ...
|
|
43
|
+
|
|
44
|
+
def infer(self, handle: object, inputs: object) -> InferenceResult: ...
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class LocalStubBackend:
|
|
48
|
+
"""A deterministic CPU backend that needs no ML framework.
|
|
49
|
+
|
|
50
|
+
It produces a reproducible digest of the inputs and a latency derived from the
|
|
51
|
+
variant footprint and the device profile, so the serving layer can be driven
|
|
52
|
+
end to end with no GPU. Same inputs and variant always give the same result.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
name = "local-stub"
|
|
56
|
+
|
|
57
|
+
def __init__(self, profile: DeviceProfile | None = None) -> None:
|
|
58
|
+
self._profile = profile
|
|
59
|
+
|
|
60
|
+
def load(self, variant: ModelVariant) -> ModelVariant:
|
|
61
|
+
# Nothing heavy to load; the variant itself is the handle.
|
|
62
|
+
return variant
|
|
63
|
+
|
|
64
|
+
def infer(self, handle: object, inputs: object) -> InferenceResult:
|
|
65
|
+
if not isinstance(handle, ModelVariant):
|
|
66
|
+
raise TypeError("handle must be a ModelVariant from load()")
|
|
67
|
+
variant = handle
|
|
68
|
+
digest = zlib.crc32(repr(inputs).encode("utf-8"))
|
|
69
|
+
latency = (
|
|
70
|
+
estimate_latency_ms(variant, self._profile)
|
|
71
|
+
if self._profile is not None
|
|
72
|
+
else _DEFAULT_LATENCY_MS
|
|
73
|
+
)
|
|
74
|
+
output = {
|
|
75
|
+
"variant_id": variant.variant_id,
|
|
76
|
+
"digest": digest,
|
|
77
|
+
"quality": variant.quality,
|
|
78
|
+
}
|
|
79
|
+
return InferenceResult(
|
|
80
|
+
output=output,
|
|
81
|
+
latency_ms=latency,
|
|
82
|
+
variant_id=variant.variant_id,
|
|
83
|
+
backend=self.name,
|
|
84
|
+
)
|