@infernetprotocol/training 0.1.29 → 0.1.79

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.
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@infernetprotocol/training",
3
- "version": "0.1.29",
3
+ "private": false,
4
+ "version": "0.1.79",
4
5
  "description": "Training orchestration for Infernet — pluggable backends (DeepSpeed/FSDP for trusted clusters, OpenDiLoCo for cross-provider async, Petals for trustless P2P fine-tunes) over a stable async-iterator API.",
5
6
  "license": "MIT",
6
7
  "type": "module",
@@ -11,13 +12,15 @@
11
12
  },
12
13
  "files": [
13
14
  "src/**/*.js",
15
+ "runners/*.py",
14
16
  "README.md"
15
17
  ],
16
18
  "engines": {
17
19
  "node": ">=18"
18
20
  },
19
21
  "dependencies": {
20
- "@infernetprotocol/engine": "0.1.29"
22
+ "@infernetprotocol/engine": "0.1.79",
23
+ "@infernetprotocol/liquid-agent": "0.1.79"
21
24
  },
22
25
  "repository": {
23
26
  "type": "git",
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env python3
2
+ """LoRA-tune a causal language model from a job file, on CPU (or CUDA if present).
3
+
4
+ python peft_train.py job.json
5
+
6
+ The runner for @infernetprotocol/training's `peft` backend (workload
7
+ infernet.text.train). `job.json` is that package's job config:
8
+
9
+ {
10
+ "id": "...", optional
11
+ "name": "business-strategist-agent",
12
+ "kind": "lora",
13
+ "base_model": "HuggingFaceTB/SmolLM2-135M-Instruct",
14
+ "system_prompt": "You are ...", optional
15
+ "dataset": { "url": "corpus.jsonl", "sha256": "<hex>"? }, jsonl of {title, text}
16
+ "hyperparams": { "lr", "batch_size", "epochs", "max_steps", "seq_len", "lora_r", "threads", "seed" },
17
+ "output": { "destination_url": "out/adapter" }
18
+ }
19
+
20
+ Relative paths resolve against the job file's directory. Progress goes to
21
+ stdout as training-protocol v1 NDJSON (meta / step / eval / checkpoint /
22
+ done / error); human-readable logs go to stderr. The output dir holds a PEFT
23
+ adapter (adapter_model.safetensors + adapter_config.json), the tokenizer and
24
+ manifest.json; the checkpoint event's `model` is sha256 of the adapter weights.
25
+ """
26
+
27
+ import hashlib
28
+ import json
29
+ import math
30
+ import os
31
+ import random
32
+ import sys
33
+ import time
34
+ import traceback
35
+ import uuid
36
+ from datetime import datetime, timezone
37
+ from pathlib import Path
38
+
39
+ DEFAULT_SYSTEM = (
40
+ "You are a concise, practical assistant grounded in what independent writers are publishing."
41
+ )
42
+
43
+
44
+ def now():
45
+ return datetime.now(timezone.utc).isoformat()
46
+
47
+
48
+ def emit(job_id, type_, **fields):
49
+ print(json.dumps({"v": 1, "type": type_, "id": job_id, **fields}), flush=True)
50
+
51
+
52
+ def log(msg):
53
+ print(msg, file=sys.stderr, flush=True)
54
+
55
+
56
+ def resolve(base_dir, p):
57
+ p = p.removeprefix("file://")
58
+ return Path(p) if os.path.isabs(p) else base_dir / p
59
+
60
+
61
+ def load_dataset(spec, base_dir):
62
+ # Local files only: the runner never fetches from the network. A remote
63
+ # corpus is downloaded and hash-checked by the caller (c0mpute's text
64
+ # worker) and handed over as a path, so a job cannot point this process at
65
+ # an arbitrary URL.
66
+ url = spec["url"]
67
+ if "://" in url and not url.startswith("file://"):
68
+ raise ValueError("dataset.url must be a local path; download remote corpora first")
69
+ raw = resolve(base_dir, url).read_bytes()
70
+ digest = hashlib.sha256(raw).hexdigest()
71
+ want = (spec.get("sha256") or "").removeprefix("sha256:")
72
+ if want and digest != want:
73
+ raise ValueError(f"dataset sha256 {digest} differs from the job's {want}")
74
+ docs = []
75
+ for line in raw.decode().splitlines():
76
+ if not line.strip():
77
+ continue
78
+ d = json.loads(line)
79
+ if d.get("text"):
80
+ docs.append({"title": d.get("title") or "", "text": d["text"]})
81
+ if len(docs) < 2:
82
+ raise ValueError("dataset needs at least 2 documents with text")
83
+ return docs, digest
84
+
85
+
86
+ def main():
87
+ import torch
88
+ from peft import LoraConfig, get_peft_model
89
+ from transformers import AutoModelForCausalLM, AutoTokenizer
90
+
91
+ job_path = Path(sys.argv[1] if len(sys.argv) > 1 else "job.json").resolve()
92
+ job = json.loads(job_path.read_text())
93
+ base_dir = job_path.parent
94
+ job_id = job.get("id") or str(uuid.uuid4())
95
+ hp = {
96
+ "lr": 2e-4, "batch_size": 4, "epochs": 1, "max_steps": None,
97
+ "seq_len": 256, "lora_r": 8, "threads": min(4, os.cpu_count() or 1), "seed": 0,
98
+ **(job.get("hyperparams") or {}),
99
+ }
100
+ system = job.get("system_prompt") or DEFAULT_SYSTEM
101
+ out_dir = resolve(base_dir, job["output"]["destination_url"])
102
+ device = "cuda" if torch.cuda.is_available() else "cpu"
103
+
104
+ random.seed(hp["seed"])
105
+ torch.manual_seed(hp["seed"])
106
+ torch.set_num_threads(int(hp["threads"]))
107
+
108
+ def to_chat(tok, doc):
109
+ # Each document becomes one briefing exchange, so the tune keeps the
110
+ # instruct model's chat format instead of drifting into raw prose.
111
+ return tok.apply_chat_template(
112
+ [
113
+ {"role": "system", "content": system},
114
+ {"role": "user", "content": f"Brief me on: {doc['title']}" if doc["title"] else "Brief me."},
115
+ {"role": "assistant", "content": doc["text"]},
116
+ ],
117
+ tokenize=False,
118
+ )
119
+
120
+ def pack(tok, docs, seq_len):
121
+ ids = []
122
+ for d in docs:
123
+ ids.extend(tok(to_chat(tok, d), add_special_tokens=False)["input_ids"])
124
+ blocks = [ids[i : i + seq_len] for i in range(0, len(ids) - seq_len + 1, seq_len)]
125
+ return torch.tensor(blocks, dtype=torch.long)
126
+
127
+ @torch.no_grad()
128
+ def perplexity(model, blocks, batch_size):
129
+ model.eval()
130
+ losses = [
131
+ model(input_ids=blocks[i : i + batch_size].to(device), labels=blocks[i : i + batch_size].to(device)).loss.item()
132
+ for i in range(0, len(blocks), batch_size)
133
+ ]
134
+ model.train()
135
+ return math.exp(sum(losses) / max(len(losses), 1))
136
+
137
+ docs, dataset_sha = load_dataset(job["dataset"], base_dir)
138
+ random.shuffle(docs)
139
+ held = max(1, len(docs) // 20)
140
+ tok = AutoTokenizer.from_pretrained(job["base_model"])
141
+ train_blocks = pack(tok, docs[held:], int(hp["seq_len"]))
142
+ eval_blocks = pack(tok, docs[:held], int(hp["seq_len"]))
143
+ if len(train_blocks) == 0:
144
+ raise ValueError("dataset too small for one training block; lower seq_len or add documents")
145
+ steps_per_epoch = math.ceil(len(train_blocks) / int(hp["batch_size"]))
146
+ total = int(hp["max_steps"] or steps_per_epoch * int(hp["epochs"]))
147
+
148
+ emit(job_id, "meta", started_at=now(), backend="peft", world_size=1, kind=job.get("kind", "lora"),
149
+ base_model=job["base_model"], device=device, total_steps=total, documents=len(docs),
150
+ dataset_sha256=dataset_sha)
151
+ log(f"{len(docs)} docs -> {len(train_blocks)} train / {len(eval_blocks)} eval blocks of {hp['seq_len']} tokens; {total} steps on {device}")
152
+
153
+ model = AutoModelForCausalLM.from_pretrained(job["base_model"], dtype=torch.float32).to(device)
154
+ # Recompute activations in the backward pass: roughly halves peak RAM, so
155
+ # the job fits beside other work on a shared box.
156
+ model.gradient_checkpointing_enable()
157
+ model.enable_input_require_grads()
158
+ model = get_peft_model(model, LoraConfig(
159
+ r=int(hp["lora_r"]), lora_alpha=int(hp["lora_r"]) * 2, lora_dropout=0.05,
160
+ target_modules=hp.get("target_modules") or ["q_proj", "k_proj", "v_proj", "o_proj"],
161
+ task_type="CAUSAL_LM",
162
+ ))
163
+ log(f"trainable params: {sum(p.numel() for p in model.parameters() if p.requires_grad):,}")
164
+
165
+ opt = torch.optim.AdamW([p for p in model.parameters() if p.requires_grad], lr=float(hp["lr"]))
166
+ sched = torch.optim.lr_scheduler.LambdaLR(opt, lambda s: min(1.0, (s + 1) / 10) * max(0.0, 1 - s / total))
167
+
168
+ if len(eval_blocks):
169
+ emit(job_id, "eval", step=0, metrics={"perplexity": perplexity(model, eval_blocks, int(hp["batch_size"]))})
170
+
171
+ step, t0 = 0, time.time()
172
+ model.train()
173
+ while step < total:
174
+ order = torch.randperm(len(train_blocks))
175
+ for i in range(0, len(order), int(hp["batch_size"])):
176
+ batch = train_blocks[order[i : i + int(hp["batch_size"])]].to(device)
177
+ loss = model(input_ids=batch, labels=batch).loss
178
+ loss.backward()
179
+ grad_norm = torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0).item()
180
+ opt.step(); sched.step(); opt.zero_grad()
181
+ step += 1
182
+ emit(job_id, "step", step=step, total_steps=total, loss=round(loss.item(), 4), lr=sched.get_last_lr()[0],
183
+ grad_norm=round(grad_norm, 3),
184
+ throughput=round(step * int(hp["batch_size"]) * int(hp["seq_len"]) / (time.time() - t0), 1))
185
+ if step >= total:
186
+ break
187
+
188
+ if len(eval_blocks):
189
+ emit(job_id, "eval", step=step, metrics={"perplexity": perplexity(model, eval_blocks, int(hp["batch_size"]))})
190
+
191
+ out_dir.mkdir(parents=True, exist_ok=True)
192
+ model.save_pretrained(out_dir)
193
+ tok.save_pretrained(out_dir)
194
+ weights = out_dir / "adapter_model.safetensors"
195
+ digest = hashlib.sha256(weights.read_bytes()).hexdigest()
196
+ (out_dir / "manifest.json").write_text(json.dumps({
197
+ "name": job.get("name") or "adapter",
198
+ "kind": job.get("kind", "lora"),
199
+ "base_model": job["base_model"],
200
+ "adapter_sha256": digest,
201
+ "dataset_sha256": dataset_sha,
202
+ "documents": len(docs),
203
+ "steps": step,
204
+ "system_prompt": system,
205
+ "hyperparams": hp,
206
+ "finished_at": now(),
207
+ }, indent=2) + "\n")
208
+ emit(job_id, "checkpoint", step=step, path=str(out_dir), size_bytes=weights.stat().st_size,
209
+ model=f"sha256:{digest}")
210
+ emit(job_id, "done", reason="complete", final_step=step, finished_at=now())
211
+
212
+
213
+ if __name__ == "__main__":
214
+ job_id = "unknown"
215
+ try:
216
+ main()
217
+ except Exception as e: # report as protocol events so callers never parse a traceback
218
+ traceback.print_exc(file=sys.stderr)
219
+ emit(job_id, "error", message=str(e), code="E_RUNTIME")
220
+ emit(job_id, "done", reason="error", finished_at=now())
221
+ sys.exit(1)
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Liquid backend — temporal-policy training (CfC / LTC liquid networks, GRU
3
+ * baseline) on one provider, CPU or GPU. Workload `infernet.temporal.train`.
4
+ *
5
+ * Runs the isolated infernet-liquid runtime from @infernetprotocol/liquid-agent
6
+ * and maps its events onto this package's v1 training protocol:
7
+ * epoch → step (step = epoch, loss, val_step_accuracy)
8
+ * result → eval + checkpoint (the exported model dir) + done:complete
9
+ * error → error + done:error (done:cancel for E_CANCELLED)
10
+ *
11
+ * Job config:
12
+ * { kind: "temporal-policy", dataset: { url: <bundle path>, sha256? },
13
+ * output: { destination_url: <dir> }, family?: "cfc"|"ltc"|"gru",
14
+ * hyperparams?: {...}, job?: TrainJobV1 }
15
+ */
16
+
17
+ import { randomUUID } from "node:crypto";
18
+ import { AsyncQueue } from "@infernetprotocol/engine";
19
+ import { LiquidRuntime } from "@infernetprotocol/liquid-agent";
20
+ import { TMSG, TRAINING_PROTOCOL_VERSION } from "../protocol.js";
21
+
22
+ export function createLiquidBackend({ runtimeFactory = () => new LiquidRuntime() } = {}) {
23
+ let runtime = null;
24
+ return {
25
+ kind: "liquid",
26
+ start({ config = {}, id } = {}) {
27
+ const jobId = id ?? randomUUID();
28
+ const stream = new AsyncQueue();
29
+ const push = (msg) => stream.push({ v: TRAINING_PROTOCOL_VERSION, id: jobId, ...msg });
30
+ let cancelled = false;
31
+ let reqId = null;
32
+
33
+ (async () => {
34
+ const family = config.job?.model_type ?? config.family ?? "cfc";
35
+ push({ type: TMSG.META, backend: "liquid", started_at: new Date().toISOString(), world_size: 1, kind: "temporal-policy", family });
36
+ try {
37
+ runtime ??= runtimeFactory();
38
+ const params = {
39
+ bundle_path: config.dataset?.url,
40
+ output_dir: config.output?.destination_url,
41
+ family,
42
+ hyperparameters: config.hyperparams ?? {},
43
+ ...(config.job ? { job: config.job } : {})
44
+ };
45
+ if (cancelled) throw Object.assign(new Error("cancelled"), { code: "E_CANCELLED" });
46
+ const res = await runtime.request("train", params, {
47
+ onId: (rid) => {
48
+ reqId = rid;
49
+ },
50
+ onEvent: (ev) => {
51
+ if (ev.event === "epoch") push({ type: TMSG.STEP, step: ev.epoch, loss: ev.loss, val_step_accuracy: ev.val_step_accuracy });
52
+ }
53
+ });
54
+ if (config.dataset?.sha256 && res.eval.dataset_hash !== config.dataset.sha256) {
55
+ throw Object.assign(new Error("trained dataset hash differs from the job's"), { code: "E_HASH_MISMATCH" });
56
+ }
57
+ push({ type: TMSG.EVAL, step: res.manifest.training.epochs, metrics: res.eval.metrics });
58
+ push({ type: TMSG.CHECKPOINT, step: res.manifest.training.epochs, path: res.model_dir, size_bytes: res.manifest.weights.size_bytes, model_hash: res.manifest.weights.weights_hash });
59
+ push({ type: TMSG.DONE, reason: "complete", final_step: res.manifest.training.epochs, finished_at: new Date().toISOString(), manifest: res.manifest });
60
+ } catch (err) {
61
+ const reason = cancelled || err?.code === "E_CANCELLED" ? "cancel" : "error";
62
+ if (reason === "error") push({ type: TMSG.ERROR, message: err?.message ?? String(err), code: err?.code ?? "E_RUNTIME" });
63
+ push({ type: TMSG.DONE, reason, finished_at: new Date().toISOString() });
64
+ }
65
+ stream.end();
66
+ })();
67
+
68
+ return {
69
+ id: jobId,
70
+ stream,
71
+ cancel: () => {
72
+ cancelled = true;
73
+ if (reqId) runtime?.cancel(reqId).catch(() => {});
74
+ }
75
+ };
76
+ },
77
+ async shutdown() {
78
+ await runtime?.close();
79
+ runtime = null;
80
+ }
81
+ };
82
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * PEFT backend — LoRA fine-tunes of causal language models on one provider,
3
+ * CPU or CUDA. Workload `infernet.text.train`.
4
+ *
5
+ * Spawns `runners/peft_train.py <job.json>` in its own Python venv and relays
6
+ * its stdout, which is already training-protocol v1 NDJSON (meta / step /
7
+ * eval / checkpoint / done / error). Anything else on stdout is ignored;
8
+ * stderr is the runner's human log.
9
+ *
10
+ * Job config (see runners/peft_train.py):
11
+ * { kind: "lora", base_model, system_prompt?, dataset: { url, sha256? },
12
+ * hyperparams?: {...}, output: { destination_url } }
13
+ *
14
+ * The venv is installed only on request (`infernet model runtime setup --peft
15
+ * --yes`): CPU PyTorch + transformers + peft, about 1 GB.
16
+ */
17
+
18
+ import { randomUUID } from "node:crypto";
19
+ import { spawn } from "node:child_process";
20
+ import { existsSync } from "node:fs";
21
+ import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
22
+ import os from "node:os";
23
+ import path from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+ import { AsyncQueue } from "@infernetprotocol/engine";
26
+ import { TMSG, TRAINING_PROTOCOL_VERSION } from "../protocol.js";
27
+
28
+ export const PEFT_KINDS = Object.freeze(["lora", "peft"]);
29
+ export const RUNNER_PATH = fileURLToPath(new URL("../../runners/peft_train.py", import.meta.url));
30
+ export const PEFT_REQUIREMENTS = Object.freeze(["transformers>=4.46", "peft>=0.13", "safetensors>=0.4"]);
31
+
32
+ export function peftRuntimeDir() {
33
+ const base = process.env.XDG_DATA_HOME || path.join(os.homedir(), ".local", "share");
34
+ return path.join(base, "infernet", "peft");
35
+ }
36
+
37
+ /** The venv python, or null when the runtime is not installed. */
38
+ export function resolvePeftPython() {
39
+ const explicit = process.env.INFERNET_PEFT_PYTHON;
40
+ if (explicit) return existsSync(explicit) ? explicit : null;
41
+ const py = path.join(peftRuntimeDir(), "venv", "bin", "python");
42
+ return existsSync(py) ? py : null;
43
+ }
44
+
45
+ function run(cmd, args, log) {
46
+ return new Promise((resolve, reject) => {
47
+ const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
48
+ const relay = (b) => b.toString().split("\n").filter(Boolean).forEach((l) => log?.(l));
49
+ child.stdout.on("data", relay);
50
+ child.stderr.on("data", relay);
51
+ child.on("error", reject);
52
+ child.on("close", (code) => (code === 0 ? resolve() : reject(new Error(`${cmd} ${args.join(" ")} exited ${code}`))));
53
+ });
54
+ }
55
+
56
+ /** Create the venv and install CPU (or CUDA) PyTorch, transformers and peft. */
57
+ export async function setupPeftRuntime({ accelerator = "cpu", python = "python3", log } = {}) {
58
+ const dir = peftRuntimeDir();
59
+ await mkdir(dir, { recursive: true });
60
+ const venv = path.join(dir, "venv");
61
+ if (!existsSync(path.join(venv, "bin", "python"))) await run(python, ["-m", "venv", venv], log);
62
+ const py = path.join(venv, "bin", "python");
63
+ await run(py, ["-m", "pip", "install", "--upgrade", "--quiet", "pip"], log);
64
+ const torchIndex = accelerator === "cuda" ? [] : ["--index-url", "https://download.pytorch.org/whl/cpu"];
65
+ await run(py, ["-m", "pip", "install", "--quiet", "torch", ...torchIndex], log);
66
+ await run(py, ["-m", "pip", "install", "--quiet", ...PEFT_REQUIREMENTS], log);
67
+ return { python: py, accelerator, runner: RUNNER_PATH };
68
+ }
69
+
70
+ /** Versions of the installed runtime, or null. */
71
+ export async function peftRuntimeStatus() {
72
+ const py = resolvePeftPython();
73
+ if (!py) return null;
74
+ const code = "import json,torch,transformers,peft;print(json.dumps({'torch':torch.__version__,'transformers':transformers.__version__,'peft':peft.__version__,'cuda':torch.cuda.is_available()}))";
75
+ return new Promise((resolve) => {
76
+ const child = spawn(py, ["-c", code], { stdio: ["ignore", "pipe", "ignore"] });
77
+ let out = "";
78
+ child.stdout.on("data", (b) => (out += b));
79
+ child.on("error", () => resolve(null));
80
+ child.on("close", (c) => {
81
+ try {
82
+ resolve(c === 0 ? { python: py, runner: RUNNER_PATH, ...JSON.parse(out) } : null);
83
+ } catch {
84
+ resolve(null);
85
+ }
86
+ });
87
+ });
88
+ }
89
+
90
+ export function createPeftBackend({ python = null, runner = RUNNER_PATH, spawnImpl = spawn } = {}) {
91
+ const children = new Set();
92
+ return {
93
+ kind: "peft",
94
+ /**
95
+ * `config` is the job object; `jobPath` (optional) is where it lives, so
96
+ * the runner resolves relative dataset/output paths against it.
97
+ */
98
+ start({ config = {}, id, jobPath } = {}) {
99
+ const jobId = id ?? config.id ?? randomUUID();
100
+ const stream = new AsyncQueue();
101
+ const push = (msg) => stream.push({ v: TRAINING_PROTOCOL_VERSION, id: jobId, ...msg });
102
+ let cancelled = false;
103
+ let child = null;
104
+
105
+ (async () => {
106
+ let sawDone = false;
107
+ try {
108
+ const py = python ?? resolvePeftPython();
109
+ if (!py) throw Object.assign(new Error("the peft runtime is not installed; run `infernet model runtime setup --peft --yes`"), { code: "E_NO_RUNTIME" });
110
+ if (!PEFT_KINDS.includes(config.kind)) throw Object.assign(new Error(`job kind ${config.kind} is not a peft job (${PEFT_KINDS.join(", ")})`), { code: "E_BAD_JOB" });
111
+ let file = jobPath;
112
+ if (!file) {
113
+ const dir = await mkdtemp(path.join(os.tmpdir(), "infernet-peft-"));
114
+ file = path.join(dir, "job.json");
115
+ await writeFile(file, JSON.stringify({ ...config, id: jobId }, null, 2));
116
+ }
117
+ child = spawnImpl(py, [runner, file], { stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, PYTHONUNBUFFERED: "1" } });
118
+ children.add(child);
119
+ let buf = "";
120
+ child.stdout.on("data", (b) => {
121
+ buf += b.toString();
122
+ let nl;
123
+ while ((nl = buf.indexOf("\n")) >= 0) {
124
+ const line = buf.slice(0, nl).trim();
125
+ buf = buf.slice(nl + 1);
126
+ if (!line.startsWith("{")) continue;
127
+ try {
128
+ const ev = JSON.parse(line);
129
+ if (ev?.v !== TRAINING_PROTOCOL_VERSION || !ev.type) continue;
130
+ if (ev.type === TMSG.DONE) sawDone = true;
131
+ stream.push({ ...ev, id: jobId });
132
+ } catch {
133
+ /* not an event */
134
+ }
135
+ }
136
+ });
137
+ const tail = [];
138
+ child.stderr.on("data", (b) => {
139
+ for (const l of b.toString().split("\n").filter(Boolean)) {
140
+ tail.push(l);
141
+ if (tail.length > 20) tail.shift();
142
+ }
143
+ });
144
+ const code = await new Promise((resolve, reject) => {
145
+ child.on("error", reject);
146
+ child.on("close", resolve);
147
+ });
148
+ if (!sawDone) {
149
+ if (cancelled) push({ type: TMSG.DONE, reason: "cancel", finished_at: new Date().toISOString() });
150
+ else {
151
+ push({ type: TMSG.ERROR, message: `runner exited ${code}: ${tail.at(-1) ?? "no output"}`, code: "E_RUNTIME" });
152
+ push({ type: TMSG.DONE, reason: "error", finished_at: new Date().toISOString() });
153
+ }
154
+ }
155
+ } catch (err) {
156
+ push({ type: TMSG.ERROR, message: err?.message ?? String(err), code: err?.code ?? "E_RUNTIME" });
157
+ push({ type: TMSG.DONE, reason: "error", finished_at: new Date().toISOString() });
158
+ } finally {
159
+ if (child) children.delete(child);
160
+ stream.end();
161
+ }
162
+ })();
163
+
164
+ return {
165
+ id: jobId,
166
+ stream,
167
+ cancel: () => {
168
+ cancelled = true;
169
+ child?.kill("SIGTERM");
170
+ }
171
+ };
172
+ },
173
+ async shutdown() {
174
+ for (const c of children) c.kill("SIGTERM");
175
+ children.clear();
176
+ }
177
+ };
178
+ }
package/src/index.js CHANGED
@@ -17,6 +17,13 @@
17
17
  * OpenDiLoCo). Class C: WAN-tolerant delta exchange.
