cortexgrid 0.2.85__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.
@@ -0,0 +1,31 @@
1
+ .DS_Store
2
+ *.local
3
+ .env
4
+ .env.head
5
+ .venv
6
+ __pycache__/
7
+ *.py[cod]
8
+ *.egg-info/
9
+ dist/
10
+ build/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+ .pytest_cache/
14
+ .terraform
15
+ *.tfstate
16
+ *.tfstate.backup
17
+ .terraform.lock.hcl
18
+ terraform/website/terraform.tfvars
19
+
20
+ # Lambda build artifacts
21
+ lambda/*/node_modules
22
+ lambda/*.zip
23
+
24
+ # claude stuff
25
+ .claude/
26
+
27
+ # local infra config
28
+ infra-config.yaml
29
+
30
+ # kustomize helmCharts pull cache (created by local `kustomize build --enable-helm`)
31
+ k8s/argo_deployments/*/arc_runner_set/charts/
@@ -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,199 @@
1
+ Metadata-Version: 2.5
2
+ Name: cortexgrid
3
+ Version: 0.2.85
4
+ Summary: Connect your ML code to the RoboLab compute cluster — Ray, MLflow, and S3
5
+ Project-URL: Homepage, https://github.com/robodatalab/cortexgrid
6
+ Project-URL: Repository, https://github.com/robodatalab/cortexgrid
7
+ Project-URL: Documentation, https://github.com/robodatalab/cortexgrid/blob/main/docs/cortexgrid/README.md
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.11
11
+ Requires-Dist: boto3>=1.34
12
+ Requires-Dist: cloudpickle>=3.0
13
+ Requires-Dist: fabric>=3.2.3
14
+ Requires-Dist: haikunator>=2.1.0
15
+ Requires-Dist: mlflow<4,>=3.11
16
+ Requires-Dist: pip>=23.0
17
+ Requires-Dist: pydantic-settings>=2.13.1
18
+ Requires-Dist: pydantic>=2.13.3
19
+ Requires-Dist: pydotenv>=0.0.7
20
+ Requires-Dist: python-dotenv>=1.2.2
21
+ Requires-Dist: pyyaml>=6.0.3
22
+ Requires-Dist: ray[default]<3,>=2.9
23
+ Requires-Dist: requests>=2.31
24
+ Requires-Dist: setuptools>=82.0.1
25
+ Requires-Dist: tqdm>=4.60
26
+ Description-Content-Type: text/markdown
27
+
28
+ # cortexgrid
29
+
30
+ `cortexgrid` is a Python library that connects your ML code to the deployed infrastructure. It wraps Ray, MLflow, and S3/MinIO so your training scripts don't need to know about URLs, credentials, or service endpoints.
31
+
32
+ ### Installation
33
+
34
+ Add `cortexgrid` as a dependency in your project's `pyproject.toml`:
35
+
36
+ ```toml
37
+ [project]
38
+ dependencies = [
39
+ "cortexgrid",
40
+ ]
41
+ ```
42
+
43
+ Then `uv sync` to install it, and point it at the head's secrets server (reachable over the tailnet):
44
+
45
+ ```bash
46
+ export CORTEXGRID_HEAD_URL=http://robolab-head:7700
47
+ ```
48
+
49
+ ### Usage
50
+
51
+ ```python
52
+ import cortexgrid
53
+
54
+ cortexgrid.init(experiment="weather-forecast")
55
+ ```
56
+
57
+ That single call reads the service URLs from the head's secrets server at `$CORTEXGRID_HEAD_URL` and connects to all services through them. It also creates (or finds) the named MLflow experiment and starts a new run inside it. Omit `experiment=` to auto-generate a unique name like `funky-koval-12`.
58
+
59
+ **One experiment per binary run.** `cortexgrid.init()` may only be called once per process. Every subsequent `cortexgrid.log_metric`, `cortexgrid.log_artifact`, checkpoint, and `cortexgrid.remote()` submission is scoped to that experiment+run. Remote jobs dispatched by the control plane inherit the experiment+run via the pickled payload, so their logging flows into the same MLflow run as the parent binary.
60
+
61
+ #### Experiment tracking (MLflow)
62
+
63
+ ```python
64
+ cortexgrid.init(experiment="weather-forecast")
65
+
66
+ cortexgrid.log_params({"lr": 1e-3, "epochs": 20, "batch_size": 64})
67
+
68
+ for epoch in range(20):
69
+ loss = train_one_epoch(model, dataloader)
70
+ cortexgrid.log_metric("loss", loss, step=epoch)
71
+
72
+ if epoch % 5 == 0:
73
+ with cortexgrid.checkpoint() as ckpt:
74
+ ckpt.epoch = epoch
75
+ ckpt.save_training_state(model, optimizer)
76
+ ```
77
+
78
+ No run-scoping context manager — `init()` starts the run, and every subsequent logging call flows into it. Metrics and artifacts are logged to the MLflow server on the DGX. View them at `http://<DGX_IP>:5000`.
79
+
80
+ #### Checkpointing and resuming
81
+
82
+ Inside a cortexgrid job, `cortexgrid.checkpoint()` returns an attribute-based checkpoint object that persists to MLflow artifacts when its `with` block exits. On job restart (either manual retry or `retry=True`), `cortexgrid.resume()` returns the last checkpoint for the same job ID, or `None` if there isn't one.
83
+
84
+ ```python
85
+ ckpt = cortexgrid.resume()
86
+ if ckpt:
87
+ ckpt.restore_training_state(model, optimizer)
88
+ start_epoch = ckpt.epoch + 1
89
+ else:
90
+ start_epoch = 0
91
+
92
+ for epoch in range(start_epoch, 20):
93
+ train_one_epoch(model, dataloader)
94
+ with cortexgrid.checkpoint() as ckpt:
95
+ ckpt.epoch = epoch
96
+ ckpt.save_training_state(model, optimizer)
97
+ ```
98
+
99
+ You can assign any cloudpickle-compatible or torch-serializable value as an attribute on the checkpoint (`ckpt.metric = 0.93`, `ckpt.weights = model.state_dict()`); the `save_training_state`/`restore_training_state` helpers are a shortcut for the common model+optimizer pair.
100
+
101
+ #### Distributed compute (jobs control plane)
102
+
103
+ ```python
104
+ def train_step(batch):
105
+ # runs on the DGX GPU
106
+ # MLflow and S3 env vars are injected automatically
107
+ return loss
108
+
109
+ job_id = cortexgrid.remote(train_step, batch, num_gpus=1, retry=True)
110
+ print(f"Submitted: {job_id}")
111
+ ```
112
+
113
+ `cortexgrid.remote` submits a job *request* (a pickled payload plus a `JobLifecycle` record) to MLflow and returns a job ID string immediately. It does not wait for the job to run or finish — use the UI at `http://<DGX_IP>:8000`, or poll `cortexgrid.list_experiment_run_jobs(run_id)`, to observe status.
114
+
115
+ A separate service — the **jobs control plane** — polls MLflow for pending job requests, matches them against the set of Ray submissions the cluster already has, and submits anything missing. It is also responsible for retrying failed jobs and honouring user-requested stops.
116
+
117
+ Each submission captures the code and dependencies the entry function needs automatically ([_bundle.py](https://github.com/robodatalab/cortexgrid/blob/main/cortexgrid/_bundle.py)):
118
+ - `bundle(entry)` traces the import graph from the function's source file, resolving each import the way the interpreter does (via `sys.path`), and returns every file needed to run it -- your own modules and third-party packages alike, wherever they live. The standard library is excluded (it ships with the interpreter)
119
+ - Everything ships **as source**: the bundle is staged at each file's import path and tarred into the Ray `working_dir`. Nothing is `pip`-installed on the worker
120
+ - Dependencies the worker image already has are subtracted rather than shipped: `bundle(entry) - worker_provides()`, where `worker_provides()` is the bundle of the packages baked into the ray image (torch and its CUDA stack, ray, mlflow, ...). See [k8s/docker/ray/Dockerfile](https://github.com/robodatalab/cortexgrid/blob/main/k8s/docker/ray/Dockerfile)
121
+ - Injects MLflow/S3 credentials so task code running on the DGX can reach all services
122
+
123
+ ##### Retries
124
+
125
+ Pass `retry=True` and the control plane will resubmit the job whenever Ray reports the most recent attempt as `FAILED`. Retries are **unbounded by design**: the intended way to end a retry loop is to stop the job manually from the UI (which flips the `stop_requested` latch on the lifecycle, and the control plane stops the current Ray attempt on its next poll). This keeps the retry policy simple — you don't have to predict a good `max_retries` up front — and puts the human in the loop for anything that's failing persistently.
126
+
127
+ ##### Stopping a job
128
+
129
+ ```python
130
+ cortexgrid.stop_experiment_run_jobs(run_id) # stops every job in the run
131
+ ```
132
+
133
+ `stop_experiment_run_jobs` never touches Ray directly. It only flips `stop_requested` on each job's lifecycle record in MLflow. The control plane observes the flag on its next poll and calls `ray.stop_job` for any attempt that has reached Ray. For jobs that have not yet been submitted, the same flag short-circuits the submission path inside the worker.
134
+
135
+ #### Object storage (S3/MinIO)
136
+
137
+ ```python
138
+ cortexgrid.upload("data/output.parquet", bucket="ray-checkpoints", key="run-42/output.parquet")
139
+ cortexgrid.download("ray-checkpoints", "run-42/output.parquet", local_path="./output.parquet")
140
+
141
+ # or get the raw boto3 client
142
+ s3 = cortexgrid.get_s3_client()
143
+ ```
144
+
145
+ Works with MinIO on the DGX today, real S3 on AWS tomorrow — same code.
146
+
147
+ #### Getting raw clients
148
+
149
+ ```python
150
+ mlflow_client = cortexgrid.get_mlflow_client() # mlflow.tracking.MlflowClient
151
+ s3_client = cortexgrid.get_s3_client() # boto3 S3 client
152
+ ```
153
+
154
+ #### Model registry and serving
155
+
156
+ Save a trained model's weights together with the serve-app that fronts it, then deploy it as a Ray Serve application:
157
+
158
+ ```python
159
+ saved = cortexgrid.save_model(weights_dir, MyServeApp, family="qwen", suffix="instruct")
160
+ deployed = cortexgrid.deploy_model("qwen", "instruct", saved.run_name, wait=True)
161
+ print(deployed.url)
162
+ ```
163
+
164
+ `save_model` is synchronous (registry lifecycle: `uploading` -> `ready`); `deploy_model` schedules the serving lifecycle (`deploying` -> `running`). See [model-serving.md](https://github.com/robodatalab/cortexgrid/blob/main/docs/cortexgrid/model-serving.md) for both lifecycles end to end - upload/deploy/undeploy/delete, status queries (`model_registry_status`, `model_serving_status`), and error handling.
165
+
166
+ ### API reference
167
+
168
+ | Function | Description |
169
+ |----------|-------------|
170
+ | `cortexgrid.init(experiment=None)` | Configure connections + start a new MLflow run inside the named experiment. One call per binary. |
171
+ | `cortexgrid.log_metric(key, value, step)` | Log a metric |
172
+ | `cortexgrid.log_metrics(metrics, step)` | Log multiple metrics |
173
+ | `cortexgrid.log_params(params)` | Log parameters |
174
+ | `cortexgrid.log_artifact(path, artifact_path)` | Log a file as an artifact |
175
+ | `cortexgrid.checkpoint()` | Context manager returning an attribute-based checkpoint saved to MLflow on exit |
176
+ | `cortexgrid.resume()` | Load the latest checkpoint for the current job, or `None` |
177
+ | `cortexgrid.remote(fn, *args, num_gpus=0, num_cpus=1, retry=False, **kwargs)` | Submit a function to the jobs control plane; returns a job ID |
178
+ | `cortexgrid.list_experiment_run_jobs(run_id)` | List `JobLifecycle` records for every cortexgrid job in a run |
179
+ | `cortexgrid.stop_experiment_run_jobs(run_id)` | Request every job in a run to stop (flips the `stop_requested` latch) |
180
+ | `cortexgrid.get_ray_job_status(ray_job_id)` | Live Ray status for a submission id |
181
+ | `cortexgrid.get_ray_logs(ray_job_id)` | Tail the stdout/stderr of a Ray submission |
182
+ | `cortexgrid.upload(path, bucket, key)` | Upload a file to S3/MinIO |
183
+ | `cortexgrid.download(bucket, key, path)` | Download a file from S3/MinIO |
184
+ | `cortexgrid.get_mlflow_client()` | Raw configured MLflow client |
185
+ | `cortexgrid.get_s3_client()` | Raw configured boto3 S3 client |
186
+
187
+ ## ML compute stack
188
+
189
+ The DGX Spark runs the following services as k8s workloads managed by Argo CD (see [../k8s/argo_deployments/](https://github.com/robodatalab/cortexgrid/tree/main/k8s/argo_deployments/)):
190
+
191
+ | Service | Port | Purpose |
192
+ |---------|------|---------|
193
+ | Ray | 8265 | Dashboard + job submission (NodePort 30265) |
194
+ | MLflow | 5000 | Experiment tracking, model registry |
195
+ | MinIO | 9000/9001 | S3-compatible artifact storage |
196
+ | PostgreSQL | 5432 | MLflow metadata backend |
197
+ | Prometheus | 9090 | Metrics collection |
198
+ | Grafana | 3000 | Dashboards (GPU, jobs, system) |
199
+
@@ -0,0 +1,195 @@
1
+ """cortexgrid — connect your code to the RoboLab compute cluster.
2
+
3
+ import cortexgrid
4
+
5
+ # Fire-and-forget training on the DGX; returns a job id immediately.
6
+ # The jobs control plane picks up the submission and dispatches it to Ray.
7
+ job_id = cortexgrid.remote(my_train, config, num_gpus=1, retry=True)
8
+ print(f"Submitted: {job_id}")
9
+
10
+ # Check on it later
11
+ for job in cortexgrid.list_experiment_run_jobs(run_id):
12
+ status = cortexgrid.get_ray_job_status(job.get_ray_job_id())
13
+
14
+ # Inside the training function — checkpoint after each epoch
15
+ with cortexgrid.checkpoint() as ckpt:
16
+ ckpt.epoch = epoch
17
+ ckpt.save_training_state(model, optimizer, scheduler)
18
+
19
+ # On resume — load checkpoint if it exists
20
+ ckpt = cortexgrid.resume()
21
+ if ckpt:
22
+ ckpt.restore_training_state(model, optimizer, scheduler)
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ from pathlib import Path
28
+ from typing import Any, Callable
29
+
30
+ from cortexgrid.checkpoint import checkpoint, resume
31
+ from cortexgrid.experiment import (
32
+ Experiment,
33
+ delete_experiment,
34
+ delete_run,
35
+ list_experiments,
36
+ )
37
+ from cortexgrid.infra import get_ray_job_server_uri
38
+ from cortexgrid.jobs import (
39
+ schedule_remote_job,
40
+ list_experiment_run_jobs,
41
+ stop_experiment_run_jobs,
42
+ JobLifecycle,
43
+ LifecycleEvent,
44
+ Payload,
45
+ )
46
+ from cortexgrid.secrets import (
47
+ delete_secret,
48
+ get_secret,
49
+ list_secrets,
50
+ set_secret,
51
+ )
52
+ from cortexgrid.mlflow_util import (
53
+ log_metric,
54
+ log_metrics,
55
+ log_params,
56
+ log_artifact,
57
+ get_mlflow_client,
58
+ list_run_metrics,
59
+ get_metric_history,
60
+ list_run_params,
61
+ list_run_artifacts,
62
+ )
63
+ from cortexgrid.ray_util import (
64
+ get_ray_status,
65
+ get_ray_logs,
66
+ get_ray_job_url,
67
+ stop_ray_job,
68
+ submit_ray_job,
69
+ list_ray_jobs_with_submission_id,
70
+ get_ray_job_status,
71
+ ray_submission_id,
72
+ get_ray_job_attempt,
73
+ JobStatus,
74
+ )
75
+ from cortexgrid.s3_util import delete_prefix, download, get_s3_client, upload, upload_dir
76
+ from cortexgrid.model_storage import (
77
+ SavedModel,
78
+ delete_model,
79
+ list_models,
80
+ load_model,
81
+ model_registry_status,
82
+ )
83
+ from cortexgrid.model_storage import save_model as _save_model_storage
84
+ from cortexgrid.model_serving import (
85
+ Deployment,
86
+ ServingStatus,
87
+ deploy_model,
88
+ list_deployed_models,
89
+ model_serving_status,
90
+ undeploy_model,
91
+ )
92
+
93
+
94
+ def remote(
95
+ fn: Callable[..., Any],
96
+ *args: Any,
97
+ num_gpus: int = 0,
98
+ num_cpus: int = 1,
99
+ retry: bool = False,
100
+ **kwargs: Any,
101
+ ) -> str:
102
+ """Submit a function to the control plane. Returns a job ID."""
103
+ experiment = Experiment.get_instance()
104
+ return schedule_remote_job(
105
+ experiment.experiment_name,
106
+ experiment.run_id,
107
+ fn,
108
+ *args,
109
+ num_gpus=num_gpus,
110
+ num_cpus=num_cpus,
111
+ retry=retry,
112
+ **kwargs,
113
+ )
114
+
115
+
116
+ def save_model(
117
+ weights_dir: str | Path, serve_app: type, family: str, suffix: str
118
+ ) -> SavedModel:
119
+ """Persist a weights directory under the current Experiment's run, paired
120
+ with the serve-app class that will front it at deploy time."""
121
+ experiment = Experiment.get_instance()
122
+ return _save_model_storage(
123
+ weights_dir,
124
+ serve_app,
125
+ suffix,
126
+ family,
127
+ run_id=experiment.run_id,
128
+ run_name=experiment.run_name(),
129
+ )
130
+
131
+
132
+ __all__ = [
133
+ "Experiment",
134
+ "delete_experiment",
135
+ "delete_run",
136
+ # Ray / jobs
137
+ "remote",
138
+ "get_ray_job_status",
139
+ "list_experiment_run_jobs",
140
+ "stop_experiment_run_jobs",
141
+ "JobStatus",
142
+ "JobLifecycle",
143
+ "LifecycleEvent",
144
+ "Payload",
145
+ "get_ray_status",
146
+ "get_ray_logs",
147
+ "get_ray_job_url",
148
+ "stop_ray_job",
149
+ "submit_ray_job",
150
+ "get_ray_job_server_uri",
151
+ "list_ray_jobs_with_submission_id",
152
+ "ray_submission_id",
153
+ "get_ray_job_attempt",
154
+ # MLflow
155
+ "log_metric",
156
+ "log_metrics",
157
+ "log_params",
158
+ "log_artifact",
159
+ "get_mlflow_client",
160
+ "list_run_metrics",
161
+ "get_metric_history",
162
+ "list_run_params",
163
+ "list_run_artifacts",
164
+ "list_experiments",
165
+ # Checkpointing
166
+ "checkpoint",
167
+ "resume",
168
+ # S3
169
+ "upload",
170
+ "upload_dir",
171
+ "download",
172
+ "get_s3_client",
173
+ "delete_prefix",
174
+ # Secrets
175
+ "get_secret",
176
+ "set_secret",
177
+ "list_secrets",
178
+ "delete_secret",
179
+ # Model registry
180
+ "SavedModel",
181
+ "save_model",
182
+ "load_model",
183
+ "list_models",
184
+ "model_registry_status",
185
+ "delete_model",
186
+ # Model serving
187
+ "Deployment",
188
+ "ServingStatus",
189
+ "deploy_model",
190
+ "model_serving_status",
191
+ "undeploy_model",
192
+ "list_deployed_models",
193
+ ]
194
+
195
+ # trigger: 315-trigger-tests-2026-05-16