pi-splash-server 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -65,6 +65,7 @@ In Pi:
65
65
  /splash status and the next step
66
66
  /splash use switch to a Splash server started outside Pi
67
67
  /splash bench [--long] measure speed and memory use on the running server
68
+ /splash bench share open a prefilled GitHub issue with the last bench report
68
69
  /splash stop stop the server
69
70
  /splash log last lines of the server log
70
71
  /splash install put the runtime's install command into the editor
@@ -91,8 +92,13 @@ are, unless the first message is a few words long.
91
92
  `/splash bench` measures prompt processing, cache reuse, decode speed and memory
92
93
  use for any model started with `/splash start <repo or repo:QUANT>`. Close other
93
94
  heavy apps and allow a few minutes, or longer with `--long` for a 32K prompt
94
- if the context allows it. We welcome results as
95
- [issues in this repo](https://github.com/sady4850/pi-splash-server/issues).
95
+ if the context allows it.
96
+
97
+ To share the result, run `/splash bench share`. It opens a
98
+ [bench report issue](https://github.com/sady4850/pi-splash-server/issues/new?template=bench.yml)
99
+ with the report filled in; nothing is sent until you press Submit. The report
100
+ has the chip, memory, macOS, runtime, model, server flags (paths and keys
101
+ removed) and the numbers.
96
102
 
97
103
  ## What it picks
98
104
 
@@ -1,8 +1,9 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { readFileSync } from "node:fs";
2
+ import { execFile } from "node:child_process";
3
+ import { readdirSync, readFileSync } from "node:fs";
3
4
  import { join } from "node:path";
4
5
  import { runBench } from "../src/bench.ts";
5
- import { benchReport } from "../src/bench-report.ts";
6
+ import { benchReport, shareUrl } from "../src/bench-report.ts";
6
7
  import { detectMac, macosWarning, runtimeFor } from "../src/mac.ts";
7
8
  import { DRAFT_GB, loadEntries, recommend, diskWarnings, isDownloaded } from "../src/recommend.ts";
8
9
  import { bytes, bytesOnDisk, downloadLabel, downloadLines, downloadNotice, gb, planDownload } from "../src/download.ts";
@@ -213,7 +214,8 @@ export default async function (pi: ExtensionAPI) {
213
214
  const progress = (text: string) => ctx.ui.setStatus("splash", `splash: bench ${text}`);
214
215
  try {
215
216
  const { result, filename } = await runBench(p, long, signal, launcher, progress);
216
- ctx.ui.notify(`${benchReport(result)}\nJSON: ~/.pi/agent/splash/${filename}`, result.error ? "error" : "info");
217
+ const share = result.error ? "" : "\nShare: /splash bench share opens a prefilled GitHub issue, you check it and submit";
218
+ ctx.ui.notify(`${benchReport(result)}\nJSON: ~/.pi/agent/splash/${filename}${share}`, result.error ? "error" : "info");
217
219
  } catch (e) {
218
220
  ctx.ui.notify(`Splash bench: ${signal.aborted ? "aborted" : e instanceof Error ? e.message : String(e)}`, "error");
219
221
  } finally {
@@ -222,6 +224,16 @@ export default async function (pi: ExtensionAPI) {
222
224
  }
223
225
  }
224
226
 
227
+ function shareCmd(ctx: any) {
228
+ const latest = readdirSync(STATE_DIR).filter((f) => /^bench-.*\.json$/.test(f)).sort().pop();
229
+ if (!latest) return ctx.ui.notify("No bench results yet. Run /splash bench first.", "error");
230
+ const url = shareUrl(JSON.parse(readFileSync(join(STATE_DIR, latest), "utf8")));
231
+ execFile("/usr/bin/open", [url], (e) => {
232
+ if (e) ctx.ui.notify(`Could not open the browser. Open this link:\n${url}`, "error");
233
+ else ctx.ui.notify(`Opened a prefilled GitHub issue for ${latest}. Check it and press Submit.`, "info");
234
+ });
235
+ }
236
+
225
237
  async function stopCmd(ctx: any) {
226
238
  bench?.abort.abort();
227
239
  const p = port();
@@ -294,9 +306,9 @@ export default async function (pi: ExtensionAPI) {
294
306
  });
295
307
 
296
308
  pi.registerCommand("splash", {
297
- description: "Local Splash server: status, doctor, start [model], bench [--long], stop, use, log, install, update",
309
+ description: "Local Splash server: status, doctor, start [model], bench [--long | share], stop, use, log, install, update",
298
310
  getArgumentCompletions: (prefix: string) => {
299
- const items = ["doctor", "start", "bench", "bench --long", "stop", "use", "log", "install", "update"].filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
311
+ const items = ["doctor", "start", "bench", "bench --long", "bench share", "stop", "use", "log", "install", "update"].filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
300
312
  return items.length ? items : null;
301
313
  },
302
314
  handler: async (args: string, ctx: any) => {
@@ -309,7 +321,8 @@ export default async function (pi: ExtensionAPI) {
309
321
  case "start":
310
322
  return startCmd(rest[0], ctx);
311
323
  case "bench": {
312
- if (rest.length && !(rest.length === 1 && rest[0] === "--long")) return ctx.ui.notify("Usage: /splash bench [--long]", "error");
324
+ if (rest.length === 1 && rest[0] === "share") return shareCmd(ctx);
325
+ if (rest.length && !(rest.length === 1 && rest[0] === "--long")) return ctx.ui.notify("Usage: /splash bench [--long | share]", "error");
313
326
  if (bench) return ctx.ui.notify("A Splash bench is already running.", "info");
314
327
  const abort = new AbortController();
315
328
  bench = { abort, done: benchmark(rest[0] === "--long", ctx, abort.signal) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-splash-server",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Run a local Splash server from Pi, with the model and flags picked for your Mac (M1/M2 via splash-m1)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,28 +8,58 @@ export function stats(values: number[]) {
8
8
  return { median, min: sorted[0], max: sorted[sorted.length - 1] };
9
9
  }
10
10
 
11
- function cell(values: (number | null | undefined)[], digits: number, scale = 1): string {
12
- const numbers = values.filter((v): v is number => v != null);
11
+ function present(values: (number | null | undefined)[]) {
12
+ return values.filter((v): v is number => v != null && Number.isFinite(v));
13
+ }
14
+
15
+ function median(values: (number | null | undefined)[]) {
16
+ return stats(present(values))?.median ?? null;
17
+ }
18
+
19
+ const fixed = (n: number | null, digits: number) => n == null ? "-" : n.toFixed(digits);
20
+
21
+ function spread(values: (number | null | undefined)[], digits: number) {
22
+ const numbers = present(values);
13
23
  const range = stats(numbers);
14
- if (!range) return "-";
15
- const format = (n: number) => (n * scale).toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: digits });
16
- const median = format(range.median);
17
- return numbers.length > 1 && range.min !== range.max ? `${median} (${format(range.min)}-${format(range.max)})` : median;
18
- }
19
-
20
- function row(test: BenchRequest["test"], runs: BenchRequest[]) {
21
- const decode = test === "code" || test === "prose";
22
- const hits = runs.flatMap((r, i) => (r.cachedTokens ?? 0) > 0 ? [i + 1] : []);
23
- const cached = cell(runs.map(r => r.cachedTokens), 1);
24
- const columns = [
25
- test, cell(runs.map(r => decode ? r.completionTokens : r.promptTokens), 1),
26
- decode ? "-" : cell(runs.map(r => r.ttftMs), 2, 0.001),
27
- test.startsWith("prefill") ? cell(runs.map(r => r.timings.prompt_per_second), 1) : "-",
28
- decode ? cell(runs.map(r => r.timings.predicted_per_second), 1) : "-",
29
- decode ? cell(runs.map(r => r.draftAcceptance), 1, 100) : "-",
30
- test.startsWith("prefill") && hits.length ? `${cached} cache hit #${hits.join(",#")}` : cached,
31
- ];
32
- return `| ${columns.join(" | ")} |`;
24
+ if (numbers.length < 2 || !range) return "";
25
+ return `${numbers.length} runs: ${range.min.toFixed(digits)}-${range.max.toFixed(digits)}`;
26
+ }
27
+
28
+ const labels: Record<BenchRequest["test"], string> = {
29
+ "warm-up": "Warm-up", "prefill 1K": "Prefill 1K", "prefill 8K": "Prefill 8K", "prefill 32K": "Prefill 32K",
30
+ "replay 8K": "Replay 8K", code: "Decode code", prose: "Decode prose",
31
+ };
32
+
33
+ function row(test: BenchRequest["test"], runs: BenchRequest[]): string[] {
34
+ const label = labels[test];
35
+ const tokens = (values: number[]) => `${Math.round(median(values) ?? 0)} tok`;
36
+ if (test === "code" || test === "prose") {
37
+ const speed = runs.map(r => r.timings.predicted_per_second);
38
+ const accepted = median(runs.map(r => r.draftAcceptance));
39
+ const tail = [tokens(runs.map(r => r.completionTokens)), spread(speed, 1)].filter(Boolean).join(", ");
40
+ return [label, fixed(median(speed), 1), "tok/s", "draft", accepted == null ? "-" : `${Math.round(accepted * 100)}%`, tail];
41
+ }
42
+ const ttft = `${fixed(median(runs.map(r => r.ttftMs / 1000)), 2)} s`;
43
+ const prompt = tokens(runs.map(r => r.promptTokens));
44
+ if (test === "replay 8K") {
45
+ const cached = Math.round(median(runs.map(r => r.cachedTokens)) ?? 0);
46
+ return [label, "", "", "TTFT", ttft, `${cached} of ${prompt} cached`];
47
+ }
48
+ const speed = runs.map(r => r.timings.prompt_per_second);
49
+ const hits = runs.flatMap((r, i) => (r.cachedTokens ?? 0) > 0 ? [`#${i + 1}`] : []);
50
+ const tail = [prompt, spread(speed, 1), hits.length && `cache hit in run ${hits.join(", ")}`].filter(Boolean).join(", ");
51
+ return [label, fixed(median(speed), 1), "tok/s", "TTFT", ttft, tail];
52
+ }
53
+
54
+ function align(rows: string[][], right: number[]) {
55
+ const widths = rows[0].map((_, c) => Math.max(...rows.map(r => r[c].length)));
56
+ const gaps = ["", " ", " ", " ", " ", " "];
57
+ return rows.map(r => r.map((cell, c) => gaps[c] + (right.includes(c) ? cell.padStart(widths[c]) : cell.padEnd(widths[c])))
58
+ .join("").trimEnd());
59
+ }
60
+
61
+ function contextLabel(tokens: number) {
62
+ return tokens % 1024 === 0 ? `${tokens / 1024}K` : tokens.toLocaleString("en-US");
33
63
  }
34
64
 
35
65
  export function benchReport(result: BenchResult): string {
@@ -39,20 +69,39 @@ export function benchReport(result: BenchResult): string {
39
69
  env.power && `on ${env.power}`, env.lowPower != null && `Low Power Mode ${env.lowPower ? "on" : "off"}`,
40
70
  env.thermalWarning && `thermal warning ${env.thermalWarning}`,
41
71
  ].filter(Boolean);
72
+ const header: [string, string][] = [
73
+ ["Mac:", mac.join(", ")],
74
+ ["Runtime:", `${env.runtime} ${env.runtimeVersion ?? "unknown version"}`],
75
+ ["Model:", `${env.model}, ${contextLabel(env.context)} context`],
76
+ [env.flagsSource === "start" ? "Flags:" : "Server process flags:", env.flags === null ? "unavailable" : env.flags || "(none)"],
77
+ ];
78
+ const width = Math.max(...header.map(([key]) => key.length)) + 1;
79
+
80
+ const tests = Array.from(new Set(requests.map(r => r.test)), test => row(test, requests.filter(r => r.test === test)));
42
81
  const seconds = Math.round(result.durationMs / 1000);
43
82
  const memory = [];
44
- if (before.swapGB != null || after.swapGB != null) memory.push(`Swap: ${before.swapGB?.toFixed(1) ?? "?"} -> ${after.swapGB?.toFixed(1) ?? "?"} GB.`);
45
- if (before.freePercent != null || after.freePercent != null) memory.push(`Free memory: ${before.freePercent ?? "?"}% -> ${after.freePercent ?? "?"}%.`);
46
- memory.push(`Took ${Math.floor(seconds / 60)} min ${seconds % 60} s.`);
83
+ if (before.swapGB != null || after.swapGB != null) memory.push(`swap ${before.swapGB?.toFixed(1) ?? "?"} -> ${after.swapGB?.toFixed(1) ?? "?"} GB`);
84
+ if (before.freePercent != null || after.freePercent != null) memory.push(`free ${before.freePercent ?? "?"}% -> ${after.freePercent ?? "?"}%`);
47
85
 
48
86
  return [
49
- `pi-splash-server bench v${result.benchVersion} (pi-splash-server ${env.packageVersion})`,
50
- `Mac: ${mac.join(", ")}`, `Runtime: ${env.runtime} ${env.runtimeVersion ?? "unknown version"}`,
51
- `Model: ${env.model}, ${env.context.toLocaleString("en-US")} context`, `${env.flagsSource === "start" ? "Flags" : "Server process flags"}: ${env.flags === null ? "unavailable" : env.flags || "(none)"}`,
52
- "", "Median (min-max) across repeats.", "",
53
- "| test | tokens | TTFT s | prefill tok/s | decode tok/s | draft accepted % | cached |",
54
- "| --- | --- | --- | --- | --- | --- | --- |",
55
- ...Array.from(new Set(requests.map(r => r.test)), test => row(test, requests.filter(r => r.test === test))),
56
- "", ...[result.note, result.error && `Stopped: ${result.error}`].filter(Boolean), memory.join(" "),
87
+ `pi-splash-server ${env.packageVersion}, bench v${result.benchVersion}`,
88
+ ...header.map(([key, value]) => key.padEnd(width) + value),
89
+ "",
90
+ ...(tests.length ? align(tests, [1, 4]) : []),
91
+ "",
92
+ ...[result.note, result.error && `Stopped: ${result.error}`].filter(Boolean),
93
+ `${memory.length ? `Memory: ${memory.join(", ")}. ` : ""}Took ${Math.floor(seconds / 60)} min ${seconds % 60} s.`,
57
94
  ].join("\n");
58
95
  }
96
+
97
+ export const ISSUES_URL = "https://github.com/sady4850/pi-splash-server/issues/new";
98
+
99
+ export function shareUrl(result: BenchResult): string {
100
+ const { chip, memoryGB, model } = result.environment;
101
+ const params = new URLSearchParams({
102
+ template: "bench.yml",
103
+ title: `Bench: ${chip} ${memoryGB} GB, ${model.split("/").pop()}`,
104
+ report: benchReport(result),
105
+ });
106
+ return `${ISSUES_URL}?${params}`;
107
+ }