18
18
  * - "petals" — pipeline-parallel sharding for fine-tunes across
19
19
  * volunteer GPUs. Class C-LLM: BigScience's Petals.
20
+ * - "liquid" — temporal policies (CfC/LTC liquid networks, GRU
21
+ * baseline) via the isolated infernet-liquid runtime.
22
+ * Single provider, CPU or GPU. Workload
23
+ * infernet.temporal.train.
24
+ * - "peft" — LoRA fine-tunes of causal LMs (transformers + peft)
25
+ * in their own venv, CPU or CUDA. Single provider.
26
+ * Workload infernet.text.train.
20
27
  * - "stub" — synthetic training run, no GPU required. Default.
21
28
  *
22
29
  * Auto-selection precedence (only if `opts.backend` is not set):
@@ -25,12 +32,23 @@
25
32
  */
26
33
 
27
34
  import { createDeepspeedBackend } from "./backends/deepspeed.js";
35
+ import { createLiquidBackend } from "./backends/liquid.js";
28
36
  import { createOpenDiLoCoBackend } from "./backends/opendiloco.js";
29
37
  import { createOpenRLHFBackend } from "./backends/openrlhf.js";
30
38
  import { createPetalsBackend } from "./backends/petals.js";
39
+ import { createPeftBackend } from "./backends/peft.js";
31
40
  import { createStubTrainer } from "./backends/stub.js";
