SparkRT 0.1.0rc1__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 (48) hide show
  1. sparkrt-0.1.0rc1/LICENSE +164 -0
  2. sparkrt-0.1.0rc1/PKG-INFO +334 -0
  3. sparkrt-0.1.0rc1/README.md +316 -0
  4. sparkrt-0.1.0rc1/SparkRT.egg-info/PKG-INFO +334 -0
  5. sparkrt-0.1.0rc1/SparkRT.egg-info/SOURCES.txt +46 -0
  6. sparkrt-0.1.0rc1/SparkRT.egg-info/dependency_links.txt +1 -0
  7. sparkrt-0.1.0rc1/SparkRT.egg-info/requires.txt +7 -0
  8. sparkrt-0.1.0rc1/SparkRT.egg-info/top_level.txt +1 -0
  9. sparkrt-0.1.0rc1/pyproject.toml +39 -0
  10. sparkrt-0.1.0rc1/setup.cfg +4 -0
  11. sparkrt-0.1.0rc1/sparkrt/__init__.py +33 -0
  12. sparkrt-0.1.0rc1/sparkrt/adapters/__init__.py +13 -0
  13. sparkrt-0.1.0rc1/sparkrt/adapters/_pi05_kv_cache.py +107 -0
  14. sparkrt-0.1.0rc1/sparkrt/adapters/act_adapter.py +127 -0
  15. sparkrt-0.1.0rc1/sparkrt/adapters/pi05_adapter.py +381 -0
  16. sparkrt-0.1.0rc1/sparkrt/api.py +149 -0
  17. sparkrt-0.1.0rc1/sparkrt/backends/__init__.py +59 -0
  18. sparkrt-0.1.0rc1/sparkrt/backends/cudagraph.py +220 -0
  19. sparkrt-0.1.0rc1/sparkrt/backends/eager.py +38 -0
  20. sparkrt-0.1.0rc1/sparkrt/backends/torchcompile.py +114 -0
  21. sparkrt-0.1.0rc1/sparkrt/config/__init__.py +35 -0
  22. sparkrt-0.1.0rc1/sparkrt/config/loader.py +117 -0
  23. sparkrt-0.1.0rc1/sparkrt/config/presets/default.yaml +18 -0
  24. sparkrt-0.1.0rc1/sparkrt/config/presets/latency.yaml +25 -0
  25. sparkrt-0.1.0rc1/sparkrt/config/presets/memory.yaml +30 -0
  26. sparkrt-0.1.0rc1/sparkrt/config/presets/quality.yaml +21 -0
  27. sparkrt-0.1.0rc1/sparkrt/config/presets/safe.yaml +15 -0
  28. sparkrt-0.1.0rc1/sparkrt/config/runtime.py +205 -0
  29. sparkrt-0.1.0rc1/sparkrt/core/__init__.py +22 -0
  30. sparkrt-0.1.0rc1/sparkrt/core/adapter.py +146 -0
  31. sparkrt-0.1.0rc1/sparkrt/core/backend.py +50 -0
  32. sparkrt-0.1.0rc1/sparkrt/core/region.py +46 -0
  33. sparkrt-0.1.0rc1/sparkrt/core/shape.py +47 -0
  34. sparkrt-0.1.0rc1/sparkrt/eval/__init__.py +18 -0
  35. sparkrt-0.1.0rc1/sparkrt/eval/policy.py +125 -0
  36. sparkrt-0.1.0rc1/sparkrt/io/__init__.py +12 -0
  37. sparkrt-0.1.0rc1/sparkrt/io/checkpoint.py +319 -0
  38. sparkrt-0.1.0rc1/sparkrt/observation.py +210 -0
  39. sparkrt-0.1.0rc1/sparkrt/policy.py +136 -0
  40. sparkrt-0.1.0rc1/sparkrt/processors/__init__.py +6 -0
  41. sparkrt-0.1.0rc1/sparkrt/processors/base.py +30 -0
  42. sparkrt-0.1.0rc1/sparkrt/processors/sparkmind.py +40 -0
  43. sparkrt-0.1.0rc1/sparkrt/session/__init__.py +5 -0
  44. sparkrt-0.1.0rc1/sparkrt/session/session.py +117 -0
  45. sparkrt-0.1.0rc1/tests/test_core_smoke.py +140 -0
  46. sparkrt-0.1.0rc1/tests/test_eval_policy_wrapper.py +75 -0
  47. sparkrt-0.1.0rc1/tests/test_observation.py +170 -0
  48. sparkrt-0.1.0rc1/tests/test_public_api_contract.py +80 -0
