offgrid-ai 0.16.3 → 0.17.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.
- package/README.md +0 -2
- package/package.json +3 -11
- package/src/cli.mjs +1 -4
- package/src/commands/main.mjs +23 -1
- package/src/commands/models.mjs +105 -32
- package/src/commands/run.mjs +1 -4
- package/src/config.mjs +16 -1
- package/src/model-name.mjs +2 -2
- package/src/model-presenters.mjs +4 -13
- package/src/profile-setup.mjs +206 -49
- package/src/ui.mjs +8 -8
- package/src/benchmark/finalize.mjs +0 -169
- package/src/benchmark/flow.mjs +0 -240
- package/src/benchmark/metrics.mjs +0 -107
- package/src/benchmark/prepare.mjs +0 -118
- package/src/benchmark/repo.mjs +0 -77
- package/src/benchmark/sdk-runner.mjs +0 -363
- package/src/benchmark/shared.mjs +0 -46
- package/src/benchmark.mjs +0 -12
- package/src/commands/benchmark.mjs +0 -4
package/src/benchmark/flow.mjs
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// ── Benchmark command flows ───────────────────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { ensureDirs } from "../config.mjs";
|
|
5
|
-
import { backendFor } from "../backends.mjs";
|
|
6
|
-
import { serverReady, startServer, waitForReady, stopProfile, modelAvailableOnServer, unloadModelFromServer } from "../process.mjs";
|
|
7
|
-
import { loadProfiles } from "../profiles.mjs";
|
|
8
|
-
import { pc, createPrompt } from "../ui.mjs";
|
|
9
|
-
import { linkBenchmarkRepo } from "./repo.mjs";
|
|
10
|
-
import { loadBenchmarks } from "./shared.mjs";
|
|
11
|
-
import { prepareBenchmarkRun } from "./prepare.mjs";
|
|
12
|
-
import { runBenchmarkInPi } from "./sdk-runner.mjs";
|
|
13
|
-
import { queryServerMetrics } from "./metrics.mjs";
|
|
14
|
-
import { finalizeBenchmarkRun, renderBenchmarkSummary } from "./finalize.mjs";
|
|
15
|
-
|
|
16
|
-
function benchmarkModelSource(profile) {
|
|
17
|
-
if (!profile) return "cloud";
|
|
18
|
-
return profile.backend === "omlx" ? "omlx" : "llama-cpp";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function chooseBenchmarkAction(prompt, canRun) {
|
|
22
|
-
const choices = [
|
|
23
|
-
{ value: "run", label: "Run Benchmark", hint: "Automated with Pi" },
|
|
24
|
-
{ value: "prepare", label: "Prepare Benchmark (manual)", hint: "Copy prompt and run yourself" },
|
|
25
|
-
];
|
|
26
|
-
return await prompt.choice("Action", canRun ? choices : choices.filter((c) => c.value === "prepare"), canRun ? "run" : "prepare");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function managedModelId(profile) {
|
|
30
|
-
return profile.omlxModel ?? profile.modelAlias ?? profile.label;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function ensureManagedModelAvailableForBenchmark(profile, backend) {
|
|
34
|
-
if (backend.type !== "managed-server") return;
|
|
35
|
-
if (await modelAvailableOnServer(profile)) return;
|
|
36
|
-
throw new Error(`${managedModelId(profile)} is not available on ${backend.label} at ${profile.baseUrl}.`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function ensureServerForBenchmark(profile) {
|
|
40
|
-
const backend = backendFor(profile.backend);
|
|
41
|
-
if (await serverReady(profile.baseUrl)) {
|
|
42
|
-
await ensureManagedModelAvailableForBenchmark(profile, backend);
|
|
43
|
-
console.log(pc.green(`[ready] ${backend.label} at ${profile.baseUrl}`));
|
|
44
|
-
return { started: false };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (backend.type === "managed-server") {
|
|
48
|
-
throw new Error(`${backend.label} is not running at ${profile.baseUrl}. Start it and try again.`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(pc.dim(`Starting ${backend.label} for ${profile.label}...`));
|
|
52
|
-
const state = await startServer(profile);
|
|
53
|
-
await waitForReady(profile, state?.pid, state?.rawLogPath);
|
|
54
|
-
console.log(pc.green(`[ready] ${profile.baseUrl}/models`));
|
|
55
|
-
return { started: true, state };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function runPreparedBenchmark(profile, runDirectory, options = {}) {
|
|
59
|
-
const controller = new AbortController();
|
|
60
|
-
if (options.signal) {
|
|
61
|
-
options.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
62
|
-
}
|
|
63
|
-
let serverStarted = false;
|
|
64
|
-
let benchmarkStarted = false;
|
|
65
|
-
let metadata;
|
|
66
|
-
|
|
67
|
-
const onSigint = () => {
|
|
68
|
-
controller.abort();
|
|
69
|
-
};
|
|
70
|
-
process.on("SIGINT", onSigint);
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const serverState = await ensureServerForBenchmark(profile);
|
|
74
|
-
serverStarted = serverState.started;
|
|
75
|
-
|
|
76
|
-
benchmarkStarted = true;
|
|
77
|
-
const runResult = await runBenchmarkInPi(profile, runDirectory, { signal: controller.signal });
|
|
78
|
-
|
|
79
|
-
let speedMetrics = null;
|
|
80
|
-
let speedMetricsError = null;
|
|
81
|
-
if (!runResult.error) {
|
|
82
|
-
try {
|
|
83
|
-
speedMetrics = await queryServerMetrics(profile);
|
|
84
|
-
} catch (err) {
|
|
85
|
-
// Non-fatal: speed metrics are a supplementary measurement, not the
|
|
86
|
-
// benchmark itself. Don't poison the run result; surface it as a note.
|
|
87
|
-
speedMetricsError = err.message;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
metadata = await finalizeBenchmarkRun(runDirectory, runResult, speedMetrics, speedMetricsError);
|
|
92
|
-
renderBenchmarkSummary(metadata);
|
|
93
|
-
} catch (err) {
|
|
94
|
-
const failedResult = {
|
|
95
|
-
error: { message: err.message },
|
|
96
|
-
wallClockMs: null,
|
|
97
|
-
agentTurns: 0,
|
|
98
|
-
promptTokens: 0,
|
|
99
|
-
completionTokens: 0,
|
|
100
|
-
totalTokens: 0,
|
|
101
|
-
cacheRead: 0,
|
|
102
|
-
cacheWrite: 0,
|
|
103
|
-
toolCalls: 0,
|
|
104
|
-
toolResults: 0,
|
|
105
|
-
perTurn: [],
|
|
106
|
-
};
|
|
107
|
-
metadata = await finalizeBenchmarkRun(runDirectory, failedResult, null);
|
|
108
|
-
renderBenchmarkSummary(metadata);
|
|
109
|
-
} finally {
|
|
110
|
-
process.removeListener("SIGINT", onSigint);
|
|
111
|
-
if (serverStarted && !options.keepServer) {
|
|
112
|
-
const backend = backendFor(profile.backend);
|
|
113
|
-
if (backend.type !== "managed-server") {
|
|
114
|
-
const result = await stopProfile(profile);
|
|
115
|
-
console.log(result.stopped ? pc.green(`[stop] ${result.message}`) : pc.dim(`[stop] ${result.message}`));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (benchmarkStarted) {
|
|
119
|
-
const unloadResult = await unloadModelFromServer(profile);
|
|
120
|
-
if (!unloadResult.unloaded && unloadResult.error) {
|
|
121
|
-
console.log(pc.yellow(`[unload] ${unloadResult.backend}: ${unloadResult.error}`));
|
|
122
|
-
} else if (!unloadResult.unloaded && unloadResult.reason) {
|
|
123
|
-
console.log(pc.dim(`[unload] ${unloadResult.backend}: ${unloadResult.reason}`));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return metadata;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ── Shared benchmark selection ────────────────────────────────────────────
|
|
132
|
-
|
|
133
|
-
async function selectBenchmark(prompt, repoPath) {
|
|
134
|
-
const kind = await prompt.choice("Benchmark category", [
|
|
135
|
-
{ value: "visual", label: "Visual Benchmark", hint: "HTML/CSS/JS animation benchmarks" },
|
|
136
|
-
{ value: "data-science", label: "Data Science", hint: "Analysis and charting benchmarks" },
|
|
137
|
-
], "visual");
|
|
138
|
-
|
|
139
|
-
const benchDir = join(repoPath, "benchmarks");
|
|
140
|
-
const benchmarks = (await loadBenchmarks(benchDir)).filter((b) => b.kind === kind);
|
|
141
|
-
if (benchmarks.length === 0) {
|
|
142
|
-
console.log(pc.yellow(`No ${kind} benchmarks found in ${benchDir}`));
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
const benchmarkId = await prompt.choice("Prompt", benchmarks.map((b) => ({
|
|
146
|
-
value: b.id, label: b.title, hint: b.description || b.id,
|
|
147
|
-
})), benchmarks[0].id);
|
|
148
|
-
const benchmark = benchmarks.find((b) => b.id === benchmarkId);
|
|
149
|
-
if (!benchmark) return null;
|
|
150
|
-
return { kind, benchmark };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ── Shared benchmark setup ───────────────────────────────────────────────
|
|
154
|
-
|
|
155
|
-
async function benchmarkSetup() {
|
|
156
|
-
await ensureDirs();
|
|
157
|
-
const prompt = createPrompt();
|
|
158
|
-
const repoPath = await linkBenchmarkRepo(prompt);
|
|
159
|
-
if (!repoPath) return { prompt, repoPath: null, selected: null };
|
|
160
|
-
const selected = await selectBenchmark(prompt, repoPath);
|
|
161
|
-
return { prompt, repoPath, selected };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// ── Benchmark from a selected profile (from model picker) ────────────────
|
|
165
|
-
|
|
166
|
-
export async function benchmarkForProfile(profile) {
|
|
167
|
-
const { prompt, repoPath, selected } = await benchmarkSetup();
|
|
168
|
-
try {
|
|
169
|
-
if (!selected) return;
|
|
170
|
-
const { kind, benchmark: selectedBenchmark } = selected;
|
|
171
|
-
|
|
172
|
-
const modelId = profile.modelAlias;
|
|
173
|
-
const modelSource = benchmarkModelSource(profile);
|
|
174
|
-
const backendLabel = backendFor(profile.backend).label;
|
|
175
|
-
|
|
176
|
-
const canRun = modelSource !== "cloud";
|
|
177
|
-
const action = await chooseBenchmarkAction(prompt, canRun);
|
|
178
|
-
|
|
179
|
-
const runDirectory = await prepareBenchmarkRun({ repoPath, benchmark: selectedBenchmark, kind, modelId, modelSource, backendLabel, profile, showNextSteps: action === "prepare" });
|
|
180
|
-
|
|
181
|
-
if (action === "run") {
|
|
182
|
-
return await runPreparedBenchmark(profile, runDirectory);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return runDirectory;
|
|
186
|
-
} finally {
|
|
187
|
-
prompt.close();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// ── Standalone benchmark flow (offgrid-ai benchmark) ──────────────────────
|
|
192
|
-
|
|
193
|
-
export async function benchmarkFlow() {
|
|
194
|
-
const { prompt, repoPath, selected } = await benchmarkSetup();
|
|
195
|
-
try {
|
|
196
|
-
if (!selected) return;
|
|
197
|
-
const { kind, benchmark: selectedBenchmark } = selected;
|
|
198
|
-
|
|
199
|
-
const profiles = await loadProfiles();
|
|
200
|
-
const source = await prompt.choice("Model source", [
|
|
201
|
-
{ value: "profile", label: "Use existing profile", hint: "Pick a saved offgrid-ai profile" },
|
|
202
|
-
{ value: "cloud", label: "Custom / cloud", hint: "Free-form model label for cloud runs" },
|
|
203
|
-
], "profile");
|
|
204
|
-
|
|
205
|
-
let modelId, modelSource, backendLabel, profile;
|
|
206
|
-
|
|
207
|
-
if (source === "profile") {
|
|
208
|
-
if (profiles.length === 0) {
|
|
209
|
-
console.log(pc.yellow("No profiles yet. Run: offgrid-ai models"));
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const profileId = await prompt.choice("Profile", profiles.map((p) => ({
|
|
213
|
-
value: p.id, label: p.label, hint: `${backendFor(p.backend).label} · ${p.modelAlias}`,
|
|
214
|
-
})), profiles[0].id);
|
|
215
|
-
profile = profiles.find((p) => p.id === profileId);
|
|
216
|
-
if (!profile) return;
|
|
217
|
-
modelId = profile.modelAlias;
|
|
218
|
-
modelSource = benchmarkModelSource(profile);
|
|
219
|
-
backendLabel = backendFor(profile.backend).label;
|
|
220
|
-
} else {
|
|
221
|
-
backendLabel = await prompt.text("Backend label", "cloud");
|
|
222
|
-
modelId = await prompt.text("Model name", "");
|
|
223
|
-
if (!modelId) { console.log(pc.yellow("Model name is required.")); return; }
|
|
224
|
-
modelSource = "cloud";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const canRun = modelSource !== "cloud" && profile != null;
|
|
228
|
-
const action = await chooseBenchmarkAction(prompt, canRun);
|
|
229
|
-
|
|
230
|
-
const runDirectory = await prepareBenchmarkRun({ repoPath, benchmark: selectedBenchmark, kind, modelId, modelSource, backendLabel, profile, showNextSteps: action === "prepare" });
|
|
231
|
-
|
|
232
|
-
if (action === "run" && profile) {
|
|
233
|
-
return await runPreparedBenchmark(profile, runDirectory);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return runDirectory;
|
|
237
|
-
} finally {
|
|
238
|
-
prompt.close();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// ── Backend-aware server speed metrics ───────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
import { backendFor } from "../backends.mjs";
|
|
4
|
-
|
|
5
|
-
const BENCH_SPEED_PROMPT = "Write a one-sentence summary of machine learning.";
|
|
6
|
-
const SPEED_QUERY_TIMEOUT_MS = 120_000;
|
|
7
|
-
const SPEED_QUERY_MAX_TOKENS = 64;
|
|
8
|
-
|
|
9
|
-
export async function queryServerMetrics(profile) {
|
|
10
|
-
const backend = backendFor(profile.backend);
|
|
11
|
-
|
|
12
|
-
if (backend.id === "llama-cpp") {
|
|
13
|
-
return await queryLlamaCppMetrics(profile);
|
|
14
|
-
}
|
|
15
|
-
if (backend.id === "omlx") {
|
|
16
|
-
return await queryOmlxMetrics(profile);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
throw new Error(`Unsupported backend for benchmark speed metrics: ${backend.id}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function speedQueryFetch(profile, { stream = false, streamOptions = null, errorLabel = "speed query" } = {}) {
|
|
23
|
-
const body = {
|
|
24
|
-
model: profile.modelAlias,
|
|
25
|
-
messages: [{ role: "user", content: BENCH_SPEED_PROMPT }],
|
|
26
|
-
stream,
|
|
27
|
-
max_tokens: SPEED_QUERY_MAX_TOKENS,
|
|
28
|
-
...(streamOptions ? { stream_options: streamOptions } : {}),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const response = await fetch(profile.baseUrl.replace(/\/$/u, "") + "/chat/completions", {
|
|
32
|
-
method: "POST",
|
|
33
|
-
headers: { "Content-Type": "application/json" },
|
|
34
|
-
body: JSON.stringify(body),
|
|
35
|
-
signal: AbortSignal.timeout(SPEED_QUERY_TIMEOUT_MS),
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw new Error(`${errorLabel} failed: ${response.status} ${response.statusText}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function queryLlamaCppMetrics(profile) {
|
|
46
|
-
const response = await speedQueryFetch(profile, { errorLabel: "llama.cpp speed query" });
|
|
47
|
-
|
|
48
|
-
const data = await response.json();
|
|
49
|
-
const timings = data.timings;
|
|
50
|
-
if (!timings || typeof timings.prompt_per_second !== "number" || typeof timings.predicted_per_second !== "number") {
|
|
51
|
-
throw new Error("llama.cpp response did not include usable timings object");
|
|
52
|
-
}
|
|
53
|
-
const draftN = timings.draft_n;
|
|
54
|
-
const draftAccepted = timings.draft_n_accepted;
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
prefillTokensPerSecond: timings.prompt_per_second ?? null,
|
|
58
|
-
generationTokensPerSecond: timings.predicted_per_second ?? null,
|
|
59
|
-
ttftMs: timings.prompt_ms ?? null,
|
|
60
|
-
modelLoadMs: null,
|
|
61
|
-
speculativeDecodeAcceptance: (draftN && Number.isFinite(draftAccepted) && Number.isFinite(draftN) && draftN > 0)
|
|
62
|
-
? draftAccepted / draftN
|
|
63
|
-
: null,
|
|
64
|
-
kvCacheTokens: timings.cache_n ?? null,
|
|
65
|
-
metricSource: "llama.cpp /v1/chat/completions timings",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function queryOmlxMetrics(profile) {
|
|
70
|
-
const response = await speedQueryFetch(profile, {
|
|
71
|
-
stream: true,
|
|
72
|
-
streamOptions: { include_usage: true },
|
|
73
|
-
errorLabel: "oMLX speed query",
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const text = await response.text();
|
|
77
|
-
let usage = null;
|
|
78
|
-
for (const line of text.split("\n").reverse()) {
|
|
79
|
-
const trimmed = line.trim();
|
|
80
|
-
if (!trimmed || !trimmed.startsWith("data:")) continue;
|
|
81
|
-
const payload = trimmed.slice(5).trim();
|
|
82
|
-
if (payload === "[DONE]") continue;
|
|
83
|
-
try {
|
|
84
|
-
const chunk = JSON.parse(payload);
|
|
85
|
-
if (chunk.usage) {
|
|
86
|
-
usage = chunk.usage;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
// Ignore malformed SSE chunks.
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!usage) {
|
|
95
|
-
throw new Error("oMLX speed query did not return usage in streaming response");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
prefillTokensPerSecond: usage.prompt_tokens_per_second ?? null,
|
|
100
|
-
generationTokensPerSecond: usage.generation_tokens_per_second ?? null,
|
|
101
|
-
ttftMs: usage.time_to_first_token != null ? usage.time_to_first_token * 1000 : null,
|
|
102
|
-
modelLoadMs: null,
|
|
103
|
-
speculativeDecodeAcceptance: null,
|
|
104
|
-
kvCacheTokens: usage.prompt_tokens_details?.cached_tokens ?? null,
|
|
105
|
-
metricSource: "oMLX /v1/chat/completions streaming include_usage",
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// ── Create a benchmark run directory ────────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { pc, renderRows, renderSection } from "../ui.mjs";
|
|
6
|
-
import { slugModelId, createRunId } from "./shared.mjs";
|
|
7
|
-
import { parseModelName } from "../model-name.mjs";
|
|
8
|
-
|
|
9
|
-
function harnessDisplayName(id) {
|
|
10
|
-
if (id === "pi") return "Pi";
|
|
11
|
-
return String(id).replace(/[-_]+/gu, " ").replace(/\b\w/gu, (char) => char.toUpperCase());
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function intendedRunnerForProfile(profile) {
|
|
15
|
-
if (!profile) return "your tool";
|
|
16
|
-
const harnessEntries = Object.entries(profile.harnesses ?? {}).filter(([, config]) => config?.enabled !== false);
|
|
17
|
-
const [id] = harnessEntries.find(([key]) => key === "pi") ?? harnessEntries[0] ?? ["pi"];
|
|
18
|
-
return harnessDisplayName(id);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function printBenchmarkNextSteps({ repoPath, runDirectory, profile, modelId, runnerLabel }) {
|
|
22
|
-
const runCommand = profile ? `offgrid-ai run ${profile.id}` : null;
|
|
23
|
-
const runnerCommand = runCommand ?? `Open ${runnerLabel} for ${modelId}`;
|
|
24
|
-
|
|
25
|
-
console.log("");
|
|
26
|
-
console.log(pc.bold("Next steps"));
|
|
27
|
-
console.log(` 1. Open the gallery. If it is not running: ${pc.cyan(`cd ${repoPath} && npm run dev`)}`);
|
|
28
|
-
console.log(` 2. ${pc.cyan(`cd ${runDirectory}`)}`);
|
|
29
|
-
console.log(` 3. ${pc.cyan(runnerCommand)}, then copy this run's prompt from the gallery and paste it into ${runnerLabel}`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function prepareBenchmarkRun({ repoPath, benchmark, kind, modelId, modelSource, backendLabel, profile, showNextSteps = true }) {
|
|
33
|
-
const toolPrompt = benchmark.prompt;
|
|
34
|
-
const now = new Date();
|
|
35
|
-
const runId = createRunId(now);
|
|
36
|
-
const modelSlug = slugModelId(modelId);
|
|
37
|
-
const runnerLabel = intendedRunnerForProfile(profile);
|
|
38
|
-
const runsDir = join(repoPath, "runs");
|
|
39
|
-
const benchmarkDirectory = join(runsDir, benchmark.id);
|
|
40
|
-
const modelDirectory = join(benchmarkDirectory, modelSlug);
|
|
41
|
-
const runDirectory = join(modelDirectory, runId);
|
|
42
|
-
|
|
43
|
-
await mkdir(runDirectory, { recursive: true });
|
|
44
|
-
|
|
45
|
-
const isDs = kind === "data-science";
|
|
46
|
-
const baseAssets = {
|
|
47
|
-
metadata: "metadata.json",
|
|
48
|
-
prompt: "prompt.md",
|
|
49
|
-
};
|
|
50
|
-
const metadata = {
|
|
51
|
-
schemaVersion: 1,
|
|
52
|
-
kind,
|
|
53
|
-
runId,
|
|
54
|
-
benchmark: { id: benchmark.id, title: benchmark.title, description: benchmark.description, prompt: benchmark.prompt },
|
|
55
|
-
model: { id: modelId, slug: modelSlug, displayName: parseModelName(modelId, modelSource === "omlx" ? "omlx" : "local-gguf").display },
|
|
56
|
-
status: "prepared",
|
|
57
|
-
createdAt: now.toISOString(),
|
|
58
|
-
updatedAt: now.toISOString(),
|
|
59
|
-
preparedAt: now.toISOString(),
|
|
60
|
-
runDirectory,
|
|
61
|
-
assets: isDs
|
|
62
|
-
? { ...baseAssets, ds: { notebook: "analysis.ipynb", summary: "summary.json", chartDistribution: "chart-distribution.png", chartTreatmentEffect: "chart-treatment-effect.png", chartCompletionRates: "chart-completion-rates.png" } }
|
|
63
|
-
: { ...baseAssets, html: "index.html", preview: "preview.png", video: "preview.webm" },
|
|
64
|
-
runner: {
|
|
65
|
-
mode: modelSource === "cloud" ? "manual" : "external",
|
|
66
|
-
intendedRunner: profile ? runnerLabel : undefined,
|
|
67
|
-
...(profile?.harnesses?.pi || runnerLabel === "Pi" ? { tool: "pi" } : {}),
|
|
68
|
-
...(modelSource ? { modelSource } : {}),
|
|
69
|
-
...(backendLabel ? { backendLabel } : {}),
|
|
70
|
-
...(profile?.baseUrl ? { baseUrl: profile.baseUrl } : {}),
|
|
71
|
-
model: modelId,
|
|
72
|
-
retries: 0,
|
|
73
|
-
tokenMetrics: {
|
|
74
|
-
reported: false,
|
|
75
|
-
promptTokens: 0,
|
|
76
|
-
completionTokens: 0,
|
|
77
|
-
totalTokens: 0,
|
|
78
|
-
},
|
|
79
|
-
speedMetrics: {
|
|
80
|
-
prefillTokensPerSecond: null,
|
|
81
|
-
generationTokensPerSecond: null,
|
|
82
|
-
ttftMs: null,
|
|
83
|
-
modelLoadMs: null,
|
|
84
|
-
speculativeDecodeAcceptance: null,
|
|
85
|
-
kvCacheTokens: null,
|
|
86
|
-
},
|
|
87
|
-
metricSource: null,
|
|
88
|
-
},
|
|
89
|
-
results: {
|
|
90
|
-
wallClockMs: null,
|
|
91
|
-
agentTurns: 0,
|
|
92
|
-
toolCalls: 0,
|
|
93
|
-
toolResults: 0,
|
|
94
|
-
success: false,
|
|
95
|
-
outputFiles: [],
|
|
96
|
-
perTurn: [],
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
await writeFile(join(runDirectory, "metadata.json"), JSON.stringify(metadata, null, 2) + "\n", "utf8");
|
|
101
|
-
await writeFile(join(runDirectory, "prompt.md"), toolPrompt + "\n", "utf8");
|
|
102
|
-
|
|
103
|
-
console.log("");
|
|
104
|
-
console.log(pc.green("✓ Run slot prepared"));
|
|
105
|
-
console.log(renderSection("Run", renderRows([
|
|
106
|
-
["Directory", pc.cyan(runDirectory)],
|
|
107
|
-
["Benchmark", benchmark.title],
|
|
108
|
-
["Kind", kind],
|
|
109
|
-
["Model", pc.bold(modelId)],
|
|
110
|
-
["Source", backendLabel || modelSource],
|
|
111
|
-
])));
|
|
112
|
-
|
|
113
|
-
if (showNextSteps) {
|
|
114
|
-
printBenchmarkNextSteps({ repoPath, runDirectory, profile, modelId, runnerLabel });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return runDirectory;
|
|
118
|
-
}
|
package/src/benchmark/repo.mjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// ── Benchmark repo linking ────────────────────────────────────────────────────
|
|
2
|
-
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
5
|
-
import { homedir } from "node:os";
|
|
6
|
-
import { execFile } from "node:child_process";
|
|
7
|
-
import { promisify } from "node:util";
|
|
8
|
-
import { loadConfig, saveConfig } from "../config.mjs";
|
|
9
|
-
import { pc } from "../ui.mjs";
|
|
10
|
-
|
|
11
|
-
const execFileAsync = promisify(execFile);
|
|
12
|
-
|
|
13
|
-
const BENCHMARK_REPO = "https://github.com/eeshansrivastava89/local-llm-visual-benchmark.git";
|
|
14
|
-
|
|
15
|
-
export async function findBenchmarkRepo() {
|
|
16
|
-
const config = await loadConfig();
|
|
17
|
-
if (config.benchmarkRepoPath && existsSync(join(config.benchmarkRepoPath, "benchmarks"))) {
|
|
18
|
-
return config.benchmarkRepoPath;
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function linkBenchmarkRepo(prompt) {
|
|
24
|
-
const existing = await findBenchmarkRepo();
|
|
25
|
-
if (existing) return existing;
|
|
26
|
-
|
|
27
|
-
const candidates = [
|
|
28
|
-
join(homedir(), "dev", "local-llm-visual-benchmark"),
|
|
29
|
-
join(homedir(), "projects", "local-llm-visual-benchmark"),
|
|
30
|
-
join(homedir(), "local-llm-visual-benchmark"),
|
|
31
|
-
];
|
|
32
|
-
for (const candidate of candidates) {
|
|
33
|
-
if (existsSync(join(candidate, "benchmarks"))) {
|
|
34
|
-
const config = await loadConfig();
|
|
35
|
-
config.benchmarkRepoPath = candidate;
|
|
36
|
-
await saveConfig(config);
|
|
37
|
-
return candidate;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log(pc.dim("\nThe benchmark gallery needs to be linked to offgrid-ai."));
|
|
42
|
-
console.log(pc.dim("This is the local-llm-visual-benchmark repo that stores prompts and run results.\n"));
|
|
43
|
-
|
|
44
|
-
const choice = await prompt.choice("Link benchmark gallery", [
|
|
45
|
-
{ value: "clone", label: "Clone from GitHub", hint: "git clone into ~/dev" },
|
|
46
|
-
{ value: "manual", label: "Enter path manually", hint: "If you already have it cloned" },
|
|
47
|
-
], "clone");
|
|
48
|
-
|
|
49
|
-
if (choice === "clone") {
|
|
50
|
-
const targetDir = join(homedir(), "dev", "local-llm-visual-benchmark");
|
|
51
|
-
console.log(pc.dim(`\nCloning ${BENCHMARK_REPO}...`));
|
|
52
|
-
try {
|
|
53
|
-
await execFileAsync("git", ["clone", BENCHMARK_REPO, targetDir], { stdio: "pipe" });
|
|
54
|
-
const config = await loadConfig();
|
|
55
|
-
config.benchmarkRepoPath = targetDir;
|
|
56
|
-
await saveConfig(config);
|
|
57
|
-
console.log(pc.green(`✓ Cloned to ${targetDir}`));
|
|
58
|
-
return targetDir;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.log(pc.red(`Clone failed: ${err.message}`));
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const path = await prompt.text("Path to local-llm-visual-benchmark", "");
|
|
66
|
-
if (!path) return null;
|
|
67
|
-
const resolved = resolve(path.replace(/^~/, homedir()));
|
|
68
|
-
if (!existsSync(join(resolved, "benchmarks"))) {
|
|
69
|
-
console.log(pc.red(`No benchmarks/ directory found at ${resolved}`));
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const config = await loadConfig();
|
|
73
|
-
config.benchmarkRepoPath = resolved;
|
|
74
|
-
await saveConfig(config);
|
|
75
|
-
console.log(pc.green(`✓ Linked to ${resolved}`));
|
|
76
|
-
return resolved;
|
|
77
|
-
}
|