32
41
 
33
42
  export * from "./protocol.js";
43
+ export {
44
+ createPeftBackend,
45
+ peftRuntimeDir,
46
+ peftRuntimeStatus,
47
+ PEFT_KINDS,
48
+ resolvePeftPython,
49
+ RUNNER_PATH as PEFT_RUNNER_PATH,
50
+ setupPeftRuntime
51
+ } from "./backends/peft.js";
34
52
 
35
53
  export async function createTrainer(opts = {}) {
36
54
  const backend = opts.backend ?? autoSelectBackend();
@@ -43,6 +61,10 @@ export async function createTrainer(opts = {}) {
43
61
  return createOpenDiLoCoBackend(opts);
44
62
  case "petals":
45
63
  return createPetalsBackend(opts);
64
+ case "liquid":
65
+ return createLiquidBackend(opts);
66
+ case "peft":
67
+ return createPeftBackend(opts);
46
68
  case "stub":
47
69
  return createStubTrainer(opts);
48
70
  default:
package/src/protocol.js CHANGED
@@ -21,7 +21,7 @@
21
21
  *
22
22
  * Job config shape (extend as needed; backends ignore fields they don't use):
23
23
  * {
24
- * kind: "fine-tune" | "lora" | "rlhf-rollout" | "pretrain",
24
+ * kind: "fine-tune" | "lora" | "rlhf-rollout" | "pretrain" | "temporal-policy",
25
25
  * base_model: string,
26
26
  * dataset: { url, sha256?, format?, split? },
27
27
  * hyperparams: { lr?, batch_size?, epochs?, max_steps? },
@@ -48,7 +48,7 @@ export const TMSG = Object.freeze({
48
48
  LOG: "log"
49
49
  });
50
50
 
51
- export const JOB_KINDS = Object.freeze(["fine-tune", "lora", "rlhf-rollout", "pretrain"]);
51
+ export const JOB_KINDS = Object.freeze(["fine-tune", "lora", "rlhf-rollout", "pretrain", "temporal-policy"]);
52
52
 
53
53
  export const DONE_REASONS = Object.freeze(["complete", "cancel", "error", "not_implemented"]);
54
54