@@ -0,0 +1,164 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work.
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form,
39
+ that is based on (or derived from) the Work and for which the editorial
40
+ revisions, annotations, elaborations, or other modifications represent, as a
41
+ whole, an original work of authorship. For the purposes of this License,
42
+ Derivative Works shall not include works that remain separable from, or
43
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
44
+ Works thereof.
45
+
46
+ "Contribution" shall mean any work of authorship, including the original
47
+ version of the Work and any modifications or additions to that Work or
48
+ Derivative Works thereof, that is intentionally submitted to Licensor for
49
+ inclusion in the Work by the copyright owner or by an individual or Legal
50
+ Entity authorized to submit on behalf of the copyright owner. For the
51
+ purposes of this definition, "submitted" means any form of electronic,
52
+ verbal, or written communication sent to the Licensor or its representatives,
53
+ including but not limited to communication on electronic mailing lists,
54
+ source code control systems, and issue tracking systems that are managed by,
55
+ or on behalf of, the Licensor for the purpose of discussing and improving the
56
+ Work, but excluding communication that is conspicuously marked or otherwise
57
+ designated in writing by the copyright owner as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
60
+ behalf of whom a Contribution has been received by Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
64
+ License, each Contributor hereby grants to You a perpetual, worldwide,
65
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
66
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
67
+ sublicense, and distribute the Work and such Derivative Works in Source or
68
+ Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of this
71
+ License, each Contributor hereby grants to You a perpetual, worldwide,
72
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
73
+ section) patent license to make, have made, use, offer to sell, sell, import,
74
+ and otherwise transfer the Work, where such license applies only to those
75
+ patent claims licensable by such Contributor that are necessarily infringed
76
+ by their Contribution(s) alone or by combination of their Contribution(s)
77
+ with the Work to which such Contribution(s) was submitted. If You institute
78
+ patent litigation against any entity (including a cross-claim or counterclaim
79
+ in a lawsuit) alleging that the Work or a Contribution incorporated within
80
+ the Work constitutes direct or contributory patent infringement, then any
81
+ patent licenses granted to You under this License for that Work shall
82
+ terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
85
+ Derivative Works thereof in any medium, with or without modifications, and in
86
+ Source or Object form, provided that You meet the following conditions:
87
+
88
+ (a) You must give any other recipients of the Work or Derivative Works a copy
89
+ of this License; and
90
+
91
+ (b) You must cause any modified files to carry prominent notices stating that
92
+ You changed the files; and
93
+
94
+ (c) You must retain, in the Source form of any Derivative Works that You
95
+ distribute, all copyright, patent, trademark, and attribution notices from the
96
+ Source form of the Work, excluding those notices that do not pertain to any
97
+ part of the Derivative Works; and
98
+
99
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
100
+ then any Derivative Works that You distribute must include a readable copy of
101
+ the attribution notices contained within such NOTICE file, excluding those
102
+ notices that do not pertain to any part of the Derivative Works, in at least
103
+ one of the following places: within a NOTICE text file distributed as part of
104
+ the Derivative Works; within the Source form or documentation, if provided
105
+ along with the Derivative Works; or within a display generated by the
106
+ Derivative Works, if and wherever such third-party notices normally appear.
107
+ The contents of the NOTICE file are for informational purposes only and do
108
+ not modify the License. You may add Your own attribution notices within
109
+ Derivative Works that You distribute, alongside or as an addendum to the
110
+ NOTICE text from the Work, provided that such additional attribution notices
111
+ cannot be construed as modifying the License.
112
+
113
+ You may add Your own copyright statement to Your modifications and may
114
+ provide additional or different license terms and conditions for use,
115
+ reproduction, or distribution of Your modifications, or for any such
116
+ Derivative Works as a whole, provided Your use, reproduction, and
117
+ distribution of the Work otherwise complies with the conditions stated in
118
+ this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the Work
130
+ and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work on an "AS IS" BASIS, WITHOUT WARRANTIES
134
+ OR CONDITIONS OF ANY KIND, either express or implied, including, without
135
+ limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
136
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
137
+ responsible for determining the appropriateness of using or redistributing
138
+ the Work and assume any risks associated with Your exercise of permissions
139
+ under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ Copyright 2026 Synria Robotics
@@ -0,0 +1,334 @@
1
+ Metadata-Version: 2.4
2
+ Name: SparkRT
3
+ Version: 0.1.0rc1
4
+ Summary: SparkRT - edge-side low-latency inference runtime for SparkMind2 robot/VLA/world models
5
+ Author: Synria Robotics
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Synria-Robotics/SparkRT
8
+ Project-URL: Repository, https://github.com/Synria-Robotics/SparkRT.git
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: numpy>=1.23
13
+ Provides-Extra: presets
14
+ Requires-Dist: omegaconf>=2.3; extra == "presets"
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=7; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # SparkRT
20
+
21
+ **SparkRT is a low-latency inference SDK for SparkMind2 robot policies.** Load a
22
+ trained checkpoint and run it from your control loop in a few lines - no
23
+ knowledge of SparkMind2 internals, tensor layouts, or preprocessor key names
24
+ required:
25
+
26
+ ```python
27
+ import sparkrt
28
+ from sparkrt import Observation
29
+
30
+ policy = sparkrt.load_policy("/path/to/checkpoints/020000/pretrained_model")
31
+
32
+ obs = Observation(
33
+ images={"image": rgb_frame, "image2": wrist_frame}, # numpy HWC RGB uint8
34
+ state=robot_state, # 1-D float array
35
+ instruction="pick up the object and place it in the basket",
36
+ )
37
+ action = policy.step(obs) # -> numpy action for your robot
38
+ ```
39
+
40
+ Under the hood SparkRT wraps trained SparkMind2 agents and optimizes the
41
+ action-inference hot path without changing SparkMind2 model definitions,
42
+ checkpoint formats, or pre/post-processing logic:
43
+
44
+ - SparkMind2 owns training, checkpoints, model modules, normalization,
45
+ tokenizers, environment logic, and evaluation metrics.
46
+ - SparkRT owns the ergonomic `Policy` SDK, inference sessions, action queues,
47
+ runtime configuration, and pluggable execution backends.
48
+
49
+ Detailed benchmark results and experiment history are kept in
50
+ [docs/EXPERIMENTS.md](docs/EXPERIMENTS.md). Backend integration guidance is in
51
+ [docs/INTEGRATION.md](docs/INTEGRATION.md).
52
+
53
+ ## Status
54
+
55
+ SparkRT currently supports:
56
+
57
+ - ACT policies (single-shot action chunking, optional temporal ensemble).
58
+ - Pi0.5 policies (vision-language-action, flow-matching denoising).
59
+ - Eager PyTorch execution.
60
+ - CUDA Graph execution for fixed-shape hot regions.
61
+ - TorchCompile execution for fused PyTorch/Inductor kernels.
62
+ - Preset-based runtime configuration.
63
+ - A SparkMind2 LIBERO eval wrapper for development certification.
64
+
65
+ The public SDK is Python-first. Native C++/CUDA or TensorRT backends can be added
66
+ later behind the same `ExecutionBackend` contract.
67
+
68
+ ## Installation
69
+
70
+ Install inside the SparkMind2 environment:
71
+
72
+ ```bash
73
+ source /path/to/SparkMind2/.venv/bin/activate
74
+ pip install -e /path/to/SparkRT
75
+ ```
76
+
77
+ SparkMind2 is a local dependency and should be installed or available on
78
+ `PYTHONPATH` separately. `torch` is intentionally not pinned by SparkRT so the
79
+ runtime can use the CUDA/Torch build provided by the target machine.
80
+
81
+ YAML presets require the optional preset extra:
82
+
83
+ ```bash
84
+ pip install -e '/path/to/SparkRT[presets]'
85
+ ```
86
+
87
+ ## Loading a Policy
88
+
89
+ Load a SparkMind2 `pretrained_model` checkpoint directly:
90
+
91
+ ```python
92
+ import sparkrt
93
+ from sparkrt import RuntimeConfig
94
+
95
+ policy = sparkrt.load_policy(
96
+ "/path/to/checkpoints/020000/pretrained_model",
97
+ config=RuntimeConfig.from_preset("latency"), # optional; no config defaults to eager
98
+ )
99
+ ```
100
+
101
+ Or wrap an agent that SparkMind2 has already constructed:
102
+
103
+ ```python
104
+ import sparkrt
105
+
106
+ policy = sparkrt.from_sparkmind_agent(agent, config=RuntimeConfig.from_preset("quality"))
107
+ ```
108
+
109
+ Both return a `Policy`. Inspect what the policy expects before building inputs:
110
+
111
+ ```python
112
+ policy.camera_names # e.g. ("image", "image2") or ("top",)
113
+ policy.state_dim # length of the state vector (0 if unused)
114
+ policy.requires_instruction # True for Pi0.5, False for ACT
115
+ policy.action_dim # environment action dimensionality
116
+ ```
117
+
118
+ ## Building an Observation
119
+
120
+ `policy.step(obs)` takes an `Observation` describing one timestep. You supply raw
121
+ camera frames and the robot state with **friendly camera names**; SparkRT handles
122
+ the channel-order, dtype, normalization, batching, and tokenization internally.
123
+
124
+ | Field | Type | Notes |
125
+ |-------|------|-------|
126
+ | `images` | `dict[str, ndarray]` | Keyed by `policy.camera_names`. Each frame: NumPy (or torch) **HWC RGB**, `uint8` `[0,255]` or float `[0,1]`. CHW is also accepted. A single-camera policy may take a bare array. |
127
+ | `state` | 1-D array | Length `policy.state_dim`. Any range - SparkRT applies the checkpoint's normalization. |
128
+ | `instruction` | `str` or `None` | Required when `policy.requires_instruction` is `True` (Pi0.5). Ignored by ACT. |
129
+
130
+ Image frames are RGB with no batch dimension; SparkRT converts `HWC -> CHW`,
131
+ scales `uint8 -> [0,1]`, and lets the checkpoint preprocessor handle batching.
132
+
133
+ ### ACT example (images + state, no language)
134
+
135
+ ACT is a deterministic single-camera policy with no instruction:
136
+
137
+ ```python
138
+ import numpy as np
139
+ import sparkrt
140
+ from sparkrt import Observation
141
+
142
+ policy = sparkrt.load_policy("/path/to/act/checkpoints/200000/pretrained_model")
143
+ # policy.camera_names == ("top",); policy.state_dim == 14; requires_instruction == False
144
+
145
+ policy.reset() # at the start of each episode
146
+ for _ in range(horizon):
147
+ obs = Observation(
148
+ images={"top": camera_rgb}, # (480, 640, 3) uint8 HWC RGB
149
+ state=joint_positions, # shape (14,) float
150
+ )
151
+ action = policy.step(obs) # numpy action, shape (action_dim,)
152
+ robot.apply(action)
153
+ ```
154
+
155
+ ### Pi0.5 example (multi-camera + state + instruction)
156
+
157
+ Pi0.5 is a vision-language-action policy with two cameras and a task prompt:
158
+
159
+ ```python
160
+ import numpy as np
161
+ import sparkrt
162
+ from sparkrt import Observation, RuntimeConfig
163
+
164
+ policy = sparkrt.load_policy(
165
+ "/path/to/pi05/checkpoints/020000/pretrained_model",
166
+ config=RuntimeConfig.from_preset("latency"),
167
+ )
168
+ # policy.camera_names == ("image", "image2"); policy.state_dim == 8; requires_instruction == True
169
+
170
+ policy.reset()
171
+ for _ in range(horizon):
172
+ obs = Observation(
173
+ images={
174
+ "image": base_rgb, # (256, 256, 3) uint8 HWC RGB
175
+ "image2": wrist_rgb, # (256, 256, 3) uint8 HWC RGB
176
+ },
177
+ state=robot_state, # shape (8,) float
178
+ instruction="pick up the object and place it in the basket",
179
+ )
180
+ action = policy.step(obs)
181
+ robot.apply(action)
182
+ ```
183
+
184
+ For advanced use (parity checks, raw chunk prediction, custom loops) the
185
+ underlying session is available as `policy.session`.
186
+
187
+ ## Runtime Presets
188
+
189
+ Built-in presets live under [sparkrt/config/presets](sparkrt/config/presets).
190
+ They are intended as named deployment profiles rather than one-off benchmark
191
+ commands. Calling `sparkrt.load_policy(..., config=None)` uses the eager backend;
192
+ `RuntimeConfig()` has the same dependency-light eager default. Presets are
193
+ explicit opt-in profiles and require `sparkrt[presets]` / `omegaconf`.
194
+
195
+ | Preset | Purpose |
196
+ |--------|---------|
197
+ | `default` / `safe` | Conservative CUDA Graph path with the checkpoint's original Pi0.5 schedule. Use when bit-exact behavior versus eager SparkMind2 is required. |
198
+ | `quality` | Conservative TorchCompile path with the full Pi0.5 denoise schedule. Use when you want compile acceleration while avoiding reduced-step solver risk. |
199
+ | `latency` | Aggressive TorchCompile path with fewer Pi0.5 denoise steps. Use when lowest single-stream latency is more important than strict task-level stability. |
200
+ | `memory` | Development profile for the INT8-artifact memory path. Artifact loading is currently handled by the quantization scripts, not the public `load_policy` API. |
201
+
202
+ Override individual fields when needed:
203
+
204
+ ```python
205
+ from sparkrt.config import RuntimeConfig
206
+
207
+ cfg = RuntimeConfig.from_preset("quality", kind="torchcompile")
208
+ cfg = RuntimeConfig.from_preset("latency", num_steps=8)
209
+ ```
210
+
211
+ Programmatic configuration is also available for deployments that should not
212
+ load YAML:
213
+
214
+ ```python
215
+ from sparkrt.config import RuntimeConfig, BackendConfig, Pi05RuntimeConfig
216
+
217
+ cfg = RuntimeConfig(
218
+ backend=BackendConfig(kind="torchcompile"),
219
+ pi05=Pi05RuntimeConfig(num_steps=10, schedule="uniform"),
220
+ device="cuda:0",
221
+ )
222
+ ```
223
+
224
+ ## Backend Integration
225
+
226
+ Recommended service shape:
227
+
228
+ 1. Load one SparkRT `Policy` per worker process and robot/environment stream.
229
+ 2. Warm the policy during worker startup, especially for TorchCompile.
230
+ 3. Call `policy.reset()` when the task changes or a new episode starts.
231
+ 4. Call `policy.step(obs)` from the control loop.
232
+ 5. Do not share a single stateful policy across concurrent tasks.
233
+
234
+ For SparkMind2 eval flows that already run the policy pre/post-processors, use
235
+ `sparkrt.eval.PreprocessedRuntimePolicy` rather than passing a `Policy` /
236
+ `InferenceSession` directly. This avoids applying normalization and action
237
+ post-processing twice.
238
+
239
+ See [docs/INTEGRATION.md](docs/INTEGRATION.md) for the full integration plan,
240
+ lifecycle recommendations, concurrency model, and failure handling.
241
+
242
+ ## Architecture
243
+
244
+ ```text
245
+ Observation (friendly camera names)
246
+ -> Policy (SDK surface: step / reset / discovery)
247
+ -> InferenceSession (stateful action queue / reset semantics)
248
+ -> SparkMind processor (normalize / tokenize)
249
+ -> model adapter (model orchestration, including Pi0.5 denoising)
250
+ -> backend-compiled Regions (eager / CUDA Graph / TorchCompile)
251
+ -> SparkMind processor (action postprocess)
252
+ -> action
253
+ ```
254
+
255
+ | Layer | Package | Responsibility |
256
+ |-------|---------|----------------|
257
+ | Processors | `sparkrt.processors` | Convert observations to model-ready batches and convert model actions back to environment actions. |
258
+ | Adapters | `sparkrt.adapters` | Describe model computation as named fixed-shape `Region`s and own model-specific orchestration such as the Pi0.5 denoise loop. |
259
+ | Backends | `sparkrt.backends` | Execute regions with eager PyTorch, CUDA Graph replay, or TorchCompile. |
260
+ | Session | `sparkrt.session` | Own runtime state, action-chunk queues, reset semantics, and the model-agnostic action loop. |
261
+ | Config | `sparkrt.config` | Provide frozen dataclass configuration plus optional YAML presets. |
262
+
263
+ The core contracts in `sparkrt.core` are intentionally lightweight and import
264
+ without SparkMind2 or torch.
265
+
266
+ ## Development
267
+
268
+ Run dependency-light tests:
269
+
270
+ ```bash
271
+ python -m pytest tests/ -q
272
+ ```
273
+
274
+ Run the main Pi0.5 runtime benchmark:
275
+
276
+ ```bash
277
+ CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl \
278
+ PYTHONPATH=/path/to/SparkRT:/path/to/SparkMind2 \
279
+ python scripts/bench/bench_pi05_runtime.py \
280
+ --checkpoint /path/to/pi05/pretrained_model \
281
+ --backend torchcompile --num-steps 10 --schedule uniform
282
+ ```
283
+
284
+ Run the development LIBERO success-rate runner:
285
+
286
+ ```bash
287
+ CUDA_VISIBLE_DEVICES=0 MUJOCO_GL=egl PYOPENGL_PLATFORM=egl \
288
+ PYTHONPATH=/path/to/SparkMind2:/path/to/SparkRT \
289
+ python scripts/eval/run_libero_eval_sparkrt.py \
290
+ --checkpoint /path/to/pretrained_model \
291
+ --preset quality \
292
+ --n-episodes 5 \
293
+ --seed 1000 \
294
+ --output-dir runs/my_eval
295
+ ```
296
+
297
+ TorchCompile has a large cold-start cost. Use a persistent Inductor cache for
298
+ long-running workers:
299
+
300
+ ```bash
301
+ export TORCHINDUCTOR_CACHE_DIR=$HOME/.cache/sparkrt/inductor
302
+ ```
303
+
304
+ ## Documentation
305
+
306
+ - [docs/INTEGRATION.md](docs/INTEGRATION.md): service/backend integration plan.
307
+ - [docs/EXPERIMENTS.md](docs/EXPERIMENTS.md): benchmark and accuracy results.
308
+ - [scripts/README.md](scripts/README.md): developer script reference.
309
+
310
+ ## Repository Layout
311
+
312
+ ```text
313
+ sparkrt/
314
+ api.py public load_policy / from_sparkmind_agent entry points
315
+ policy.py Policy SDK facade (step / reset / discovery)
316
+ observation.py Observation input type + camera-name conversion
317
+ config/ RuntimeConfig dataclasses and YAML presets
318
+ core/ backend, adapter, region, and shape contracts
319
+ processors/ SparkMind processor reuse layer
320
+ adapters/ ACT and Pi0.5 model adapters
321
+ backends/ eager, cudagraph, and torchcompile executors
322
+ session/ stateful inference session
323
+ io/ SparkMind2 checkpoint loading helpers
324
+ eval/ SparkMind2 eval-compatible policy wrapper
325
+
326
+ scripts/
327
+ bench/ latency, profiling, and parity scripts
328
+ eval/ LIBERO dev eval runner
329
+ quant/ INT8 artifact export and benchmark scripts
330
+
331
+ docs/
332
+ EXPERIMENTS.md
333
+ INTEGRATION.md
334
+ ```