dataspires 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. dataspires-0.1.0/LICENSE +21 -0
  2. dataspires-0.1.0/MANIFEST.in +9 -0
  3. dataspires-0.1.0/PKG-INFO +451 -0
  4. dataspires-0.1.0/README.md +409 -0
  5. dataspires-0.1.0/afrilink/__init__.py +205 -0
  6. dataspires-0.1.0/afrilink/adapt.py +60 -0
  7. dataspires-0.1.0/afrilink/api_key_auth.py +255 -0
  8. dataspires-0.1.0/afrilink/auth.py +459 -0
  9. dataspires-0.1.0/afrilink/billing_auth.py +38 -0
  10. dataspires-0.1.0/afrilink/build.py +806 -0
  11. dataspires-0.1.0/afrilink/checkpoint.py +124 -0
  12. dataspires-0.1.0/afrilink/cineca_auth.py +924 -0
  13. dataspires-0.1.0/afrilink/client.py +1797 -0
  14. dataspires-0.1.0/afrilink/cluster_metrics_hook.py +67 -0
  15. dataspires-0.1.0/afrilink/container.py +753 -0
  16. dataspires-0.1.0/afrilink/credentials.py +266 -0
  17. dataspires-0.1.0/afrilink/distributed.py +515 -0
  18. dataspires-0.1.0/afrilink/docker_runner.py +437 -0
  19. dataspires-0.1.0/afrilink/finetune.py +1660 -0
  20. dataspires-0.1.0/afrilink/gcp_auth.py +180 -0
  21. dataspires-0.1.0/afrilink/generate.py +565 -0
  22. dataspires-0.1.0/afrilink/help.py +1086 -0
  23. dataspires-0.1.0/afrilink/inference.py +269 -0
  24. dataspires-0.1.0/afrilink/initialize.py +52 -0
  25. dataspires-0.1.0/afrilink/k8s_runner.py +422 -0
  26. dataspires-0.1.0/afrilink/metrics.py +170 -0
  27. dataspires-0.1.0/afrilink/opentoken_auth.py +207 -0
  28. dataspires-0.1.0/afrilink/pretrain.py +646 -0
  29. dataspires-0.1.0/afrilink/pretrain_api.py +245 -0
  30. dataspires-0.1.0/afrilink/progress.py +125 -0
  31. dataspires-0.1.0/afrilink/registry.py +657 -0
  32. dataspires-0.1.0/afrilink/routing.py +384 -0
  33. dataspires-0.1.0/afrilink/session.py +433 -0
  34. dataspires-0.1.0/afrilink/slurm.py +636 -0
  35. dataspires-0.1.0/afrilink/telemetry.py +816 -0
  36. dataspires-0.1.0/afrilink/train.py +1419 -0
  37. dataspires-0.1.0/afrilink/train_config.py +203 -0
  38. dataspires-0.1.0/afrilink/transfer.py +591 -0
  39. dataspires-0.1.0/afrilink/vlm.py +141 -0
  40. dataspires-0.1.0/afrilink/vouchers.py +176 -0
  41. dataspires-0.1.0/afrilink/watchdog.py +315 -0
  42. dataspires-0.1.0/dataspires/__init__.py +26 -0
  43. dataspires-0.1.0/dataspires.egg-info/PKG-INFO +451 -0
  44. dataspires-0.1.0/dataspires.egg-info/SOURCES.txt +48 -0
  45. dataspires-0.1.0/dataspires.egg-info/dependency_links.txt +1 -0
  46. dataspires-0.1.0/dataspires.egg-info/requires.txt +12 -0
  47. dataspires-0.1.0/dataspires.egg-info/top_level.txt +2 -0
  48. dataspires-0.1.0/pyproject.toml +80 -0
  49. dataspires-0.1.0/setup.cfg +4 -0
  50. dataspires-0.1.0/setup.py +71 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DataSpires
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,9 @@
1
+ include LICENSE
2
+ include README.md
3
+ include pyproject.toml
4
+
5
+ recursive-include afrilink *.py
6
+
7
+ prune container_build
8
+ prune examples
9
+ prune .git
@@ -0,0 +1,451 @@
1
+ Metadata-Version: 2.4
2
+ Name: dataspires
3
+ Version: 0.1.0
4
+ Summary: DataSpires SDK — Train, finetune, and generate on GPUs from your notebook
5
+ Home-page: https://github.com/DataSpires/backend-server
6
+ Author: DataSpires
7
+ Author-email: DataSpires <info@dataspires.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://dataspires.com
10
+ Project-URL: Documentation, https://www.dataspires.com/docs
11
+ Project-URL: Repository, https://github.com/DataSpires/afrilink-sdk
12
+ Project-URL: Bug Tracker, https://github.com/DataSpires/afrilink-sdk/issues
13
+ Keywords: hpc,high-performance-computing,finetuning,pretrain,generate,vlm,llm,lora,notebook,gpu,dataspires,afrilink
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Classifier: Topic :: System :: Distributed Computing
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: requests>=2.28.0
30
+ Provides-Extra: full
31
+ Requires-Dist: psutil>=5.9.0; extra == "full"
32
+ Provides-Extra: build
33
+ Requires-Dist: cryptography>=41.0.0; extra == "build"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
38
+ Dynamic: author
39
+ Dynamic: home-page
40
+ Dynamic: license-file
41
+ Dynamic: requires-python
42
+
43
+ # DataSpires SDK
44
+
45
+ **Version:** 0.1.0
46
+
47
+ Train, finetune, and run inference on DataSpires GPUs from any notebook.
48
+
49
+ ```bash
50
+ pip install dataspires
51
+ ```
52
+
53
+ **Works in:** Google Colab · Kaggle · Jupyter · VS Code · any Python 3.8+ environment
54
+
55
+ ---
56
+
57
+ ## Contents
58
+
59
+ 1. [60-second quickstart](#60-second-quickstart)
60
+ 2. [Authentication](#authentication)
61
+ 3. [Which method should I use?](#which-method-should-i-use)
62
+ 4. [Backend](#backend)
63
+ 5. [Guides by task](#guides-by-task)
64
+ — [Pretrain](#pretrain) · [Finetune](#finetune) · [Generate](#generate)
65
+ — [Checkpointing](#checkpointing-and-resuming)
66
+ 6. [Working with your output model](#working-with-your-model)
67
+ 7. [API reference](#api-reference)
68
+ 8. [Hardware & billing](#hardware--billing)
69
+ 9. [Model & dataset registry](#model--dataset-registry)
70
+ 10. [Troubleshooting](#troubleshooting)
71
+ 11. [Built-in help](#built-in-help)
72
+
73
+ ---
74
+
75
+ ## 60-second quickstart
76
+
77
+ ```python
78
+ from dataspires import DataSpiresClient
79
+
80
+ client = DataSpiresClient()
81
+ client.authenticate(api_key="afk_live_…") # or set API_KEY
82
+
83
+ job = client.pretrain(
84
+ architecture="cnn",
85
+ kind="resnet18",
86
+ init="pretrained",
87
+ data="./images/",
88
+ config={"n_epoch": 5, "num_classes": 2, "seed": 42},
89
+ gpus=1,
90
+ )
91
+ result = job.run(wait=True)
92
+ print(result["status"]) # "completed" | "failed" | "timeout" | …
93
+ if result["status"] != "completed":
94
+ print(result.get("error") or result.get("reason"))
95
+ ```
96
+
97
+ `finetune()` and `generate()` use the same `client → job → job.run()` pattern.
98
+
99
+ ---
100
+
101
+ ## Authentication
102
+
103
+ ### Get a key
104
+
105
+ 1. Sign up at [dataspires.com](https://dataspires.com).
106
+ 2. **Profile → DataSpires SDK keys → Create new key.** Copy the `afk_live_…` value — it's shown once.
107
+ 3. Store it as `API_KEY`.
108
+
109
+ ### Set the key
110
+
111
+ | Environment | How |
112
+ | --- | --- |
113
+ | Google Colab | Secrets → `API_KEY` |
114
+ | Kaggle | Secrets → `API_KEY` |
115
+ | Local | `os.environ["API_KEY"] = "afk_live_…"` |
116
+ | Anywhere | `client.authenticate(api_key="afk_live_…")` |
117
+
118
+ ```python
119
+ client = DataSpiresClient()
120
+ client.authenticate()
121
+ ```
122
+
123
+ `authenticate()` raises on a bad or revoked key. Rotate a key by revoking it on the dashboard and creating a new one.
124
+
125
+ ---
126
+
127
+ ## Which method should I use?
128
+
129
+ | Your goal | Call | You provide |
130
+ | --- | --- | --- |
131
+ | Detector, CNN, or scratch transformer | `client.pretrain()` | `architecture`, `kind`, `data`, optional `init` / `config` |
132
+ | Fine-tune an LLM / VLM foundation model | `client.finetune()` | `model`, `training_mode`, `data`, optional `task=` |
133
+ | Run a model without changing weights | `client.generate()` | `model`, prompts / image+question manifest |
134
+
135
+ > Train from zero → `pretrain()`. Adapt existing weights → `finetune()`. Frozen answers → `generate()`.
136
+
137
+ ---
138
+
139
+ ## Backend
140
+
141
+ Jobs run on the DataSpires GPU cluster by default.
142
+
143
+ | | |
144
+ | --- | --- |
145
+ | **Job model** | Async — submit, then poll or `list_jobs()` |
146
+ | **Outputs** | `job.download()` and `client.download_model()` |
147
+ | **Multi-GPU** | Supported when the cluster has capacity |
148
+ | **Wall-clock max** | `time_limit` capped at **10 hours** |
149
+
150
+ ### `status` vs `state`
151
+
152
+ | API | Field | Example values |
153
+ | --- | --- | --- |
154
+ | `job.run()` return dict | **`status`** | `submitted`, `completed`, `failed`, `timeout`, `cancelled` |
155
+ | `client.list_jobs()` / `client.get_job_status()` | **`state`** | same lifecycle strings; may also include `queued`, `running` |
156
+
157
+ ```python
158
+ result = job.run(wait=True)
159
+ print(result["status"])
160
+
161
+ for entry in client.list_jobs():
162
+ print(entry["job_id"], entry["state"], entry.get("reason"))
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Guides by task
168
+
169
+ ### Pretrain
170
+
171
+ ```python
172
+ job = client.pretrain(
173
+ architecture="cnn",
174
+ kind="resnet18",
175
+ init="pretrained",
176
+ data="./images/",
177
+ config={"n_epoch": 5, "num_classes": 2, "batch_size": 32, "seed": 42},
178
+ gpus=1,
179
+ time_limit="02:00:00",
180
+ )
181
+ result = job.run(wait=True)
182
+ rows = job.get_metrics()
183
+ job.export_metrics("./run.csv")
184
+ ```
185
+
186
+ **Detector.** Metrics are loss only in v1.
187
+
188
+ ```python
189
+ job = client.pretrain(
190
+ architecture="detector",
191
+ kind="detect", # or segment, pose
192
+ init="pretrained",
193
+ weights="yolo11n.pt",
194
+ data="./dataset/",
195
+ data_config="data.yaml",
196
+ config={"n_epoch": 100, "imgsz": 640, "batch_size": 16, "seed": 42},
197
+ )
198
+ ```
199
+
200
+ **Decoder from scratch.** `tokenizer` is required for decoder kinds only.
201
+
202
+ ```python
203
+ job = client.pretrain(
204
+ architecture="transformer",
205
+ kind="gpt-decoder-tiny",
206
+ init="scratch",
207
+ tokenizer="gpt2",
208
+ data="./corpus/",
209
+ config={"max_steps": 1000, "n_epoch": 1, "seed": 42},
210
+ )
211
+ ```
212
+
213
+ | `architecture` | `kind` |
214
+ | --- | --- |
215
+ | `detector` | `detect`, `segment`, `pose` |
216
+ | `cnn` | `resnet18`, `resnet50` |
217
+ | `transformer` | `gpt-decoder-tiny`, `qwen-decoder-tiny`, `llama-3-decoder-tiny`, `vit-tiny` |
218
+
219
+ `time_limit` is an `HH:MM:SS` string.
220
+
221
+ ```python
222
+ job.download("./my-outputs")
223
+ job.download("./ckpts", include="checkpoints")
224
+ client.download_model(job.job_id, "./my-outputs")
225
+ ```
226
+
227
+ ### Finetune
228
+
229
+ ```python
230
+ import pandas as pd
231
+
232
+ data = pd.DataFrame({"text": ["Below is an instruction...\n\n### Response:\n..."]})
233
+
234
+ job = client.finetune(
235
+ model="qwen2.5-0.5b",
236
+ training_mode="low", # low | medium | high | custom
237
+ data=data,
238
+ gpus=1,
239
+ time_limit="01:00:00",
240
+ )
241
+ result = job.run(wait=True)
242
+ if result["status"] == "completed":
243
+ client.download_model(result["job_id"], "./my-model")
244
+ ```
245
+
246
+ | Mode | Strategy | Precision |
247
+ | --- | --- | --- |
248
+ | `low` | QLoRA (rank 8) | 4-bit |
249
+ | `medium` | LoRA (rank 16) | 8-bit on 1 GPU, bf16 otherwise |
250
+ | `high` | High-rank LoRA (rank 64) | bf16 |
251
+ | `custom` | User-defined (see `config=`) | `bf16`, `fp16`, `4bit`, or `8bit` |
252
+
253
+ `training_mode="custom"` requires `config=`. Presets reject `config`. `gpus` and `time_limit` stay outside `config`.
254
+
255
+ ```python
256
+ job = client.finetune(
257
+ model="qwen2.5-0.5b",
258
+ training_mode="custom",
259
+ data=data,
260
+ config={
261
+ "batch_size": 2,
262
+ "learning_rate": 2e-4,
263
+ "scheduler": "cosine",
264
+ "n_epoch": 3,
265
+ "precision": "bf16",
266
+ "lora": {"r": 16, "alpha": 32, "dropout": 0.05},
267
+ "max_seq_length": 2048,
268
+ "optimizer": "adamw_torch",
269
+ "n_checkpoint": 100,
270
+ "n_evals": 0,
271
+ "seed": 42,
272
+ },
273
+ )
274
+ rows = job.get_metrics()
275
+ job.export_metrics("./run_metrics.csv")
276
+ ```
277
+
278
+ Causal-LM accuracy is token accuracy, not a task score. If `n_evals` is above 0 and there is no eval split, the SDK fails before submit.
279
+
280
+ For VLMs, pass `task=` (captioning / VQA) with image+text data. See `dataspires.docs("finetune")`.
281
+
282
+ Optional: `checkpoint={"every": 200, "keep": 2}` and `resume_from=` (prior job, job id, or `{job_id, step}`).
283
+
284
+ ### Checkpointing and resuming
285
+
286
+ Jobs honour `time_limit` (capped at 10 hours). A stopped run can be continued with `resume_from=`.
287
+
288
+ ```python
289
+ job = client.finetune(
290
+ model="qwen2.5-0.5b",
291
+ training_mode="low",
292
+ data=data,
293
+ time_limit="08:00:00",
294
+ checkpoint={"every": 200, "keep": 2},
295
+ )
296
+ result = job.run(wait=True)
297
+
298
+ if result["status"] != "completed":
299
+ job2 = client.finetune(
300
+ model="qwen2.5-0.5b",
301
+ training_mode="low",
302
+ data=data,
303
+ resume_from=job,
304
+ )
305
+ job2.run(wait=True)
306
+ ```
307
+
308
+ | Path | Meaning |
309
+ | --- | --- |
310
+ | `output/checkpoints/checkpoint-N/` | Mid-run snapshots |
311
+ | `output/final/` | Weights after a clean exit |
312
+
313
+ `client.list_checkpoints(job_id)` lists prefixes. See `dataspires.docs("checkpoints")`.
314
+
315
+ ### Generate
316
+
317
+ *(Frozen inference — no weight updates)*
318
+
319
+ ```python
320
+ job = client.generate(
321
+ model="smolvlm-256m",
322
+ data="./manifest_dir/",
323
+ outputs=["text", "confidence"],
324
+ max_new_tokens=64,
325
+ temperature=0.0,
326
+ )
327
+ result = job.run(wait=True)
328
+ ```
329
+
330
+ ### Job failures
331
+
332
+ `job.run(wait=True)` returns a dict on failure instead of raising. Check `result["status"] == "completed"` before downloading. Auth and submit-time validation errors do raise.
333
+
334
+ ---
335
+
336
+ ## Working with your model
337
+
338
+ ### Convert to GGUF for Ollama / llama.cpp
339
+
340
+ ```python
341
+ from transformers import AutoModelForCausalLM, AutoTokenizer
342
+ from peft import PeftModel
343
+
344
+ base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B")
345
+ model = PeftModel.from_pretrained(base, "./my-model")
346
+ merged = model.merge_and_unload()
347
+ merged.save_pretrained("./my-model-merged")
348
+ AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B").save_pretrained("./my-model-merged")
349
+ ```
350
+
351
+ Then convert with [llama.cpp](https://github.com/ggerganov/llama.cpp) `convert_hf_to_gguf.py`.
352
+
353
+ ### Publish to Hugging Face Hub
354
+
355
+ ```python
356
+ from huggingface_hub import HfApi
357
+ api = HfApi()
358
+ api.upload_folder(folder_path="./my-model", repo_id="you/my-model", repo_type="model")
359
+ ```
360
+
361
+ ---
362
+
363
+ ## API reference
364
+
365
+ ### `DataSpiresClient`
366
+
367
+ | Method | Description |
368
+ | --- | --- |
369
+ | `authenticate(api_key=None)` | Resolve key; raises on failure |
370
+ | `pretrain(architecture, kind, init, config, …)` | Returns a job — call `.run()` |
371
+ | `finetune(model, training_mode, data, config, …)` | Returns `FinetuneJob` — call `.run()` |
372
+ | `generate(model, data, outputs, …)` | Returns `GenerateJob` — call `.run()` |
373
+ | `download_model(job_id, local_dir, include=("final",))` | Download outputs |
374
+ | `list_checkpoints(job_id)` | List checkpoint prefixes |
375
+ | `upload_dataset(local_path, dataset_name=None)` | Optional separate staging |
376
+ | `list_available_models()` / `list_available_datasets()` | Registry lookups |
377
+ | `get_model_requirements(model, training_mode)` | GPU/memory recommendation |
378
+ | `cancel_job(job_id)` | Stop a job |
379
+ | `list_jobs(include_completed=False)` | List jobs → dicts with **`state`** |
380
+ | `get_job_status(job_id)` | Poll by ID → dict with **`state`** |
381
+
382
+ ### Job objects
383
+
384
+ | Member | Description |
385
+ | --- | --- |
386
+ | `run(wait=True, poll_interval=30)` | Submit; with `wait=True`, return a result **dict** with **`status`** |
387
+ | `cancel()` | Stop the job |
388
+ | `get_logs(tail=100)` | Recent log lines |
389
+ | `get_metrics()` | Loss/acc rows |
390
+ | `export_metrics(path)` | Write metrics to `.csv` or `.json` |
391
+ | `download(local_dir, include=("final",))` | Download outputs |
392
+ | `checkpoints()` | List checkpoint prefixes |
393
+ | `estimated_cost_usd()` | Planning ceiling from `gpus × time_limit` |
394
+ | `status`, `job_id` | Current tracked state / job ID |
395
+
396
+ ---
397
+
398
+ ## Hardware & billing
399
+
400
+ Prefer small models and `training_mode="low"` for lighter runs.
401
+
402
+ | Model size | Mode | Fits on 1 GPU? |
403
+ | --- | --- | --- |
404
+ | 0.5B – 3B | low / medium | yes |
405
+ | 3B – 7B | low (QLoRA 4-bit) | yes |
406
+ | 7B | medium | yes |
407
+ | 13B | low | tight |
408
+ | 30B+ | low | unlikely |
409
+
410
+ **Limits:** **10h** `time_limit`; hard max **32 GPUs** (SDK warns above 8).
411
+
412
+ **Billing:** invoices at [dataspires.com/dashboard/billing](https://dataspires.com/dashboard/billing). GPU time is **$0.60/GPU-hr for an L4**. `job.estimated_cost_usd()` is a planning ceiling from `time_limit`, not the invoice.
413
+
414
+ ---
415
+
416
+ ## Model & dataset registry
417
+
418
+ ```python
419
+ client.list_available_models()
420
+ client.list_available_models(size="tiny")
421
+ client.list_available_datasets()
422
+ client.get_model_requirements("qwen2.5-0.5b", "low")
423
+ ```
424
+
425
+ ---
426
+
427
+ ## Troubleshooting
428
+
429
+ | Symptom | Likely cause | Fix |
430
+ | --- | --- | --- |
431
+ | `API key auth failed` | Bad / revoked key | Create a new key; set `API_KEY` |
432
+ | Job stuck in `queued` | Cluster at capacity | `client.list_jobs()`; wait or try later |
433
+ | `KeyError: 'status'` on `list_jobs()` | Wrong field | Use `entry["state"]` for list/status APIs |
434
+ | `KeyError: 'state'` on `job.run()` result | Wrong field | Use `result["status"]` for `job.run()` |
435
+ | Gated HF model fails | Missing token | Add `HUGGINGFACE_TOKEN` |
436
+ | `download_model()` returns nothing | No finals written | Confirm the run completed; try `include="checkpoints"` |
437
+ | `reason` is `DeadlineExceeded` | Hit `time_limit` | `resume_from=job` |
438
+
439
+ ---
440
+
441
+ ## Built-in help
442
+
443
+ ```python
444
+ import dataspires
445
+ dataspires.docs("help")
446
+ dataspires.docs("finetune")
447
+ dataspires.docs("pretrain")
448
+ dataspires.docs("checkpoints")
449
+ ```
450
+
451
+ `AfriLinkClient` and `import afrilink` remain available as aliases for existing notebooks.