collimate-rl 0.3.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.
- collimate_rl-0.3.0/LICENSE +202 -0
- collimate_rl-0.3.0/PKG-INFO +256 -0
- collimate_rl-0.3.0/README.md +237 -0
- collimate_rl-0.3.0/collimate_rl/__init__.py +107 -0
- collimate_rl-0.3.0/collimate_rl/burst.py +243 -0
- collimate_rl-0.3.0/collimate_rl/client.py +496 -0
- collimate_rl-0.3.0/collimate_rl/fleet.py +514 -0
- collimate_rl-0.3.0/collimate_rl/gateway.py +751 -0
- collimate_rl-0.3.0/collimate_rl/harness.py +581 -0
- collimate_rl-0.3.0/collimate_rl/launch_view.py +606 -0
- collimate_rl-0.3.0/collimate_rl/local_backend.py +339 -0
- collimate_rl-0.3.0/collimate_rl/openenv/__init__.py +21 -0
- collimate_rl-0.3.0/collimate_rl/openenv/collimate_provider.py +364 -0
- collimate_rl-0.3.0/collimate_rl/rewards.py +370 -0
- collimate_rl-0.3.0/collimate_rl/rl_view.py +463 -0
- collimate_rl-0.3.0/collimate_rl/sandbox.py +448 -0
- collimate_rl-0.3.0/collimate_rl/seeds.py +90 -0
- collimate_rl-0.3.0/collimate_rl/skyrl/__init__.py +13 -0
- collimate_rl-0.3.0/collimate_rl/skyrl/collimate_code_env.py +273 -0
- collimate_rl-0.3.0/collimate_rl/slime/__init__.py +18 -0
- collimate_rl-0.3.0/collimate_rl/slime/reward.py +264 -0
- collimate_rl-0.3.0/collimate_rl/template.py +456 -0
- collimate_rl-0.3.0/collimate_rl/transport.py +101 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/PKG-INFO +256 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/SOURCES.txt +47 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/dependency_links.txt +1 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/entry_points.txt +3 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/requires.txt +9 -0
- collimate_rl-0.3.0/collimate_rl.egg-info/top_level.txt +1 -0
- collimate_rl-0.3.0/pyproject.toml +41 -0
- collimate_rl-0.3.0/setup.cfg +4 -0
- collimate_rl-0.3.0/tests/test_client.py +293 -0
- collimate_rl-0.3.0/tests/test_collimate_provider.py +278 -0
- collimate_rl-0.3.0/tests/test_file_io.py +193 -0
- collimate_rl-0.3.0/tests/test_fleet.py +262 -0
- collimate_rl-0.3.0/tests/test_gateway.py +310 -0
- collimate_rl-0.3.0/tests/test_gateway_sessions.py +182 -0
- collimate_rl-0.3.0/tests/test_grade.py +171 -0
- collimate_rl-0.3.0/tests/test_harness.py +201 -0
- collimate_rl-0.3.0/tests/test_launch_view.py +208 -0
- collimate_rl-0.3.0/tests/test_local_backend.py +70 -0
- collimate_rl-0.3.0/tests/test_rewards.py +63 -0
- collimate_rl-0.3.0/tests/test_rl_view.py +83 -0
- collimate_rl-0.3.0/tests/test_sandbox.py +62 -0
- collimate_rl-0.3.0/tests/test_seeds.py +80 -0
- collimate_rl-0.3.0/tests/test_skyrl_env.py +138 -0
- collimate_rl-0.3.0/tests/test_skyrl_gateway.py +104 -0
- collimate_rl-0.3.0/tests/test_slime_reward.py +174 -0
- collimate_rl-0.3.0/tests/test_transport.py +112 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: collimate-rl
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Use a Collimate microVM control plane as the sandboxed reward grader for RL post-training — one interface over the node-local daemon or the GA gateway (any col_* key tier); SkyRL, OpenEnv and slime adapters included.
|
|
5
|
+
Author-email: "Omer Gero (Gero Consulting)" <hello@collimate.ai>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://collimate.ai
|
|
8
|
+
Keywords: rl,rlhf,grpo,sandbox,microvm,skyrl,openenv,slime,reward
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Provides-Extra: skyrl
|
|
13
|
+
Requires-Dist: skyrl-gym; extra == "skyrl"
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
16
|
+
Provides-Extra: demo
|
|
17
|
+
Requires-Dist: rich>=13; extra == "demo"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# collimate-rl — Collimate for RL post-training
|
|
21
|
+
|
|
22
|
+
Run RL rollout execution and reward grading inside forked
|
|
23
|
+
[Collimate](https://collimate.ai) microVMs: each rollout gets an isolated,
|
|
24
|
+
reproducible copy-on-write fork of a warm template — isolation for untrusted
|
|
25
|
+
model output, density for the GRPO group fan-out — through the RL frameworks
|
|
26
|
+
you already use (SkyRL, OpenEnv, slime).
|
|
27
|
+
|
|
28
|
+
There are two ways to wire Collimate into an RL stack; this package ships both.
|
|
29
|
+
|
|
30
|
+
| Mode | What Collimate does | Needs | Status |
|
|
31
|
+
|---|---|---|---|
|
|
32
|
+
| **B — exec-grader** (this package) | runs each rollout in a forked microVM via `/v1/exec` to produce an isolated, reproducible **reward** | only today's control plane | ✅ done; tested vs real microVMs |
|
|
33
|
+
| **A — OpenEnv runtime** | runs an OpenEnv env-server **image** as a forked microVM, reached over a per-session endpoint | the control plane's `expose_ports` (per-clone DNAT) + an app-warm template (`WAIT_HTTP`) | ✅ end-to-end on KVM: `from_docker_image(provider=CollimateProvider)` drives `reset/step` over **WebSocket** into a fork that resumes a live server baked in the snapshot; 24 concurrent persistent-WS sessions / 0 leaked VMs. Provider in `collimate_rl.openenv` |
|
|
34
|
+
|
|
35
|
+
Mode B is itself a legitimate RL-environment integration: the environment logic
|
|
36
|
+
lives in the trainer, and the model's code is graded inside a Collimate microVM
|
|
37
|
+
instead of in-process — isolation for untrusted output, density for the GRPO
|
|
38
|
+
group fan-out, and an optional per-rollout seed for common random numbers.
|
|
39
|
+
|
|
40
|
+
## One interface, both transports, any key tier
|
|
41
|
+
|
|
42
|
+
Everything in this package — `grade`/`grade_batch`, `Sandbox`, and the three
|
|
43
|
+
framework adapters (SkyRL, OpenEnv, slime) — runs over **either** wire with the
|
|
44
|
+
**same interface**:
|
|
45
|
+
|
|
46
|
+
| transport | client | auth |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| node-local `serve` daemon (dev box, BYOC node, in-pod SESSION socket) | `CollimateClient` | none (node-local) |
|
|
49
|
+
| GA gateway (the managed cloud) | `GatewayClient` | Bearer `col_*` key — demo / pro / enterprise |
|
|
50
|
+
|
|
51
|
+
`GatewayClient` implements the daemon client's session surface 1:1
|
|
52
|
+
(`create_session` / `session_exec` / `exec_once` / `get_session` /
|
|
53
|
+
`list_sessions` / `delete_session`), and `collimate_rl.connect()` picks the
|
|
54
|
+
transport from what you name (explicit args first, then the environment):
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from collimate_rl import connect, grade, PropertyReward
|
|
58
|
+
|
|
59
|
+
client = connect() # env-resolved: in-pod socket >
|
|
60
|
+
# COLLIMATE_API_KEY (gateway) >
|
|
61
|
+
# COLLIMATE_SERVE_URL > localhost daemon
|
|
62
|
+
client = connect("http://127.0.0.1:8080") # a daemon, explicitly
|
|
63
|
+
client = connect(api_key="col_demo_...") # the gateway, any key tier
|
|
64
|
+
|
|
65
|
+
res = grade(client, "dkr-python311", candidate, spec) # identical either way
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Key-tier differences are enforced server-side and surface as **typed errors**
|
|
69
|
+
(`DemoTierLimit` with the friendly upgrade message, `quota_exceeded`, ...) —
|
|
70
|
+
never as silent behavior changes. One thing to size for: the gateway has no
|
|
71
|
+
one-shot `/v1/exec`, so `exec_once` composes create → exec → delete
|
|
72
|
+
client-side (reap guaranteed even on failure) and each in-flight grade briefly
|
|
73
|
+
holds one concurrency slot — keep `grade_batch(concurrency=...)` within your
|
|
74
|
+
tier's cap (demo: 8).
|
|
75
|
+
|
|
76
|
+
## Framework adapters
|
|
77
|
+
|
|
78
|
+
| framework | adapter | wiring |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| **SkyRL** | `collimate_rl.skyrl` `CollimateCodeEnv` | `register("collimate_code")` + `env_config` (add `api_key:` for the gateway) |
|
|
81
|
+
| **OpenEnv** (verl / TRL / TorchForge / ...) | `collimate_rl.openenv` `CollimateProvider` | `from_docker_image(image, provider=CollimateProvider(...))` |
|
|
82
|
+
| **slime** | `collimate_rl.slime` `reward_func` / `group_reward_func` | `--custom-rm-path collimate_rl.slime.reward_func` (no slime import, zero deps) |
|
|
83
|
+
|
|
84
|
+
## Install
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install collimate-rl # zero runtime deps (stdlib-only client)
|
|
88
|
+
pip install "collimate-rl[skyrl]" # + skyrl-gym for the SkyRL adapter
|
|
89
|
+
pip install "collimate-rl[demo]" # + rich, for the `collimate` visual CLI
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 30-second tour (no GPU, no KVM)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# an in-process stand-in for the real daemon (⚠️ dev/test only — NOT a sandbox):
|
|
96
|
+
python -m collimate_rl.local_backend --port 8080 &
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from collimate_rl import CollimateClient, PropertyReward, grade, group_seeds
|
|
101
|
+
|
|
102
|
+
client = CollimateClient("http://127.0.0.1:8080") # the local backend above —
|
|
103
|
+
# or a real daemon, or
|
|
104
|
+
# connect(api_key="col_...")
|
|
105
|
+
spec = PropertyReward(
|
|
106
|
+
reference=" return sum(c in 'aeiouAEIOU' for c in x)",
|
|
107
|
+
generator="''.join(random.choice('abcdEIOUxyz') for _ in range(8))",
|
|
108
|
+
k=16,
|
|
109
|
+
)
|
|
110
|
+
res = grade(client, "dkr-python311", completion_code, spec, seed="ab"*32)
|
|
111
|
+
print(res.reward, res.seed, res.seed_ack)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## What's here
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
collimate_rl/
|
|
118
|
+
client.py CollimateClient — stdlib client for /v1/sessions + /v1/exec
|
|
119
|
+
gateway.py GatewayClient — the GA gateway (Bearer col_* key, any tier),
|
|
120
|
+
incl. the daemon-parity session surface
|
|
121
|
+
transport.py connect() — one entry point, either transport
|
|
122
|
+
template.py Ready / Template.bake / Session — the gateway bake+session flow
|
|
123
|
+
rewards.py UnitTestReward / PropertyReward, grade(), grade_batch(),
|
|
124
|
+
reward_spec_from_ground_truth()
|
|
125
|
+
sandbox.py Sandbox — the in-worker-pod hot path (fork / exec / attach /
|
|
126
|
+
byte-exact download + upload_bytes); works over either transport
|
|
127
|
+
seeds.py common-random-numbers seed helpers (vanilla / crn / deterministic)
|
|
128
|
+
local_backend.py ⚠️ DEV/TEST in-process stand-in (NOT a sandbox) — runs the
|
|
129
|
+
exec contract locally so tests + demos work with no VMM
|
|
130
|
+
skyrl/ SkyRL BaseTextEnv adapter (CollimateCodeEnv) + register()
|
|
131
|
+
openenv/ OpenEnv ContainerProvider (CollimateProvider) — Mode A
|
|
132
|
+
slime/ slime custom-RM hooks (reward_func / group_reward_func)
|
|
133
|
+
tests/ 230+ tests, all run on a laptop (no KVM)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Each adapter's module docstring is its guide; the source tree additionally
|
|
137
|
+
carries worked examples (`examples/`) and a throughput benchmark
|
|
138
|
+
(`benchmarks/`).
|
|
139
|
+
|
|
140
|
+
**Validated end-to-end** against a real `serve` daemon forking actual microVMs
|
|
141
|
+
on a KVM host: GRPO-group rewards match the local backend exactly, common random
|
|
142
|
+
numbers reproduce on the real guest CRNG (`seed_ack: verified`), and every exec
|
|
143
|
+
is captured in a bit-for-bit replay manifest. The SkyRL layer is exercised
|
|
144
|
+
through the real `skyrl_gym.make()` registry (py3.12).
|
|
145
|
+
|
|
146
|
+
## File IO (byte-exact, no wire change)
|
|
147
|
+
|
|
148
|
+
`Sandbox.download(path) -> bytes` and `Sandbox.upload_bytes(path, data)` move
|
|
149
|
+
arbitrary bytes in and out of a live clone purely over the existing exec API:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
with Sandbox("dkr-python311") as sb:
|
|
153
|
+
sb.upload_bytes("/task/input.tar", tar_bytes) # verified in-guest (size+sha256)
|
|
154
|
+
r = sb.exec(command="cd /task && ./run.sh")
|
|
155
|
+
patch = sb.download("/task/out.patch") # bytes, byte-exact
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- **Byte-exact, both directions.** `upload_bytes` streams base64 chunks through
|
|
159
|
+
`printf | base64 -d` into a temp file, verifies size + sha256 **in-guest**,
|
|
160
|
+
then `mv`s into place — so a failed upload never leaves a truncated target,
|
|
161
|
+
and (unlike `exec(files=[...])`, which writes *text* via heredoc and appends
|
|
162
|
+
a trailing newline to content not ending in one) NULs, newlines and
|
|
163
|
+
missing-EOF-newlines survive exactly. `download` verifies the guest-side
|
|
164
|
+
sha256 against the decoded bytes before returning them.
|
|
165
|
+
- **Sentinel framing vs the merged-stderr hazard.** Guest stdout and stderr
|
|
166
|
+
share one pipe (the response's `stderr` is always `""`), so `download` frames
|
|
167
|
+
the base64 payload between per-call random sentinel lines and parses
|
|
168
|
+
*strictly* between them: noise outside the frame is ignored, noise that
|
|
169
|
+
breaks the frame (missing/duplicated sentinel, extra lines) raises, and noise
|
|
170
|
+
spliced into the payload line itself is caught by the sha256 check. A
|
|
171
|
+
download either returns exact bytes or raises — never silently corrupts.
|
|
172
|
+
- **Task vs infra errors.** In-guest failures (missing file, unwritable parent,
|
|
173
|
+
disk full, corrupted frame) raise the typed `CollimateTaskError` (a
|
|
174
|
+
`CollimateError` subclass carrying `exit_code` + the guest transcript in
|
|
175
|
+
`.output`); infra failures keep raising plain `CollimateError` exactly as
|
|
176
|
+
`exec` does.
|
|
177
|
+
- **Limits.** Downloads are capped at ~11 MiB per file (the guest agent's
|
|
178
|
+
16 MiB exec-output cap ÷ base64's 4/3 inflation; larger files fail with a
|
|
179
|
+
clear in-guest error). Uploads go one ~96 KiB base64 chunk per exec (the
|
|
180
|
+
composed command reaches the guest as a single `sh -c` argv string, bounded
|
|
181
|
+
by the kernel's 128 KiB per-string cap), i.e. ~15 execs — a few ms each on a
|
|
182
|
+
warm clone — per MiB. The guest needs a POSIX shell with a `printf` builtin
|
|
183
|
+
plus `base64` and `sha256sum` (busybox and coreutils both qualify).
|
|
184
|
+
|
|
185
|
+
## Per-rollout egress (net templates)
|
|
186
|
+
|
|
187
|
+
A `NET=1` template gives every fork its own netns, so egress is enforced **per
|
|
188
|
+
rollout**, not per host: two forks of the same template can run different
|
|
189
|
+
policies at the same time. Pass `egress=` when you open the sandbox:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
with Sandbox("py-swebench", egress={"mode": "none"}) as sb: ... # no egress at all
|
|
193
|
+
with Sandbox("py-swebench", egress={"preset": "rl-leakage"}) as sb: ... # block answer sources
|
|
194
|
+
with Sandbox("py-swebench", egress={"allow": ["pypi.org", "10.20.0.0/16"]}) as sb: ...
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Modes: `open` (the default when unset) | `none` | `allowlist` (`allow`) |
|
|
198
|
+
`denylist` (`deny`/`preset`). `allowlist`/`none` are fail-closed; a domain
|
|
199
|
+
`denylist` is best-effort (domains resolve at apply time). To default a whole
|
|
200
|
+
template, bake the policy in at build with the `EGRESS` knob (it writes the
|
|
201
|
+
`egress` object into `collimate.json`); a per-call `egress=` overrides it.
|
|
202
|
+
Requires `NET=1` (a vsock-only template rejects a policy with 400).
|
|
203
|
+
|
|
204
|
+
## Failure semantics (v0.1.1)
|
|
205
|
+
|
|
206
|
+
Production RL runs hit load-shed, drains, and long test suites; the SDK makes
|
|
207
|
+
each of those explicit instead of folding them into the reward signal:
|
|
208
|
+
|
|
209
|
+
- **Infra failures never masquerade as task failures.**
|
|
210
|
+
`grade_batch(..., on_infra_error="raise")` (the default) re-raises the first
|
|
211
|
+
backend error so the trainer resamples the group — averaging infra zeros into
|
|
212
|
+
GRPO advantages poisons the gradient. `"zero"` keeps positional alignment and
|
|
213
|
+
flags the miss (`GradeResult.infra_error=True`); `"skip"` drops it.
|
|
214
|
+
- **Draining nodes are retry-safe.** A node draining for a rolling upgrade
|
|
215
|
+
refuses new work with 503 *before* admitting it (no VM forked, no exec run),
|
|
216
|
+
so the client retries with backoff and then raises the typed
|
|
217
|
+
`CollimateDrainingError` — catch it and route the request to another node.
|
|
218
|
+
- **Retries back off with exponential full jitter,** bounded by a configurable
|
|
219
|
+
total budget (`CollimateClient(..., backoff=0.15, retry_budget=30.0)`), so a
|
|
220
|
+
shed GRPO group doesn't re-arrive as a synchronized thundering herd.
|
|
221
|
+
- **Long execs are never abandoned client-side.** The exec socket timeout is
|
|
222
|
+
`max(client.timeout, timeout_seconds + 30)` — a 30-minute test-suite exec
|
|
223
|
+
(`timeout_seconds=1800`; the daemon accepts up to 3600 s) holds the
|
|
224
|
+
connection instead of dying at the flat default.
|
|
225
|
+
- **Crashed-worker recovery.** `Sandbox.attach(client, session_id)` adopts an
|
|
226
|
+
already-live session (validated via `GET /v1/sessions/{id}`, nothing forked)
|
|
227
|
+
so a replacement worker or janitor can resume or reap an orphaned clone; the
|
|
228
|
+
context manager reaps on exit as usual.
|
|
229
|
+
- **stderr is merged into stdout, everywhere.** The guest agent runs execs with
|
|
230
|
+
both fds on one pipe (`stderr` in the response is always `""`), and the local
|
|
231
|
+
backend now reproduces that — write graders with a sentinel-prefixed reward
|
|
232
|
+
line rather than branching on `stderr` (see `RewardSpec.parse`).
|
|
233
|
+
|
|
234
|
+
## Tests
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
# from a source checkout of the package:
|
|
238
|
+
python -m pytest -q # ~18s, no network, no VMM
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The suite runs the real exec/reward contract against the in-process
|
|
242
|
+
`LocalCollimateBackend`, including the seed→reproducibility (CRN) property that
|
|
243
|
+
the whole common-random-numbers story rests on.
|
|
244
|
+
|
|
245
|
+
## Design notes
|
|
246
|
+
|
|
247
|
+
- **Reward stays the env's job.** Collimate only runs the grader faster + isolated;
|
|
248
|
+
it never inspects or alters the reward (the OpenEnv contract, honored here too).
|
|
249
|
+
- **The GRPO group fan-out maps to forks.** `grade_batch()` of K candidates = K
|
|
250
|
+
ephemeral VMs forked off one warm template — the after-setup group-fork.
|
|
251
|
+
- **CRN is opt-in and explicit.** `seeds.group_seeds(K, "crn")` pins one guest
|
|
252
|
+
seed across a prompt-group so env-noise cancels in the group-relative advantage;
|
|
253
|
+
`"vanilla"` keeps fresh entropy per rollout; `"deterministic"` removes env-noise
|
|
254
|
+
entirely (a control arm). Packaged for reuse.
|
|
255
|
+
- **Small public surface.** The integration only ever assumes "fork a warm
|
|
256
|
+
microVM and exec in it"; everything else stays behind the API.
|