dsh-runnpu 0.1.0

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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -0
  3. package/compute-mode/preset/agent.cordis.yml +368 -0
  4. package/compute-mode/preset/preset.yml +3 -0
  5. package/compute-mode/preset/skills/runnpu/SKILL.md +233 -0
  6. package/compute-mode/preset/skills/runnpu/VENDOR.txt +11 -0
  7. package/compute-mode/preset/skills/runnpu/examples/01-dev-environment.sh +26 -0
  8. package/compute-mode/preset/skills/runnpu/examples/02-training-job.sh +26 -0
  9. package/compute-mode/preset/skills/runnpu/examples/03-inference-service.sh +24 -0
  10. package/compute-mode/preset/skills/runnpu/examples/04-fractional-vnpu.sh +14 -0
  11. package/compute-mode/preset/skills/runnpu/examples/05-troubleshoot.sh +17 -0
  12. package/compute-mode/preset/skills/runnpu/references/admin.md +60 -0
  13. package/compute-mode/preset/skills/runnpu/references/data-sources.md +35 -0
  14. package/compute-mode/preset/skills/runnpu/references/templates-assets.md +61 -0
  15. package/compute-mode/preset/skills/runnpu/references/training-runs.md +56 -0
  16. package/compute-mode/preset/skills/runnpu/references/troubleshooting.md +75 -0
  17. package/compute-mode/preset/skills/runnpu/references/workload-types.md +47 -0
  18. package/cordis.patch.yml +80 -0
  19. package/dist/chunk-JLZMOSQC.mjs +1 -0
  20. package/dist/chunk-JUBIWGKW.mjs +4 -0
  21. package/dist/chunk-JZXLCA2E.mjs +1 -0
  22. package/dist/chunk-KQOFBYGE.mjs +9 -0
  23. package/dist/chunk-XMZG2NP7.mjs +2 -0
  24. package/dist/chunk-XQPU3AJN.mjs +1 -0
  25. package/dist/chunk-YKASEMP3.mjs +1 -0
  26. package/dist/chunk-YPL4VUYF.mjs +4 -0
  27. package/dist/compute-node.mjs +1 -0
  28. package/dist/compute-tools.mjs +41 -0
  29. package/dist/connectors.mjs +3 -0
  30. package/dist/dsh-runnpu.mjs +43 -0
  31. package/dist/json.mjs +1 -0
  32. package/dist/pins.mjs +1 -0
  33. package/dist/series.mjs +1 -0
  34. package/dist/training-node.mjs +2 -0
  35. package/dist/training-tools.mjs +30 -0
  36. package/dist/ui-host.mjs +1 -0
  37. package/lib/client.js +189 -0
  38. package/package.json +78 -0
  39. package/training-mode/preset/agent.cordis.yml +343 -0
  40. package/training-mode/preset/preset.yml +3 -0
  41. package/training-mode/preset/skills/runnpu/SKILL.md +233 -0
  42. package/training-mode/preset/skills/runnpu/VENDOR.txt +11 -0
  43. package/training-mode/preset/skills/runnpu/examples/01-dev-environment.sh +26 -0
  44. package/training-mode/preset/skills/runnpu/examples/02-training-job.sh +26 -0
  45. package/training-mode/preset/skills/runnpu/examples/03-inference-service.sh +24 -0
  46. package/training-mode/preset/skills/runnpu/examples/04-fractional-vnpu.sh +14 -0
  47. package/training-mode/preset/skills/runnpu/examples/05-troubleshoot.sh +17 -0
  48. package/training-mode/preset/skills/runnpu/references/admin.md +60 -0
  49. package/training-mode/preset/skills/runnpu/references/data-sources.md +35 -0
  50. package/training-mode/preset/skills/runnpu/references/templates-assets.md +61 -0
  51. package/training-mode/preset/skills/runnpu/references/training-runs.md +56 -0
  52. package/training-mode/preset/skills/runnpu/references/troubleshooting.md +75 -0
  53. package/training-mode/preset/skills/runnpu/references/workload-types.md +47 -0
  54. package/training-mode/preset/skills/swanlab-skill/LICENSE +21 -0
  55. package/training-mode/preset/skills/swanlab-skill/SKILL.md +163 -0
  56. package/training-mode/preset/skills/swanlab-skill/VENDOR.txt +9 -0
  57. package/training-mode/preset/skills/swanlab-skill/references/ANALYSIS_GUIDE.md +83 -0
  58. package/training-mode/preset/skills/swanlab-skill/references/CLI_REFERENCE.md +510 -0
  59. package/training-mode/preset/skills/swanlab-skill/references/SDK_QUICKSTART.md +341 -0
  60. package/training-mode/preset/skills/swanlab-skill/references/SWANLAB_CONCEPTS.md +523 -0
  61. package/training-mode/preset/skills/swanlab-skill/scripts/plot_metrics.py +353 -0
  62. package/training-mode/preset/skills/swanlab-skill/scripts/runs_benchmark.py +550 -0
  63. package/training-mode/preset/skills/training-research/SKILL.md +33 -0
  64. package/training-mode/preset/skills/training-research/references/pipeline.md +45 -0
  65. package/training-mode/preset/skills/training-research/references/research.md +76 -0
