A chat client resends the whole conversation every turn, pictures included, and the vision encoder is the slow part
of a request: 6 s a screenshot on 16 CPU threads, 18 s on 6, every turn, while the engine reuses the prompt's KV
prefix in a fraction of a second. Upstream's Python server kept the encoder's output per picture in an LRU of 64
files keyed by the SHA-256 of the picture's bytes (serve/server.py, class Vision); this is that cache for the C++
front end, in memory.
frontend/picture_cache.hpp (header-only, no llama.cpp): PictureCache keeps PictureRows (the projector's output,
n_tok rows of the embedding width) under mtmd's chunk id, which is the SHA-256 of the bitmap's bytes. Shared
pointers, so a request keeps the rows it is writing when the cache lets go of them; two limits, entries and bytes,
the newest entry always kept. engine_key() turns the id into the 64-bit key the engine's conversation cache takes
(img_keys= on the GENI line, #2228), so a picture encoded again with other bits still matches its KV prefix.
encode_pictures is now six short functions: open the file, fill it, find the chunk, its id, its rows (cache or
encoder), its grid, write the record. --picture-cache N (default 64, 1 GiB) sets the size; 0 turns it off.
frontend/tests/picture_cache_test.cpp: hit/miss and counters, LRU order and the entry limit, the byte limit and the
oversize newest entry, a held entry outliving its eviction and a key replaced, off and an empty key, the engine
keys, eight threads at once. In make test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The rendered prompt was tokenized whole with specials parsed, so "<|image_pad|>" in a
document an agent read became the image pad token and the engine refused the request
("the prompt has more images than the embeddings file"); "<|im_end|>" in a tool
result ended a turn. Upstream's Python server marked these literals before the template
rendered (#537, #554); the C++ front end lost that with the server's removal.
frontend/literals.hpp: the texts of the vocabulary's control tokens and marker-like
added tokens (<think>, <tool_call>, [gMASK]) are swapped for private-use marks in the
messages and tools before oaicompat_chat_params_parse renders the template, swapped
back after, and the spans they covered are tokenized as text: parse_special off, and an
added token the tokenizer matches regardless is split until none is left. Media parts
are not scanned. An assistant message keeps a leading whole <think>...</think> block
as the model's markers (clients that send reasoning inline), as upstream did. A mark
that a template's tojson(ensure_ascii=True) escaped as a surrogate pair is read too.
A request without literals renders and tokenizes exactly as before.
mtmd's logger wrote every level to stderr, its debug line add_text() among them: the
whole rendered prompt once per request into the journal. It now goes through the
common log, where debug lines need the server's verbosity raised.
Tests: frontend/tests/literals_test.cpp (no model; nlohmann json, the interface
common_json copies) in make test; e2e.sh runs a third fake-engine server with upstream's
Qwen3 template (frontend/tests/data/qwen3-chat-template.jinja) and checks
usage.prompt_tokens against the prompt tokenized by hand with the literals as text, for
user content, a tool description and an assistant history message.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
tools/acceptance/: Dockerfile (pi 0.85.1 image), run-task.sh / run-all.sh / judge.sh / pretty.py, tasks md-toc,
kvstore, bugfix (seeded), minesweeper with hidden tests / black-box judges, models.tsv, README. Runs go to
runs/ (ignored); curated results land under bench/unbiased/ when the campaign closes.
frontend/tests/acceptance-real-engine.sh: PLAN.md step 13 (c): sampled checks, seeded repeat, tool call, decode and
prompt-reading speed against an expected figure with a 15 % band.
frontend/strata_context.cpp: the vocabulary-only load is retried with general.architecture overridden to "llama"
when llama.cpp does not know the file's architecture; GLM 5.3 Flash's file says glm5-next (neurall's fork) and
the front end refused to start (USTRAT-6). Verified on the 2x B200 pod: GLM starts, template renders, answers.
tools/pod/README.md: pod-to-pod tree copy (90 s against hours from the laptop), bringup must wait for the tree.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
An uncapped 1920x1080 screenshot is 2040 rows and took 146 s on the A6000 VM's
Ryzen 7 1700. Upstream's setup.py gave strata-vision --max-tokens 300 on the CPU
and 1024 on the GPU; the same defaults here, --image-max-tokens overrides. The
front end's ggml has no GPU backend (the engines bring their own CUDA), so
--mmproj-gpu now fails at start instead of running on the CPU under a GPU label.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The first picture on the A6000 VM (Ryzen 7 1700, 12 vCPUs, AVX2) took 146 s to
encode a 1920x1080 screenshot (2040 rows) on the CPU against 0.85 s of engine
time. The card had 29 GB free beside the engine. --mmproj-gpu (a front-end
option, not llama-server's, whose default is the GPU) puts the encoder there with
mtmd's warm-up so the work buffers exist before the first request.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
server-common replaces an image_url part by a marker that is random per process;
mtmd was left at its default marker, so the first picture request on the A6000
failed with 'number of media markers in text (0) does not match number of bitmaps
(1)'. Set mtmd's marker to get_media_marker(), as llama-server does.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
--mmproj FILE loads the model's vision projector with llama.cpp's mtmd in the server
process (CPU, --threads or half the cores; the card is the engine's), after checking
that the projector's output width (clip.vision.projection_dim) equals the model's
embedding width from the GGUF metadata and that the vocabulary has <|image_pad|>.
A request's image_url parts come through llama.cpp's own parser as media chunks;
launch() encodes each chunk, writes strata-vision records ('SVE1', rows, nx, ny,
width, float32 rows) to a per-request temp file removed with the slot, replaces the
chunk's placeholders by image_pad ids, and sends GENI <max_new> ... image_pad=<id>
<file> <ids>, which strata-poly (take_pictures) and strata read. Without --mmproj
the parser refuses images with llama.cpp's message; e2e.sh checks that.
Reference: upstream tools/vision/strata_vision.cpp (same records, a child process)
and UnbiasedStrata 1's frontend/vision.hpp. Qwen family only (the pad token);
tiled encoders (MiniCPM-V canvases) are refused. Gate on a real engine follows.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Upstream PolyStrata's server reports usage on every streamed reply, and its
tools/strata_bench.py reads prompt_tokens from it without sending
stream_options.include_usage. llama.cpp only adds the usage chunk on request,
so the fork's step-9 Flash-Next arm recorded prompt_tokens = null. Set
include_usage on every task result: the last chunk has usage, timings and an
empty choices array (OpenAI's documented shape).
e2e.sh: the health check from 453d3015 compared the json boolean to 'True'
instead of 'true'; the stream checks now skip the empty-choices chunk and
assert usage on it.
Verified: make test under sandbox-exec (engine_test 7 cases, e2e all checks).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Upstream's tools/strata_bench.py (is_strata, wait_ready) only talks to a server
whose /health has service == "strata" and loaded; the fork answered llama.cpp's
{status, busy} only, so the step-9 fork arms never left the readiness wait
(fork-flash-next on the pod sat ready for 30 min, then was killed as 'failed
to start'). Add service, loaded, model, max_context; keep status and busy.
e2e.sh checks the two required fields.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
frontend/strata_context.cpp replaces tools/server/server-context.cpp. The other seven server files
(server-http, -queue, -task, -common, -chat, -schema, -stream) compile unmodified from the submodule into
the static library strata_llama_server; frontend/ui_stub/ supplies the empty web-UI asset table that
server-http.cpp references. The context runs one slot: the engine is a child process spoken to over its
line protocol (docs/BACKENDS.md), a vocab-only llama_model provides tokenizing, the chat template and the
reasoning and tool-call parsers, and the server's own task and result types carry the OpenAI JSON, SSE
framing and client-disconnect cancel. Routes kept: /health, /v1/models, /v1/chat/completions, /tokenize,
/detokenize. The strata engine's 8-token reserve is kept out of max_new. A supervisor thread ends the
process with exit code 1 when the engine dies, for a unit with Restart=on-failure.
frontend/engine.hpp is the child adapter: fork+exec, READY/INFO, GEN/GENI, T/PP/RESUME/DONE/ERR/FATAL,
STOP with drain to DONE, non-blocking reap. quit() and the supervisor's reap_exit() share the pid through
an atomic that quit() takes over by exchange, and only a positive local copy ever reaches kill(). The
first draft kept a plain pid_t and the supervisor set it to -1 on reaping, so a SIGTERM during shutdown
raced into kill(-1, SIGKILL), which killed every process of the user; it did so twice on 2026-10-17.
Build: STRATA_FRONTEND (default on) gates the llama.cpp libraries and the front end, not CUDA, so they
build on a machine without a GPU. Makefile: unbiased-strata joins `make build`; `make frontend` builds it
alone without CUDA into build-frontend/; `make test` builds engine_test there and runs it and
frontend/tests/e2e.sh against a fake engine (frontend/tests/fake-engine.py). The nvcc probes run only
when there is an nvcc and only the build and configure goals demand one. UPSTREAM.md records all of it.
Verified on macOS arm64 without CUDA: `make frontend` and `make test` pass. engine_test, 7 cases: READY,
a request, STOP mid-request with drain and a clean next request, a 100k-token burst the caller abandons,
ERR leaves the adapter usable, the engine dying mid-request is diagnosed, a DONE with the wrong prompt
size is visible. e2e.sh, 12 checks: /health, /v1/models, a non-streaming chat with content, finish and
usage, a stream whose deltas join to the content and end with finish_reason and [DONE], a client that
disconnects mid-stream (the server logs the cancel and the next request completes), an oversize prompt
refused with 400, a tokenize/detokenize round trip. Zero new patch lines to llama.cpp, so the step-4
gate of PLAN.md section 5 passes and design C stands. Not yet run against a real engine.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>