@infernetprotocol/cli 0.1.35 → 0.1.36
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/commands/start.js +96 -1
- package/commands/train.js +51 -13
- package/package.json +6 -6
package/commands/start.js
CHANGED
|
@@ -776,6 +776,81 @@ async function runDaemon(args, ctx) {
|
|
|
776
776
|
};
|
|
777
777
|
}
|
|
778
778
|
|
|
779
|
+
/**
|
|
780
|
+
* IPIP-0030: shard-hosting routes layered on top of /healthz.
|
|
781
|
+
* Returns true if the request matched and was handled.
|
|
782
|
+
*/
|
|
783
|
+
async function handleTrainingHttp(req, res) {
|
|
784
|
+
if (!req.url) return false;
|
|
785
|
+
const url = new URL(req.url, 'http://localhost');
|
|
786
|
+
const pathname = url.pathname;
|
|
787
|
+
|
|
788
|
+
// GET /v1/training/shards/<run_id>/<shard_index>.jsonl
|
|
789
|
+
const shardMatch = pathname.match(/^\/v1\/training\/shards\/([A-Za-z0-9_-]+)\/shard-(\d+)\.jsonl$/);
|
|
790
|
+
if (shardMatch && req.method === 'GET') {
|
|
791
|
+
const fs = await import('node:fs');
|
|
792
|
+
const path = await import('node:path');
|
|
793
|
+
const [, runId, idx] = shardMatch;
|
|
794
|
+
const filePath = path.join(
|
|
795
|
+
process.env.HOME ?? '/tmp',
|
|
796
|
+
'.infernet', 'training-runs', runId, 'shards', `shard-${idx}.jsonl`
|
|
797
|
+
);
|
|
798
|
+
if (!fs.existsSync(filePath)) {
|
|
799
|
+
res.writeHead(404, { 'content-type': 'text/plain' });
|
|
800
|
+
res.end('shard not found\n');
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
res.writeHead(200, {
|
|
804
|
+
'content-type': 'application/jsonl',
|
|
805
|
+
'content-length': fs.statSync(filePath).size,
|
|
806
|
+
'cache-control': 'no-store'
|
|
807
|
+
});
|
|
808
|
+
fs.createReadStream(filePath).pipe(res);
|
|
809
|
+
return true;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// PUT /v1/training/adapters/<run_id>/<shard_index>?token=<t>
|
|
813
|
+
const adapterMatch = pathname.match(/^\/v1\/training\/adapters\/([A-Za-z0-9_-]+)\/(\d+)$/);
|
|
814
|
+
if (adapterMatch && req.method === 'PUT') {
|
|
815
|
+
const fsp = await import('node:fs/promises');
|
|
816
|
+
const fs = await import('node:fs');
|
|
817
|
+
const path = await import('node:path');
|
|
818
|
+
const [, runId, idx] = adapterMatch;
|
|
819
|
+
const runDir = path.join(process.env.HOME ?? '/tmp', '.infernet', 'training-runs', runId);
|
|
820
|
+
const manifestPath = path.join(runDir, 'manifest.json');
|
|
821
|
+
if (!fs.existsSync(manifestPath)) {
|
|
822
|
+
res.writeHead(404, { 'content-type': 'text/plain' });
|
|
823
|
+
res.end('run not found\n');
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
// Token check: only accept PUTs whose ?token=<t> matches the
|
|
827
|
+
// run's manifest. The submitter mints the token at run-start
|
|
828
|
+
// and shares it with the control plane only via upload_url.
|
|
829
|
+
const manifest = JSON.parse(await fsp.readFile(manifestPath, 'utf8'));
|
|
830
|
+
const presentedToken = url.searchParams.get('token');
|
|
831
|
+
if (!presentedToken || presentedToken !== manifest.upload_token) {
|
|
832
|
+
res.writeHead(403, { 'content-type': 'text/plain' });
|
|
833
|
+
res.end('bad token\n');
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
const adapterDir = path.join(runDir, 'adapters');
|
|
837
|
+
await fsp.mkdir(adapterDir, { recursive: true });
|
|
838
|
+
const outPath = path.join(adapterDir, `shard-${idx}.adapter.safetensors`);
|
|
839
|
+
await new Promise((resolve, reject) => {
|
|
840
|
+
const ws = fs.createWriteStream(outPath);
|
|
841
|
+
req.pipe(ws);
|
|
842
|
+
ws.on('finish', resolve);
|
|
843
|
+
ws.on('error', reject);
|
|
844
|
+
req.on('error', reject);
|
|
845
|
+
});
|
|
846
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
847
|
+
res.end(JSON.stringify({ ok: true, path: outPath }));
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
|
|
779
854
|
function snapshot() {
|
|
780
855
|
return {
|
|
781
856
|
pid: process.pid,
|
|
@@ -946,7 +1021,7 @@ async function runDaemon(args, ctx) {
|
|
|
946
1021
|
// firewalled). Returns 200 + a JSON daemon snapshot.
|
|
947
1022
|
const healthPort = Number.parseInt(process.env.PORT ?? '', 10) || 8080;
|
|
948
1023
|
try {
|
|
949
|
-
healthServer = http.createServer((req, res) => {
|
|
1024
|
+
healthServer = http.createServer(async (req, res) => {
|
|
950
1025
|
if (req.url === '/healthz' || req.url === '/health' || req.url === '/') {
|
|
951
1026
|
const snap = snapshot();
|
|
952
1027
|
const body = JSON.stringify({
|
|
@@ -968,6 +1043,26 @@ async function runDaemon(args, ctx) {
|
|
|
968
1043
|
res.end(body);
|
|
969
1044
|
return;
|
|
970
1045
|
}
|
|
1046
|
+
|
|
1047
|
+
// IPIP-0030: serve training shards directly from this node's
|
|
1048
|
+
// local filesystem. The submitter's CLI writes shards to
|
|
1049
|
+
// ~/.infernet/training-runs/<run_id>/shards/shard-<i>.jsonl
|
|
1050
|
+
// and posts the URL referencing this same daemon's endpoint.
|
|
1051
|
+
// No third-party storage, no separate ports, no signup —
|
|
1052
|
+
// the daemon's already on a reachable port.
|
|
1053
|
+
//
|
|
1054
|
+
// Routes:
|
|
1055
|
+
// GET /v1/training/shards/<run_id>/<shard_index>.jsonl
|
|
1056
|
+
// PUT /v1/training/adapters/<run_id>/<shard_index>?token=<t>
|
|
1057
|
+
try {
|
|
1058
|
+
const handled = await handleTrainingHttp(req, res);
|
|
1059
|
+
if (handled) return;
|
|
1060
|
+
} catch (err) {
|
|
1061
|
+
res.writeHead(500, { 'content-type': 'text/plain' });
|
|
1062
|
+
res.end(`training http error: ${err?.message ?? err}\n`);
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
971
1066
|
res.writeHead(404, { 'content-type': 'text/plain' });
|
|
972
1067
|
res.end('not found\n');
|
|
973
1068
|
});
|
package/commands/train.js
CHANGED
|
@@ -359,6 +359,13 @@ async function cmdRun(args) {
|
|
|
359
359
|
* IPIP-0030: post a training job to the open market. Any operator on
|
|
360
360
|
* the network running with --accept-training claims shards and reports
|
|
361
361
|
* back; we poll until all shards complete, then FedAvg the adapters.
|
|
362
|
+
*
|
|
363
|
+
* Shards are hosted by the SUBMITTER'S OWN DAEMON — no S3, no HF, no
|
|
364
|
+
* IPFS, no third-party storage. The local daemon's HTTP server already
|
|
365
|
+
* has a reachable endpoint registered with the control plane; we just
|
|
366
|
+
* drop shard files in ~/.infernet/training-runs/<run_id>/shards/ and
|
|
367
|
+
* the daemon serves them at /v1/training/shards/<run_id>/shard-<i>.jsonl
|
|
368
|
+
* (handler in commands/start.js handleTrainingHttp).
|
|
362
369
|
*/
|
|
363
370
|
async function runOpenMarket({ trainConfig, runDir, runId, args }) {
|
|
364
371
|
const cfg = await loadConfig().catch(() => ({}));
|
|
@@ -368,15 +375,27 @@ async function runOpenMarket({ trainConfig, runDir, runId, args }) {
|
|
|
368
375
|
process.stderr.write(`error: open-market training needs a logged-in session — run \`infernet login\` first\n`);
|
|
369
376
|
return 1;
|
|
370
377
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
378
|
+
|
|
379
|
+
// Discover this submitter's own daemon endpoint. The daemon
|
|
380
|
+
// registered an endpoint_url at startup; it's stored locally in
|
|
381
|
+
// config under node.endpoint_url OR can be derived from advertised
|
|
382
|
+
// address + PORT (default 8080 — the same /healthz HTTP server).
|
|
383
|
+
const advertised = cfg?.node?.advertised_endpoint
|
|
384
|
+
?? cfg?.node?.endpoint_url
|
|
385
|
+
?? process.env.INFERNET_DAEMON_ENDPOINT;
|
|
386
|
+
if (!advertised) {
|
|
374
387
|
process.stderr.write(
|
|
375
|
-
`error:
|
|
376
|
-
`
|
|
388
|
+
`error: can't find this node's public endpoint. Either:\n` +
|
|
389
|
+
` - run \`infernet start\` so the daemon registers an endpoint, OR\n` +
|
|
390
|
+
` - set INFERNET_DAEMON_ENDPOINT=http://<your-public-ip>:8080\n` +
|
|
391
|
+
`\nThe submitter's daemon hosts the shards directly — no S3, no HF.\n` +
|
|
392
|
+
`If your machine is behind NAT, run a tunnel:\n` +
|
|
393
|
+
` cloudflared tunnel --url http://localhost:8080\n` +
|
|
394
|
+
`and set INFERNET_DAEMON_ENDPOINT to the cloudflared URL.\n`
|
|
377
395
|
);
|
|
378
396
|
return 1;
|
|
379
397
|
}
|
|
398
|
+
|
|
380
399
|
const numShards = Number.parseInt(args.get("max-nodes") ?? args.get("num-shards") ?? "5", 10);
|
|
381
400
|
const budget = Number.parseFloat(args.get("budget") ?? "0");
|
|
382
401
|
const pricePerShard = numShards > 0 ? budget / numShards : 0;
|
|
@@ -387,12 +406,31 @@ async function runOpenMarket({ trainConfig, runDir, runId, args }) {
|
|
|
387
406
|
return 1;
|
|
388
407
|
}
|
|
389
408
|
|
|
390
|
-
// Split the local JSONL into N shards
|
|
409
|
+
// Split the local JSONL into N shards under ~/.infernet/training-runs/<run_id>/.
|
|
410
|
+
// The daemon's HTTP server reads from this exact path.
|
|
391
411
|
const { splitJsonl } = await import("../lib/training/p2p-coordinator.js");
|
|
392
|
-
const
|
|
412
|
+
const home = process.env.HOME ?? "/tmp";
|
|
413
|
+
const localRunDir = path.join(home, ".infernet", "training-runs", runId);
|
|
414
|
+
const shardsDir = path.join(localRunDir, "shards");
|
|
393
415
|
process.stdout.write(`Splitting ${datasetPath} into ${numShards} shard(s)…\n`);
|
|
394
416
|
const shards = await splitJsonl({ inputPath: datasetPath, outDir: shardsDir, numShards });
|
|
395
|
-
|
|
417
|
+
|
|
418
|
+
// Mint a per-run upload token so operators that complete a shard
|
|
419
|
+
// can PUT their adapter back to the submitter's daemon, and only
|
|
420
|
+
// those who claimed the shard via the control plane have the token.
|
|
421
|
+
const uploadToken = (await import("node:crypto")).randomBytes(16).toString("hex");
|
|
422
|
+
await fs.writeFile(
|
|
423
|
+
path.join(localRunDir, "manifest.json"),
|
|
424
|
+
JSON.stringify({ run_id: runId, num_shards: shards.length, upload_token: uploadToken, created_at: new Date().toISOString() }, null, 2)
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
// Build the canonical URLs the control plane will hand out to claimers.
|
|
428
|
+
const base = advertised.replace(/\/$/, "");
|
|
429
|
+
const datasetBaseUrl = `${base}/v1/training/shards/${runId}`;
|
|
430
|
+
const uploadBaseUrl = `${base}/v1/training/adapters/${runId}?token=${uploadToken}`;
|
|
431
|
+
|
|
432
|
+
process.stdout.write(` shard URLs: ${datasetBaseUrl}/shard-N.jsonl\n`);
|
|
433
|
+
process.stdout.write(` adapter PUT URL: ${uploadBaseUrl.replace(uploadToken, "<token>")}\n`);
|
|
396
434
|
|
|
397
435
|
// Submit the job
|
|
398
436
|
process.stdout.write(`\nPosting job to the open market…\n`);
|
|
@@ -419,11 +457,11 @@ async function runOpenMarket({ trainConfig, runDir, runId, args }) {
|
|
|
419
457
|
return 1;
|
|
420
458
|
}
|
|
421
459
|
const { data } = await res.json();
|
|
422
|
-
process.stdout.write(
|
|
423
|
-
process.stdout.write(
|
|
424
|
-
process.stdout.write(`
|
|
425
|
-
process.stdout.write(
|
|
426
|
-
process.stdout.write(`
|
|
460
|
+
process.stdout.write(`\n✓ job ${data.job.id} posted (${data.shards.length} shards · $${pricePerShard.toFixed(4)}/shard · $${budget.toFixed(2)} budget)\n`);
|
|
461
|
+
process.stdout.write(`Shards hosted by your local daemon at ${base}\n`);
|
|
462
|
+
process.stdout.write(`Adapters land in ${path.join(localRunDir, "adapters")} as operators report\n`);
|
|
463
|
+
process.stdout.write(`\nKeep the daemon running until all shards complete. When done:\n`);
|
|
464
|
+
process.stdout.write(` python3 ${path.join(runDir, "_fedavg.py")} --out ${path.join(runDir, "checkpoint-final")} ${path.join(localRunDir, "adapters")}/*\n`);
|
|
427
465
|
|
|
428
466
|
await fs.writeFile(path.join(runDir, "open-market-job.json"), JSON.stringify(data, null, 2));
|
|
429
467
|
return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infernetprotocol/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"ora": "^9.4.0",
|
|
31
31
|
"react": "^17.0.2",
|
|
32
32
|
"react-blessed": "^0.7.2",
|
|
33
|
-
"@infernetprotocol/auth": "0.1.
|
|
34
|
-
"@infernetprotocol/
|
|
35
|
-
"@infernetprotocol/deploy-providers": "0.1.
|
|
36
|
-
"@infernetprotocol/
|
|
37
|
-
"@infernetprotocol/gpu": "0.1.
|
|
33
|
+
"@infernetprotocol/auth": "0.1.36",
|
|
34
|
+
"@infernetprotocol/config": "0.1.36",
|
|
35
|
+
"@infernetprotocol/deploy-providers": "0.1.36",
|
|
36
|
+
"@infernetprotocol/engine": "0.1.36",
|
|
37
|
+
"@infernetprotocol/gpu": "0.1.36"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|