@@ -0,0 +1,341 @@
1
+ # SwanLab SDK Quick Start
2
+
3
+ Reference for writing SwanLab tracking code. Based on the current SDK API surface.
4
+ All data **reading** operations should use the `swanlab api` CLI — see `CLI_REFERENCE.md`.
5
+
6
+ ---
7
+
8
+ ## 1. Install & Login
9
+
10
+ ```bash
11
+ pip install swanlab
12
+ ```
13
+
14
+ Login (one-time):
15
+
16
+ ```bash
17
+ swanlab login
18
+ ```
19
+
20
+ Or login programmatically:
21
+
22
+ ```python
23
+ import swanlab
24
+
25
+ swanlab.login(api_key="your-api-key", save=True)
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 2. Create an Experiment — `swanlab.init()`
31
+
32
+ ```python
33
+ run = swanlab.init(
34
+ project="my-project", # project name (defaults to cwd name)
35
+ name="resnet-exp-1", # experiment name (auto-generated if omitted)
36
+ description="baseline run", # experiment description
37
+ config={ # hyperparameters / metadata (dict, JSON path, or YAML path)
38
+ "learning_rate": 0.01,
39
+ "epochs": 10,
40
+ "batch_size": 32,
41
+ },
42
+ )
43
+ ```
44
+
45
+ ### Key Parameters
46
+
47
+ | Parameter | Type | Default | Description |
48
+ | ------------- | ----------------------- | -------------- | ---------------------------------------------------------------------------------------------- |
49
+ | `project` | `str` | cwd name | Project name |
50
+ | `name` | `str` | auto-generated | Experiment display name |
51
+ | `description` | `str` | none | Experiment description |
52
+ | `config` | `dict` / `str` / `Path` | none | Hyperparameters dict or path to JSON/YAML file |
53
+ | `mode` | `str` | `"online"` | Run mode — see SKILL.md for details |
54
+ | `workspace` | `str` | current user | Target workspace username |
55
+ | `tags` | `list[str]` | none | Tags for categorization |
56
+ | `group` | `str` | none | Group name for distributed/related experiments — see §11 |
57
+ | `job_type` | `str` | none | Role label, e.g. `"train"`, `"worker"` — see §11 |
58
+ | `resume` | `str` / `bool` | `"never"` | Resume strategy — see §9 |
59
+ | `id` | `str` | auto | Custom run ID (1–512 chars, no `<>:"/\|?*#%` or control chars). Required when `resume="must"`. |
60
+ | `log_dir` | `str` | `"./swanlog"` | Local log directory |
61
+ | `callbacks` | `list` | none | Callback objects for lifecycle hooks |
62
+ | `reinit` | `bool` | `False` | If True, finish current run before starting new one |
63
+
64
+ ### Access Config at Runtime
65
+
66
+ `run.config` is a mutable mapping with attribute access. Read hyperparameters after init:
67
+
68
+ ```python
69
+ lr = run.config.learning_rate
70
+ epochs = run.config["epochs"]
71
+ ```
72
+
73
+ ---
74
+
75
+ ## 3. Log Metrics — `swanlab.log()`
76
+
77
+ Log a dict of scalar values. `step` auto-increments if omitted.
78
+
79
+ ```python
80
+ swanlab.log({"loss": 0.5, "accuracy": 0.92})
81
+ swanlab.log({"loss": 0.3, "accuracy": 0.95}, step=10) # explicit step
82
+ ```
83
+
84
+ - Keys support `/` for nested grouping: `swanlab.log({"train/loss": 0.5, "val/loss": 0.6})`
85
+ - Nested dicts are auto-flattened using `/`: `{"train": {"loss": 0.5}}` → `"train/loss"`
86
+ - Values can be `int`, `float`, or `str`
87
+ - `step` must be a non-negative integer
88
+
89
+ ---
90
+
91
+ ## 4. Log Media — Two Styles
92
+
93
+ ### Style A: Pass media objects to `swanlab.log()`
94
+
95
+ ```python
96
+ swanlab.log(
97
+ {
98
+ "sample_image": swanlab.Image(tensor_or_path),
99
+ "sample_audio": swanlab.Audio(numpy_array, sample_rate=16000),
100
+ "sample_text": swanlab.Text("generated output"),
101
+ "sample_video": swanlab.Video("video.mp4"),
102
+ "chart": swanlab.ECharts(pyecharts_chart),
103
+ "point_cloud": swanlab.Object3D(numpy_array),
104
+ "mol": swanlab.Molecule("CCO"), # SMILES string
105
+ }
106
+ )
107
+ ```
108
+
109
+ ### Style B: Use convenience functions
110
+
111
+ ```python
112
+ swanlab.log_image(key="image", data=pil_image, caption="epoch 5")
113
+ swanlab.log_audio(key="audio", data="audio.wav", sample_rate=44100)
114
+ swanlab.log_text(key="output", data="hello world")
115
+ swanlab.log_video(key="demo", data="demo.mp4")
116
+ swanlab.log_echarts(key="chart", data=pyecharts_obj)
117
+ swanlab.log_object3d(key="pc", data=numpy_array)
118
+ swanlab.log_molecule(key="mol", data="CCO")
119
+ ```
120
+
121
+ ### Media Input Types
122
+
123
+ | Media Class | Accepted Input Types |
124
+ | ----------- | -------------------------------------------------------------------------- |
125
+ | `Image` | PIL Image, numpy array, torch Tensor, matplotlib Figure, file path (`str`) |
126
+ | `Audio` | numpy array, file path (`str`) |
127
+ | `Video` | file path (`str`) |
128
+ | `Text` | string (`str`) |
129
+ | `ECharts` | pyecharts chart object |
130
+ | `Object3D` | numpy array, dict, file path (`str`) |
131
+ | `Molecule` | SMILES string, file path (`str`), RDKit Mol object |
132
+
133
+ All media `log_*` functions accept optional `caption` (string) and `step` (int) parameters.
134
+
135
+ ---
136
+
137
+ ## 5. Finish an Experiment — `swanlab.finish()`
138
+
139
+ ```python
140
+ swanlab.finish() # state="success" (default)
141
+ swanlab.finish(state="crashed", error="OOM") # report a crash
142
+ ```
143
+
144
+ - `state`: `"success"` / `"crashed"` / `"aborted"`
145
+ - `error`: optional error message (required when `state="crashed"`)
146
+ - `async_log_timeout`: optional timeout (seconds) for pending async_log tasks
147
+ - SwanLab auto-calls `finish()` at program exit if not called explicitly
148
+
149
+ ---
150
+
151
+ ## 6. Other SDK Utilities
152
+
153
+ ### Async Logging — `swanlab.async_log()`
154
+
155
+ Run a function in the background, auto-log its return dict when done:
156
+
157
+ ```python
158
+ future = swanlab.async_log(compute_expensive_metric, x=data, mode="threading")
159
+ # finish() waits for all pending async_log tasks
160
+ ```
161
+
162
+ | `mode` | Execution |
163
+ | ------------- | --------------------------- |
164
+ | `"threading"` | Background thread (default) |
165
+ | `"spawn"` | New process |
166
+ | `"fork"` | Forked process |
167
+ | `"asyncio"` | Async event loop |
168
+
169
+ ---
170
+
171
+ ## 7. Complete Example
172
+
173
+ ```python
174
+ import swanlab
175
+ import random
176
+
177
+ # Initialize
178
+ run = swanlab.init(
179
+ project="my-project",
180
+ config={"learning_rate": 0.01, "epochs": 10},
181
+ )
182
+
183
+ # Training loop
184
+ for epoch in range(2, run.config.epochs):
185
+ acc = 1 - 2**-epoch - random.random() / epoch
186
+ loss = 2**-epoch + random.random() / epoch
187
+ swanlab.log({"accuracy": acc, "loss": loss})
188
+
189
+ # Finish
190
+ swanlab.finish()
191
+ ```
192
+
193
+ ---
194
+
195
+ ## 8. External Tool Conversion
196
+
197
+ SwanLab can import data from other tracking tools:
198
+
199
+ ```python
200
+ from swanlab import sync_wandb, sync_tensorboardX, sync_tensorboard_torch, sync_mlflow
201
+ ```
202
+
203
+ See the `converter/` module for detailed usage.
204
+
205
+ ---
206
+
207
+ ## 9. Resume / Continue Training — `resume` + `id`
208
+
209
+ Resume an existing experiment to append new data (instead of creating a new one).
210
+
211
+ ```python
212
+ # First run — remember the ID
213
+ run = swanlab.init(project="my-project")
214
+ run_id = run.id # e.g. "abc123"
215
+ swanlab.log({"loss": 2.0})
216
+ run.finish()
217
+
218
+ # Later — resume that same experiment
219
+ run = swanlab.init(project="my-project", resume="must", id=run_id)
220
+ swanlab.log({"loss": 0.5}) # appended after the existing data
221
+ run.finish()
222
+ ```
223
+
224
+ ### Resume Strategies
225
+
226
+ | `resume` | Existing experiment with same `id` | No matching experiment |
227
+ | ------------------- | ---------------------------------- | ---------------------- |
228
+ | `"must"` | Resume it | **Error** |
229
+ | `"allow"` / `True` | Resume it | Create a new one |
230
+ | `"never"` / `False` | **Error** (if `id` is set) | Create a new one |
231
+
232
+ ### Finding the Experiment ID
233
+
234
+ - In the UI: experiment → **Environment** tab → **Log Directory** field shows the run ID
235
+ - In the URL: `https://swanlab.cn/@<user>/<project>/runs/<exp_id>/...`
236
+ - Via CLI: `swanlab api run info user/project/run_id`
237
+
238
+ ### Environment Variable Alternative
239
+
240
+ When modifying `swanlab.init()` is inconvenient (e.g. framework integration):
241
+
242
+ ```bash
243
+ export SWANLAB_RUN_RESUME=must # legacy alias: SWANLAB_RESUME
244
+ export SWANLAB_RUN_ID=<exp_id>
245
+ ```
246
+
247
+ `must` is not the only option — see the strategy table above. It is used here because an
248
+ explicit `id` plus the default `never` is an error, and `must` fails loudly if the target
249
+ experiment doesn't exist (typo'd ID, wrong project). `allow` would silently create a new
250
+ experiment instead, so your "resumed" data lands in a different run without any warning.
251
+
252
+ ---
253
+
254
+ ## 10. Sync Offline Data — `swanlab sync`
255
+
256
+ Upload locally stored experiment data to the cloud. Works with `mode="offline"` and `mode="local"` experiments.
257
+
258
+ ```bash
259
+ # Sync a single experiment
260
+ swanlab sync ./swanlog/run-abc123
261
+
262
+ # Sync to a different project / workspace
263
+ swanlab sync ./swanlog/run-abc123 -p other-project -w team-workspace
264
+
265
+ # Sync onto an existing experiment (incremental — only new data is uploaded)
266
+ swanlab sync ./swanlog/run-abc123 --id <exp_id>
267
+
268
+ # Batch sync all runs
269
+ swanlab sync ./swanlog/run-*
270
+
271
+ # Self-hosted target
272
+ swanlab sync ./swanlog/run-abc123 --host https://your-swanserver
273
+ ```
274
+
275
+ Key options: `-p` (project), `-w` (workspace), `--id` (existing experiment ID), `-k` (API key), `--host`.
276
+
277
+ ---
278
+
279
+ ## 11. Distributed Training — `group` + `job_type`
280
+
281
+ SwanLab supports two patterns for distributed training:
282
+
283
+ ### Pattern A: Log only from rank 0
284
+
285
+ Simplest approach — only the main process initializes and logs:
286
+
287
+ ```python
288
+ import os, swanlab
289
+
290
+ local_rank = int(os.environ.get("LOCAL_RANK", 0))
291
+
292
+ if local_rank == 0:
293
+ swanlab.init(project="ddp-training", name="resnet-ddp")
294
+
295
+ for epoch in range(10):
296
+ # ... training ...
297
+ if local_rank == 0:
298
+ swanlab.log({"loss": loss.item()})
299
+
300
+ if local_rank == 0:
301
+ swanlab.finish()
302
+ ```
303
+
304
+ ### Pattern B: Each process logs independently
305
+
306
+ Each process creates its own experiment, grouped with `group` and distinguished by `job_type`:
307
+
308
+ ```python
309
+ import os, swanlab
310
+
311
+ rank = int(os.environ.get("RANK", 0))
312
+
313
+ swanlab.init(
314
+ project="ddp-training",
315
+ group="exp-20260604", # same group for all ranks
316
+ job_type="main" if rank == 0 else f"worker-{rank}",
317
+ )
318
+
319
+ for epoch in range(10):
320
+ # ... training ...
321
+ swanlab.log({"loss": loss.item()})
322
+
323
+ swanlab.finish()
324
+ ```
325
+
326
+ ### Environment Variables for Distributed
327
+
328
+ Useful when injecting config from the training platform instead of passing args to `swanlab.init()`:
329
+
330
+ | Variable | Purpose |
331
+ | -------------------------------- | --------------------------------------------------------------------------- |
332
+ | `SWANLAB_PROJECT_NAME` | Project name (legacy alias: `SWANLAB_PROJ_NAME`) |
333
+ | `SWANLAB_EXPERIMENT_NAME` | Experiment name (legacy alias: `SWANLAB_EXP_NAME`) |
334
+ | `SWANLAB_EXPERIMENT_GROUP` | Group name for associating experiments (legacy alias: `SWANLAB_GROUP`) |
335
+ | `SWANLAB_EXPERIMENT_JOB_TYPE` | Role label, e.g. `"train"`, `"worker"` (legacy alias: `SWANLAB_JOB_TYPE`) |
336
+ | `SWANLAB_EXPERIMENT_TAGS` | Comma-separated tags, e.g. `"ddp,resnet50"` (legacy alias: `SWANLAB_TAGS`) |
337
+ | `SWANLAB_EXPERIMENT_DESCRIPTION` | Experiment description (legacy alias: `SWANLAB_DESCRIPTION`) |
338
+ | `SWANLAB_RUN_PARALLEL` | Parallel mode — set to `shared` so multiple processes log to one shared run |
339
+
340
+ > The nested-style names above require SDK ≥ 0.8.0. The legacy aliases still work for
341
+ > backward compatibility; when both are set, the nested-style name takes precedence.