Commit Graph
6 Commits
Author SHA1 Message Date
Pavlo RatushnyiandClaude Sonnet 5.5 4725df5bdf feat: --cache-slots, one worker keeps the KV caches of several agents and picks the right one (STRA-220)
GptOssEngine holds up to N conversation caches (--cache-slots N on the four workers, default 1 =
unchanged). crates/cpu-worker/src/slots.rs chooses per prompt: continue in place a slot that is
wholly a prefix of the prompt (the same agent's next turn); otherwise take the slot sharing the
longest prefix as a donor and either continue it (losing its tail) or copy the shared part into
a new/empty/least recently used slot (State::copy_prefix_from), whichever discards fewer cached
tokens, so a new agent gets the shared system prompt without destroying another agent's cache.
Results are bit-identical to a fresh prefill (synthetic test: copied prefix continues bit for
bit, donor untouched).

Measured: CPU only, 3 agents, 36 requests: 1.37x/1.46x prompt time, outputs identical.
Through the control plane, 4 agents on one iGPU worker, 3 clean alternating pairs: 986/993/995 s
with 1 slot against 569/575/575 s with 4 slots (1.73x), answers identical in all six runs. The
first run of pair 1 was disturbed by the UTC date in the system prompt changing mid-run and was
repeated. Compare-ConcurrentEpisodes.ps1 takes -Agents, -SharedInstructionTokens and the
'slots' arm and records output hashes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-17 03:45:20 +02:00
Pavlo RatushnyiandClaude Opus 5.5 f3bc0ab695 feat: decode time breakdown in the speculation log; the serve loop has no hidden cost (STRA-220)
LELEKA_SPECULATION_LOG=1 now also prints, per request and with or without --speculate, where the decode time went:
passes by number of tokens (count and mean), sampling, output lines, drafting, cache cuts and the rest.

Measured with it (ab_speculation, 2 pairs, quiet machine, outputs identical in all 16 runs; paired speed-ups 1.55,
1.12, 1.01, 0.97): everything outside the model passes is under 0.5% of decode time (sampling 40-64 ms per request,
the rest a few ms), and single steps cost the same in both arms (81-93 ms). Verifying passes in the worker cost
1.57, 2.04, 2.50, 2.99, 3.66, 4.04, 4.32, 4.80 single steps for 2-9 tokens, 3% above batch_cost's random-id passes at
2-3 tokens and 8-22% above from 4 tokens on, which accounts for the rewrite's 1.55 against the replay's 1.59.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 13:40:35 +02:00
Pavlo RatushnyiandClaude Opus 5.5 b0f2b23d4e feat: exact prompt-lookup speculative decoding in the worker loop, cost-aware and off by default (STRA-220)
--speculate on leleka-cpu-worker, leleka-igpu-worker and leleka-npu-worker drafts from
prompt lookup, verifies the sampled token plus the draft in one batch
(Model::logits_after_each, bit-identical to one-at-a-time feeding), samples every
emitted token from the real logits and truncates rejected positions from the cache,
so output equals plain decoding. The drafter estimates acceptance per matched-context
length and drafts only the length whose expected tokens per pass beat the pass cost
(measured ratios, then observed pass times). Drafts are clipped to the output budget.
speculate::replay runs a policy over a recorded output without a model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 12:11:02 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 7a78e87ea8 feat: add leleka-igpu-worker, the CPU worker with GPU prefill for long prompts (STRA-219, phase D)
- cpu-worker: GptOssEngine can take a PrefillAccelerator (falls back to the CPU and drops it on failure)
- igpu-worker: separate executable, same protocol, --gpu-min-tokens/--gpu-batch; CPU-only with a message when
  no GPU is usable
- real-model worker tests no longer assert llama.cpp's later greedy tokens (near-ties that moved with the
  attention/KV/router changes of STRA-214; the first token and the reuse/determinism checks stay); the
  teacher-forced gate is the comparison with llama.cpp

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 00:21:20 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 4c00f0d209 feat: keep the gpt-oss KV cache in half precision (STRA-214)
Keys and values are stored as IEEE half floats (49 KB per token instead of 98 KB, llama.cpp's default
cache type). New cpu-sys kernels read them directly: attention scores and weighted value sums over half
floats (portable and AVX2 + FMA + F16C, blocked over positions like the f32 ones) and a vector
float-to-half conversion that is bit-identical to the portable one. The decoder writes rotated keys and
values through Dispatch::f32_to_f16; the synthetic f64 reference rounds K and V the same way.

Teacher-forced gate against llama.cpp (same 383 tokens): best token 97.4% (unchanged), mean KL 0.0077
(was 0.0082 with f32 cache), next-token NLL 1.2852 vs 1.2798. The conversions cost a little attention time
(2,000-token context, one noisy run: decode attention 9.9 ms against 7.7 ms with f32), which is the price
of halving the cache. The worker's default context rises to 32,768 tokens (1.6 GB).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 22:35:50 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 c2a2166fa5 feat: add the CPU worker that serves gpt-oss-20b over the control plane's line protocol (STRA-199, STRA-217)
New crate leleka-cpu-worker (executable leleka-cpu-worker --serve --model <gguf>): loads the GGUF through
the read-only mapping, runs the gpt-oss decoder on the AVX2 / AVX-VNNI kernels, and speaks the stdin/stdout
protocol of Strata's --serve mode (READY, GEN with temperature, top_p and seed, STOP, QUIT, PP, REUSED, T,
DONE, ERR). Prefix reuse across requests, cancellation between prefill chunks and between tokens, a stale
STOP while idle is ignored, the end-of-generation marker is emitted as the last token.

leleka-gptoss gains sampling (greedy, or temperature and top-p over the 1,024 best logits, with a seeded
generator) and prefill_reuse_with (progress and cancellation). A stray NUL byte left in a doc comment by an
earlier shell edit is removed.

Tests: protocol parsing, the request loop against a mock decoder (stop token, length, reuse, STOP, QUIT,
engine failure, broken pipe), and an end-to-end run on the real model (needs LELEKA_GPTOSS_GGUF) that gets
llama.cpp's 16 greedy tokens for "The capital of France is" and reuses the prefix of a longer prompt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 19:14:31 +02:00