Files
leleka/engine/strata/apps/host/tests/stream-speed.test.mjs
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

41 lines
2.2 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { proxyCompletion } from '../server/inference.mjs';
/* The speed shown while an answer streams must be the decode speed of everything generated, reasoning included, from the first
token (the owner saw 4-5 tok/s in chat while the engine log said 48-57): the stand-in engine streams 90 reasoning tokens at about
40 a second, a 4 s "prompt" before the first one, then a short answer. */
function engine({ promptMs, reasoning, answer, perSecond }) {
return createServer((req, res) => {
res.writeHead(200, { 'content-type': 'text/event-stream' });
const send = obj => res.write(`data: ${JSON.stringify(obj)}\n\n`);
let sent = 0;
setTimeout(function tick() {
if (sent < reasoning + answer) {
send({ choices: [{ delta: sent < reasoning ? { reasoning_content: 'tok ' } : { content: 'ans ' } }] });
sent++;
return setTimeout(tick, 1000 / perSecond);
}
send({ choices: [], usage: { prompt_tokens: 20, completion_tokens: reasoning + answer } });
res.write('data: [DONE]\n\n'); res.end();
}, promptMs);
});
}
test('live speed counts reasoning tokens over decode time, not the answer over the whole wait', async () => {
const server = engine({ promptMs: 4000, reasoning: 90, answer: 10, perSecond: 40 });
await new Promise(r => server.listen(0, '127.0.0.1', r));
const frames = [];
try {
const result = await proxyCompletion({ baseUrl: `http://127.0.0.1:${server.address().port}/v1`, message: 'hi', onFrame: f => frames.push(f), engine: { beginReading() {}, beginThinking() {}, beginGenerating() {} } });
const stats = frames.filter(f => f.type === 'stats');
assert.ok(stats.length >= 2, 'live frames while it streams');
const last = stats.at(-1);
assert.ok(last.tps > 22 && last.tps < 80, `live tok/s ${last.tps} is the decode rate, not tokens over the wait including the prompt (~14)`);
assert.ok(last.tokensOut >= 50, 'reasoning tokens are counted');
assert.equal(result.tokensOut, 100);
assert.ok(result.tps > 22 && result.tps < 80, `final tok/s ${result.tps}`);
} finally { server.close(); }
});