Skip to content

Latest commit

 

History

History
3567 lines (2822 loc) · 182 KB

argus-launch-plan.md

File metadata and controls

3567 lines (2822 loc) · 182 KB

Argus — launch plan

Created 2026-08-21. Revised 2026-08-21 after review — six changes, listed below. Argus is FFai's VLM component: image/video → language. It is a registered stub today (66 lines, returns NotImplemented). This is the plan to make it real.

Revision 1 — what changed and why. The first draft was thorough about the model and thin about the harness and the claim. Six changes:

# change where
1 Correction: the ffai-bench "vlm task slot" does not exist. Three doc comments and an unreachable!() guard. Moved from the reuse ledger to genuinely new, and into step 0a §1.3, §3.3, §4
2 VLMEvalKit is a reference ADAPTER inside ffai-bench, not a second harness — otherwise Argus's numbers never become ledger lines and cannot sit in the same README table as Mercury's §1.1(a), §1.3, §4 step 0
3 Two measurement arms. Arm 1 (VLMEvalKit) prices the model; Arm 2 (matched weights, independent CPU runtime) prices the port and feeds three of the four gates §1.3, §4 steps 0c/6, §5
4 Determinism promoted from ⚠ EXTEND to a v1 requirement — byte-stability is the one property every other FFai component holds, and Mercury TTS ships it as a competitive claim §2 Gate 2, §5
5 Step 7 has an unpriced prerequisite: sample_frames materialises a whole clip (10.4 GiB/min at 1080p) and no CLI verb drives it. Named as step 7-pre §3.3, §4
6 Smaller: Gate 3 folded into Gate 1.2 as column (e); step 0's reference model must be a Tier-3 candidate; MMVet cut from the core set explicitly; the C/C++ disclosure becomes a measured table + a pinned mistral.rs behind the seam §1.1(b), §1.2, §3.3, §5

Carmenta is the template and the warning. It reached 0.116 text on OmniDocBench by one discipline: the reference implementation's own evaluator is the only scoreboard, and our own metric lied to us for a year before we learned that (§8.173 — a scorer biased 2.8× in our favour produced four shipped mechanisms that were artifacts). Every number in this document that comes from a vendor's published table is a claim, not a measurement, until it is reproduced locally. They are marked as such.


0. What Argus is FOR — decided by measurement, not ambition

The §57 loss ledger attributed every point of Carmenta's remaining error from the evaluator's own per-block records. Two entries are VLM-shaped:

Carmenta's remaining loss share VLM-addressable?
inline-math blocks 36 % partly — the reference answer is a specialist formula model, not a general VLM
recognition substitutions 20 % yes — a language model repairs tne → the from context; a CTC head cannot
assembly/matcher, unread CJK, detection, harness 44 % no — pipeline work, already named and priced

So Argus has two distinct missions, and conflating them is the first way this goes wrong:

  • A — the product mission (the roadmap's Phase 4). "Describe this image / this video." Captioning, VQA, a chaptered timed track from a video. Nothing else in the toolkit does this: Carmenta reads text that exists in an image and correctly returns nothing for a photo of a dog; Diana returns boxes and labels, not description. This is what completes FFai's pitch.
  • B — the repair mission. A VLM tier that rescoring Carmenta's output could attack ~20 % of its remaining loss.

Mission A is the one to build. Mission B is a hypothesis until a probe prices it (§4, gate B1) — and Carmenta's cheaper, named pipeline levers (server-tier recognizer, vertical CJK, matcher alignment) come first regardless. Do not justify Argus by mission B without that probe.


1. The champions, the corpus, and the scoreboard

1.1 The scoreboard: VLMEvalKit is our OmniDocBench

The direct analog exists and it is the right one to adopt: VLMEvalKit (OpenCompass) — one-command evaluation, 220+ models and 80+ benchmarks implemented, and it is the harness that produces the public OpenVLM Leaderboard. Same shape as omnidocbench-eval: their code, their prompts, their metrics, their answer extraction.

This matters more than the model choice. VLM benchmarks are mostly multiple-choice or short-answer, which means answer extraction — parsing "B" or "the third one" out of free text — is part of the metric. Every implementation does it differently, and a home-grown extractor is exactly the 2.8×-biased scorer again. Run their harness or the number is fiction.

The OpenVLM core leaderboard is eight benchmarks, and it is a good spine:

benchmark what it measures why it's in the core set
MMBench v1.1 all-round capability, EN + CN CircularEval — rotates answer order to kill position bias
MMStar vision-dependent questions curated to remove items answerable without the image
MMMU college-level, 30 subjects the "MMLU of VLMs" — reasoning, not perception
MathVista visual math the closest general benchmark to our math gap
HallusionBench hallucination & illusion the failure mode a small VLM has most of
AI2D diagram understanding structured-image reasoning
OCRBench text in images, 0–1000 our home turf — Carmenta's strength should show here
MMVet integrated capability ❌ CUT from FFai's core set — decided, not deferred. GPT-judged: it costs API calls, it is not reproducible offline, and its score moves when someone else's judge model changes. "Reproducible offline" is a house property, so a benchmark that cannot be is not allowed into the spine where it will be quoted later. Run it ad hoc if a comparison demands it; never in a ledger row.

Add for FFai specifically, beyond the core eight:

benchmark why we need it
DocVQA (ANLS) document VQA — the Carmenta↔Argus overlap, and mission B's proving ground
ChartQA, InfoVQA structured visuals; where OCR + reasoning must combine
TextVQA scene text — Carmenta's photo front, asked as a question
OCRBench v2 the expanded OCR suite (site)
Video-MME / MVBench video understanding — describe_video has no other gate
COCO Captions (CIDEr) plain captioning; the one metric that is purely generative

Gate 1.1 — stand up the harness FIRST, and score a REFERENCE model through it before Argus produces a single token. Carmenta's §32 lesson: we scored the reference implementation under our own harness and found the "residual gap" was the harness. If VLMEvalKit + a known model does not reproduce that model's published row, the harness is wrong and every Argus number after it would be wrong too.

Two clauses were added after review, and both change what step 0 costs.

(a) VLMEvalKit is a REFERENCE ADAPTER inside ffai-bench, not a second harness. Every claim Mercury, Carmenta and Diana make traces to a line in bench/ledger.jsonl carrying a four-gate verdict. A VLMEvalKit row that never becomes a ledger line lives in a different universe from every other FFai number and cannot go in the same README table. ReferenceSpec already has a batch_command + JSONL-on-stdout contract built for exactly this shape — so the integration is an adapter, and step 0 must deliver run_vlm + the VLM gate as well as the Python harness. See §1.3.

(b) The reference model scored at this gate MUST be one of the Tier-3 candidates (§1.2), not an arbitrary well-known model. One setup then has three uses: it validates the harness, it produces the chosen model's own baseline row (the number Argus must reproduce), and it becomes the runtime that step 3 oracle-matches the vision tower against. Scoring a model we will never port throws two of those away.

1.2 The champions — two tiers, and only one of them is a target

⚠ All figures below are vendor/leaderboard CLAIMS gathered 2026-08-21 and must be re-pinned at build time. They set direction, not targets.

Tier 1 — the frontier (the bar, not the goal). GPT-5-class, Gemini 3, Claude Opus 4.x. Closed, enormous, API-only. Argus will not beat these and should never claim to. They are the "PaddleOCR-VL" of this campaign: the number you cite to be honest about where you stand.

Tier 2 — open weights (the real competitive field).

model claimed MMMU claimed OCRBench note
Llama 4 Maverick ~73.4 — leaderboard leader among open weights
Qwen2.5-VL-72B ~70.2 ~888 strongest OCR of the open tier
InternVL3-78B ~72.2 — strongest MIT-licensed
InternVL3.5-8B ~73.4 ~840 ⚠ 8B claiming 78B-class MMMU — verify before believing

Tier 3 — the portable tier, and this is where Argus actually lives. FFai is CPU-first, pure Rust, no CUDA requirement. A 72B model is not a candidate; a 256M–4B model is.

model size claimed scores why it's a candidate
SmolVLM2 256M / 500M / 2.2B 256M: OCRBench 52.6, DocVQA 58.3, ChartQA 55.6 ❌ CORRECTED — see §8. Those figures are SmolVLM v1's, from v1's model card; SmolVLM2 publishes no OCRBench row anywhere. And SmolVLM2 is the one candidate mistral.rs cannot load.
SmolVLM v1 ✅ 256M / 500M / 2.2B 256M: OCRBench 52.6, DocVQA 58.3, ChartQA 55.8, MMStar 34.6, MMMU 28.3 — published, on its own card THE GATE-1.2 PICK. Wins every triage column: SigLIP tower (candle has it), pixel-shuffle connector, Llama decoder (candle has it), and mistral.rs serves it via Idefics3. Apache-2.0; 513 MB of weights against SmolVLM2's 1026 MB.
Qwen2.5-VL-3B / Qwen3-VL-2B 2–3B strong OCR lineage shares the family whose OCR we already trust (PP-OCRv5 ≠ Qwen, but the VL line is OCR-heavy)
InternVL3.5-2B 2B family claims strong small-tier MIT
Moondream ~1.8B runs in 2 GB built for tiny deployment

Gate 1.2 — the port-cost triage. This is ONE table with FIVE columns, and column (e) is the old "Gate 3" folded in — it was a sibling step in the first draft, which invited doing the (a)–(d) port-cost work on a model mistral.rs would simply have run for us. They are five columns of one decision, so they get filled in together:

col question why it decides
(a) is the vision tower a plain ViT/SigLIP we can express in candle, or something exotic? carmenta::svtr is the precedent; exotic = no precedent
(b) is the connector an MLP (easy) or a Q-Former/perceiver resampler (harder)? the MLP variant is ~50 lines; a resampler is a project
(c) is the LLM a Llama/Qwen-shaped decoder candle already has reference implementations for? decides whether §3.2–§3.4 is a port or a write
(d) is dynamic-resolution tiling required for its claimed scores? if yes, the tiling brick (§3.3) is not optional and the row without it is fiction
(e) does mistral.rs already serve this VLM? if yes, most of §3.2–§3.4 is already written by someone else and Argus becomes preprocess → call the engine → assemble. Porting a decoder we could have called is the most expensive possible mistake in this plan

Pick the model whose architecture is the cheapest honest port, not the one with the best row. That is exactly how mobiledet-svtr was chosen over a 3B VLM and it is why Carmenta shipped. A candidate that wins on (e) alone is still a valid pick — and a candidate cheap on (a)–(d) but unsupported by mistral.rs is not disqualified, it is just priced honestly against the one that is.

1.3 The corpus discipline, and the TWO measurement arms

Correction to the first draft, which claimed the harness slot already existed. It does not. corpus.rs:70, reference.rs:37 and ledger.rs:142 are doc comments on String fields that happen to list "vlm" among the task names; the field accepts any string. There is no run_vlm — runner.rs has run_asr, run_ocr, run_detect, and TTS lives in tts.rs — and ffai-cli explicitly guards Task::Vlm out:

Task::Detect => ffai_bench::runner::run_detect(&reg, &cfg)?,
_ => unreachable!("guarded above"),

So the VLM harness is not "unused", it is absent, and the CLI refuses it. That work belongs in §3.3's genuinely new column and in step 0, not in the reuse ledger. (This is the first draft's own §32 failure mode, caught before it cost anything: an asset assumed present because a comment named it.)

The corpus rules (inherited, non-negotiable):

  • corpora/argus-*.toml following the existing corpus format, hash-pinned, per-clip license recorded — public corpora only, this is a public repo.
  • References declared in corpora/references.toml with decode config pinned explicitly, the way every ASR reference is. Sampling temperature, top-p, seed, max tokens: unpinned, we would be comparing decoding strategies while pretending to compare models.
  • Every claim traceable to a ledger line. No exceptions.

The two arms — and why one is not enough

A VLMEvalKit row of OCRBench 840 tells you how good InternVL3.5-8B is. It tells you nothing about whether FFai's implementation of it is any good. Every other FFai headline is an implementation claim against a matched reference, and the README says why in as many words:

"Comparing our small.en against their tiny.en would price the model rather than the implementation, which is the error the reference file exists to prevent."

A scoreboard measuring only the model would let Argus publish a leaderboard row that is true and says nothing about the port. So Argus runs two arms, both declared in references.toml, both landing in the same ledger record:

arm what it is what it prices which gates it feeds
Arm 1 — the scoreboard VLMEvalKit as a batch_command reference adapter: their code, their prompts, their metrics, their answer extraction the model — the absolute row, and honesty about Tier-1/Tier-2 standing quality
Arm 2 — the matched reference the same checkpoint, same prompts, same pinned decode config, run on CPU by an independent runtime (Transformers, or llama.cpp/mtmd if it serves the chosen model) the implementation — us against them on identical weights correctness, speed, footprint — and it supplies step 3's tensor oracle

Arm 2 must be named at Gate 1.2 alongside the model, because the choice of model constrains which runtimes can serve it — and a model no independent CPU runtime will run cannot be gated on three of the four gates at all. A skipped gate is never a pass, so that is a disqualifying property, not a footnote.


2. Content and context types a VLM requires

This is the full input/output surface. FFai's VlmEngine trait models a fraction of it — noted per row, because each gap is either a trait change (breaking) or a deliberate scope cut.

2.1 Visual inputs

type what it means FFai today
Single image one ImageBuffer ✅ describe_image
Native / arbitrary aspect ratio modern VLMs do not square-crop; they preserve aspect and pad to patch multiples ⚠ preprocessing must be written; Carmenta's svtr_input is the closest precedent
Dynamic resolution / tiling ("AnyRes") a high-res page is split into tiles + a global thumbnail, each encoded, tokens concatenated. This is what makes small VLMs readable on documents ❌ not built
Multi-image several images in one prompt ("compare these") ❌ trait takes one
Interleaved image-text text <img> text <img> text — the native format of modern VLM chat ❌ trait has no representation
Video as frames sampled frames + timestamps ✅ describe_video(&[VideoFrame]), and VideoFrame already carries timestamp
Video with temporal encoding the model must know frames are ordered in time, not a bag of images (M-RoPE's time axis) ❌ not modelled
Region / grounding input "what is in this box" — a box or point as part of the prompt ❌

2.2 Textual / control context

type what it means FFai today
User prompt the instruction ✅ VlmOptions.prompt
System prompt role/behaviour framing ❌
Chat template every instruct model has a specific turn format (<|im_start|>…); getting it wrong silently degrades output with no error ❌ — the highest-risk silent failure in the whole build
Special vision tokens <image>, <|vision_start|>… inserted at the exact position image tokens occupy ❌
Conversation history multi-turn ❌
Generation config temperature, top-p, top-k, repetition penalty, seed ⚠ only max_new_tokens
Stop conditions EOS token, stop strings, max length ❌

2.3 Outputs

type what it means FFai today
Free text a caption or answer ✅ String
Timed segments video → chaptered track ✅ Vec<TimedSegment<String>>
Structured / JSON schema-constrained extraction — the highest-value output for a tooling product ❌ needs constrained decoding
Grounded output text + boxes ("the dog [x,y,w,h]") ❌
Token-level confidence logprobs — Carmenta uses recognition confidence for its verifier; the analog is valuable ❌
Streaming tokens as produced ❌

Gate 2 — decide the trait surface ONCE, before implementing. VlmOptions currently has two fields. Every gap above is either added now (cheap, pre-1.0) or becomes a breaking change later. Recommendation: extend VlmOptions with system prompt, sampling config and stop conditions; add a multi-image/interleaved input type; leave grounding and streaming out of v1 explicitly and in writing, so their absence is a decision and not an oversight.

★ DETERMINISM IS A v1 REQUIREMENT, NOT AN EXTENSION. The table above marks seeded sampling ⚠ EXTEND (§3.4.4). That is wrong and it is promoted here to a hard gate condition, because byte-stability is the one property true of every other component at once:

  • Mercury TTS: same text, same seed, byte-identical WAV — verified at both the library and file-hash level — and the README makes the point that piper structurally cannot offer this. It is a shipped competitive claim.
  • Mercury ASR: byte-identical transcripts; the adaptive-context escalation path is byte-for-byte the old path by construction.
  • Carmenta: gates on byte-identity; LIVE's whole value is zero churn across unchanged frames.
  • Diana: detections identical to PyTorch at four tiers; wasm agrees with native to display precision.

A VLM that ships stochastic sampling with an unpinned seed breaks that line and makes future gate-off byte-identity checks impossible — you cannot prove a knob is inert against a target that will not repeat. v1 ships: greedy decode as the default, every sampling knob seeded and recorded, and the decode config pinned on both arms. The corpus gate then reports what Mercury TTS already reports — the seed-to-seed spread — so a change smaller than that spread is never mistaken for a result.


3. The encode / decode function map

This is the complete call graph of a VLM forward pass, annotated with what FFai already has — which is more than it looks.

3.1 ENCODE — image → tokens

ImageBuffer
  │
  ├─ 3.1.1  PREPROCESS
  │         resize (aspect-preserving) · pad to patch multiple · normalize
  │         (mean/std) · RGB↔BGR · planar layout · dtype cast
  │         ✅ PRECEDENT: carmenta::svtr::svtr_input, carmenta::image
  │
  ├─ 3.1.2  TILE (dynamic resolution)
  │         choose tile grid from aspect ratio · crop tiles · build global
  │         thumbnail · record tile positions
  │         ❌ NEW — and load-bearing for document/OCR scores
  │
  ├─ 3.1.3  PATCH EMBED
  │         conv2d(k=patch, s=patch) → flatten → [n_patches, d]
  │         ✅ PRECEDENT: carmenta::svtr conv + reshape
  │
  ├─ 3.1.4  VISION POSITION ENCODING
  │         learned abs · OR interpolated 2-D · OR 2-D RoPE
  │         ⚠ PARTIAL — 1-D only in existing code
  │
  ├─ 3.1.5  VISION TRANSFORMER (×N)
  │         LayerNorm → MHSA(q,k,v,proj) → residual
  │         LayerNorm → MLP(fc1, act, fc2) → residual
  │         ✅ PRECEDENT: carmenta::svtr::{attention, enc_block, ln, linear}
  │            — SVTR is a real ViT-shaped encoder already running on candle
  │
  └─ 3.1.6  CONNECTOR / PROJECTOR → LLM embedding space
            MLP (easiest) · pixel-shuffle/token-merge (cuts token count 4×)
            · Q-Former / perceiver resampler (hardest)
            ❌ NEW — but the MLP variant is ~50 lines
Text prompt
  │
  ├─ 3.2.1  CHAT TEMPLATE  — exact turn markers for the chosen model  ❌ NEW
  ├─ 3.2.2  TOKENIZE       — BPE/SentencePiece
  │                          ✅ HAVE: `tokenizers` crate, used by Mercury ASR
  ├─ 3.2.3  SPECIAL TOKENS — <image> placeholders at image positions  ❌ NEW
  └─ 3.2.4  EMBED          — token ids → vectors                      ✅ candle
  3.3  SEQUENCE ASSEMBLY
       splice image-token blocks into the text embedding sequence at the
       placeholder positions · build attention mask · assign positions
       (M-RoPE: separate time/height/width axes for video)
       ❌ NEW — this is the actual "multimodal" step and the one most likely
       to be silently wrong (wrong offset = plausible but degraded output)

3.2 DECODE — tokens → text

  3.4.1  PREFILL           full forward over the assembled sequence,
                           populate KV cache
                           ✅ PRECEDENT: Mercury Whisper decoder holds and
                              mutates a KV cache across steps
  3.4.2  DECODE STEP       one token at a time, cache-appended
                           ✅ PRECEDENT: same
  3.4.3  LOGIT PROCESSING  temperature · top-k · top-p · min-p ·
                           repetition/frequency penalty                ⚠ EXTEND
  3.4.4  SAMPLE            greedy or stochastic (seeded — determinism is a
                           house requirement; Mercury advertises byte-stable
                           output and Carmenta gates on byte-identity)  ⚠ EXTEND
  3.4.5  CONSTRAINED DECODE  grammar / JSON-schema masking — what makes a
                           small model emit valid structured output     ❌ NEW
  3.4.6  STOP              EOS · stop strings · max_new_tokens          ❌ NEW
  3.4.7  DETOKENIZE        ids → text, incremental for streaming
                           ✅ `tokenizers`
  3.4.8  ASSEMBLE          video: per-window captions → TimedSegment    ✅ types exist

3.3 The reuse ledger — what this build actually costs

already in-tree where
candle tensor spine, safetensors loading workspace-wide
ViT-shaped encoder blocks (attention/LN/MLP/conv) carmenta::svtr
image preprocessing + crop/resize/normalize carmenta::image, svtr_input
autoregressive decoder with KV cache mercury::asr::whisper_candle
BPE tokenizer + detokenize tokenizers, used by Mercury
ONNX graph import (arch JSON + safetensors) carmenta::onnx_graph
engine registry, VlmEngine trait, VideoFrame, TimedSegment ffai-core
bench SPINE reusable as-is: hashed corpora, best-of-N timing, footprint sampler, four-gate verdict, ledger, external-reference adapters ffai-bench
genuinely new rough weight
run_vlm + the VLM gate + un-guarding Task::Vlm in the CLI small–medium — and it is step 0's real content. The first draft listed a "vlm" task slot as in-tree; it is three doc comments and an unreachable!() (§1.3)
streaming frame ingest in ffai-media medium — a hard prerequisite for step 7, see §4
dynamic-resolution tiling medium — but decides document scores
connector/projector (MLP form) small
chat template + special-token splicing small code, high silent-failure risk
M-RoPE / 3-D positions for video medium
sampling stack + stop conditions small
constrained (JSON) decoding medium — defer to v2 unless the product needs it
sequence assembly small code, highest silent-failure risk

The honest read: Argus is a connector-and-plumbing build, not a from-scratch-model build — provided the model choice (Gate 1.2) picks an architecture whose two halves we already have precedent for.

The alternative that must be priced, not assumed away: the house doctrine (rusty-coding-requirements) names mistral.rs as the LLM serving engine on top of candle, through a ChatEngine seam, and ffai-argus/Cargo.toml already reserves a mistralrs-backend feature. If mistral.rs supports the chosen VLM, most of §3.2–§3.4 is already written by someone else and Argus becomes: preprocess → call the engine → assemble.

This was "Gate 3"; it is now column (e) of Gate 1.2 and is answered in the same sitting as the port-cost triage, for the reason given there. Porting a decoder we could have called is the most expensive possible mistake in this plan, and running the check as a separate later step is how that mistake happens.

Two conditions the house doctrine attaches to using it (rusty-coding-requirements §4–§5), which are cheap now and breaking later:

  • Through the seam, pinned to a tagged release. VlmEngine is the seam — that part is already right — so the rule reduces to: nothing outside ffai-argus may name mistralrs, and the dependency is pinned to a tag, not a floating git ref. The Cargo.toml comment already flags the git-dep cost; the pin is the other half of that thought.
  • Re-run the crate-count and C-dependency table for Argus and publish it. Diana publishes 138 default / 308 with fetch / 95 on wasm32, compiles no C, as part of its pitch. mistral.rs is a large dependency and Argus's disclosure is not "inherited unchanged" — it is whatever the table says after the dependency lands. Measure it, then write it down. See §5.

4. Sequencing, with kill gates

# step gate that must pass before the next step
0a ✅ ffai-bench VLM harness: run_vlm, the VLM four-gate verdict, the ledger record, Task::Vlm un-guarded in the CLI, the corpora/argus-*.toml shape (§1.3) DONE 2026-08-21 — ffai bench vlm --corpus … runs end to end and appends a ledger line; see §6 for what landed and what it deliberately does not do
0b ✅ stand up VLMEvalKit as a references.toml batch adapter (Arm 1), and score a Tier-3 candidate through it DONE — GATE 1.1 PASSED 2026-08-21, see §12. SmolVLM-256M-Instruct scored 525/1000 against a published 526 (52.6). Inside the pre-registered 496–556 band by 30x. 1000/1000 scored
0c declare Arm 2 — the matched-weights CPU reference — in references.toml with its decode config pinned Arm 2 runs the same checkpoint on the same clips. Without it, steps 6–7 can price the model but not the port (§1.3)
1 ✅ port-cost triage of the Tier-3 shortlist — all five columns of Gate 1.2, mistral.rs support included DONE 2026-08-21 — see §8. Model chosen: SmolVLM-256M-Instruct (v1). Connector: pixel-shuffle (scale_factor: 4). mistral.rs: serves it via Idefics3. candle fallback: has SigLIP + Llama, needs only the connector. Arm 2: plain Transformers CPU, SmolVLM-256M/greedy-64
2 ✅ trait surface decision (§2 Gate 2), including the v1 determinism requirement DONE 2026-08-21 — see §10. ffai-core 0.6.5 → 0.7.0. Decoding enum makes unseeded sampling unrepresentable; VlmPrompt/VlmPart add interleaved multi-image with describe as the required method; v1 exclusions written down. 5 new tests
3 ✅ vision tower only, oracle-matched against Arm 2's runtime on fixed input DONE 2026-08-21 — see §11. vision_out SNR 104.8 dB, connector 113.2 dB, both within 3e-4 of the stage's own std. Preprocessing and tiling deliberately excluded — step 3 is the tower only
4 ✅ connector + sequence assembly + chat template DONE 2026-08-21 — see §13. Input ids exact (1142/1142), splice bit-exact, and 32/32 output tokens identical feeding our embeddings to the reference decoder. Preprocessing and tiling deliberately excluded
5 ✅ decode loop (or mistral.rs call) DONE 2026-08-21 — see §15. candle llama loop with KV cache: 32/32 tokens both decoder-isolated and whole-pipeline. Content path built and measured; its ≤1-level Lanczos gap flips a token and is an open, named gate
6 ✅ describe_image end-to-end; score on the core suite DONE 2026-08-21 — see §16. Caption byte-identical to the reference; 49/50 answers identical to Arm 2 on OCRBench-lite. Four gates, both arms, no SKIPs: correctness PASS, quality PASS (exact tie), footprint PASS (0.71x), speed FAIL (2.4x) with both obvious causes measured and refuted
7-pre streaming frame ingest in ffai-media — an unpriced prerequisite in the first draft sample_frames stops materialising the whole clip. Today it returns every frame in memory at once — one minute of 1080p is 10.4 GiB — and no CLI verb drives it. describe_video sits directly on top of this, so step 7 is a media-plumbing step with a VLM on the end
7 ✅ describe_video: frame sampling → windowed captions → timed track DONE 2026-08-21 — see §17. ffai caption -i clip.mp4 with srt/vtt/json; sampling policy stated; windowed (splitting OFF, 64 tokens/frame); track gated by 6 structural tests. Found and fixed a stream_frames defect that returned ONE frame per clip at any fps. No Video-MME row: the checkpoint is an image model with no published video row, and inventing one is the scorer trap §5 refuses
B1 (mission B probe, independent) take Carmenta's worst substitution pages, ask the chosen VLM to repair, score on OmniDocBench ≥ the pipeline levers' prize, or mission B is closed and Argus stays a product feature

5. What this build must NOT repeat

  • No home-grown scorer. The single most expensive lesson of the Carmenta campaign. Answer extraction is part of the metric; write none of it.

  • No claim without the reference under the same harness. Published rows are claims; a reproduced row is a measurement.

  • ★ No score that prices the MODEL where the claim is about the PORT. A benchmark row and an implementation verdict are different objects. Arm 1 answers "how good is this model"; Arm 2 answers "how good is our version of it" (§1.3). Publishing Arm 1 alone would be the small.en-vs-tiny.en error the reference file exists to prevent — true, and about someone else's work.

  • ★ No asset counted as in-tree because a comment names it. The first draft listed a ffai-bench "vlm" task slot as existing; it was three doc comments and a _ => unreachable!(). Before a reuse-ledger row is written, grep for the function, not the string.

  • ★ No stochastic default. Greedy decode is the default and every sampling path is seeded (§2 Gate 2). The seed-to-seed spread is reported beside the score, the way Mercury TTS reports its 1.11 pp, so a delta smaller than the spread is never read as a result.

  • Oracle-match the tower before generating text. Every silent defect the §45–§47 model ports had was found by tensor comparison, not by looking at output. Generated text hides numerical error behind plausibility.

  • Pin the decode config, ours and theirs. Unpinned sampling compares strategies, not implementations (references.toml already says this for ASR).

  • State the C/C++ position honestly — and MEASURE it rather than inheriting it. candle's CUDA path and the tokenizers/onig_sys build-time C dependency already exist in this workspace; the README rule is that we never claim "no C in the tree" for a candle build. But "Argus inherits that disclosure" is too weak: mistral.rs is a large dependency, and Diana set the precedent that this is a published table, not a sentence —

    build transitive crates compiles C?
    ffai-diana, default 138 yes — onig_sys
    ffai-diana + ffai-models/fetch 308 yes — onig_sys, aws-lc-sys
    wasm32-unknown-unknown 95 no

    Argus publishes the same three rows once the backend lands, whatever they say. If the mistral.rs path drags in C or balloons the count, that goes in the README beside Diana's — the project's habit of printing its losing rows is the reason its winning ones are believable.

  • Do not let mission B justify the build without the B1 probe. A VLM that helps documents is a hypothesis; the ledger says 44 % of Carmenta's remaining loss is cheaper pipeline work either way.


6. Step 0a — what landed (2026-08-21)

The VLM harness exists and runs. It is the plan's first step and it is deliberately ahead of the engine: Gate 1.1's whole argument is that a harness built after the engine is a harness the engine's behaviour has already shaped.

ffai bench vlm --corpus corpora/argus-smoke-v1.toml \
               --refs corpora/references-argus-smoke.toml --baseline-only
bench bench-vlm-1787338596 · corpus argus-smoke-v1 (eb013c79a9f4) · 3 items

IMPLEMENTATION           FIXTURE SCORE01  IT/S_WARM   IT/S_E2E   LOAD_S  PEAK_MiB   CLIPS
  fixture-arm1            100.00  100.00  140186.99      28.64     0.00        17     3/3
  fixture-arm2-matched    100.00  100.00  145631.19      35.30     0.00        17     3/3

correctness  SKIP  baseline-only run (no engine)
quality      SKIP  baseline-only run (no engine)
speed        SKIP  baseline-only run (no engine)
footprint    SKIP  baseline-only run (no engine)

verdict: not claimable yet

What was built

piece where
run_vlm — the vertical, with the two-arm reference contract crates/ffai-bench/src/vlm.rs
ScorerSpec — the benchmark's own evaluator, declared by the corpus crates/ffai-bench/src/corpus.rs
VlmScore — raw + normalised + metric + scorer + item count crates/ffai-bench/src/ledger.rs
QualityMetric::VlmScore — the higher-better → lower-better fold crates/ffai-bench/src/runner.rs
ClipEntry::prompt — inline, and now genuinely inside the manifest hash crates/ffai-bench/src/corpus.rs
Task::Vlm un-guarded; VLM columns in render crates/ffai-cli, runner::render
smoke corpus + fixture adapter/scorer corpora/argus-smoke-v1.toml, tools/argus_fixture_*.py

The load-bearing design decision

Predictions are ours; scoring is theirs. The engine runs in-process — the speed and footprint gates ask what our binary costs, and routing it through a Python wrapper would measure the wrapper — but the answers go to the benchmark's own evaluator, declared per corpus. vlm.rs contains no answer-comparison code and must never contain any. The nearest thing to scoring in the whole module is dividing the evaluator's number by a scale the corpus declared.

Two things it refuses to do, on purpose

  • A VLM corpus with no [scorer] is an error, not an unscored run. The alternative to a declared evaluator is not "no score" — it is somebody adding a string comparison here next month.
  • A stub engine fails loudly rather than appending an empty run. Argus returns NotImplemented, so --baseline-only is the only honest invocation today. This is the state detect was in before Diana's first engine landed.

A correction found while building it

ClipEntry::prompt was documented as falling under Manifest::manifest_hash "for free". It did not. The hash covered (name, version, id, sha256, split) and nothing else, so a reworded question would have left the corpus fingerprint unchanged — an unpinned input, the same class of defect as an unpinned decode config, in a plan whose §5 lists exactly that as a thing not to repeat. The hash now includes the prompt, length-prefixed, only when present, so every pre-existing corpus fingerprint is byte-for-byte unchanged; hashes_are_stable_for_promptless_corpora pins that by recomputing the old algorithm independently rather than by hardcoding a constant captured from the new code.

An extra gate the plan did not ask for

tighten_correctness compares the corpus holdout count against the item count the scorer reports. A scorer that silently scored 900 of 1000 items produces a real number over the wrong population, and it reads as an ordinary result. This is work-count parity — the cheapest check available and the one most likely to fire — and when the scorer reports no count, the gate says the check did not run rather than passing quietly.

What is NOT done, and is not claimed to be

Steps 0b and 0c are untouched. They need VLMEvalKit, a Python environment, model weights and a network, none of which this session had. What exists in their place is a labelled fixture pair (tools/argus_fixture_reference.py, tools/argus_fixture_scorer.py) whose entire job is to prove the pipe is connected — they read no ground truth, extract no answers and compare nothing, and both print NOT A METRIC / NOT A MODEL in their own --version output so the label reaches the ledger line. No number produced by the smoke corpus is a measurement of anything.

The real work remaining at step 0:

  • 0b — VLMEvalKit stood up and declared in corpora/references.toml as Arm 1, scoring a Tier-3 candidate, with its published row reproduced.
  • 0c — Arm 2, the matched-weights CPU runtime, declared with its decode config pinned to the same decode key the engine will report.

7. Steps 0b and 0c — the two arms, built (2026-08-21)

Step 0a gave the harness a shape. 0b and 0c fill the two arms it was shaped for, and the design decision that makes them work is one sentence:

Both arms are scored by the same VLMEvalKit evaluator. What differs is who produced the predictions.

That is what makes the arms comparable to each other at all. If Arm 1 were scored by VLMEvalKit and Arm 2 by anything else, the difference between them would confound "different runtime" with "different metric", and neither number would mean what its label says.

Arm 1 Arm 2
file corpora/refs/vlmevalkit_ref.py corpora/refs/smolvlm_hf_ref.py
who infers VLMEvalKit's own model wrapper plain Transformers on CPU
decode config whatever the wrapper does pinned: greedy, 64 tokens, fp32, seed 0
config key SmolVLM2-256M/vlmevalkit-default SmolVLM2-256M/greedy-64
prices the model — leaderboard-comparable the implementation — our port's bar
feeds quality (as open-field context) correctness, speed, footprint, quality
scored by corpora/refs/vlmevalkit_score.py the same file

Why the config strings differ, and why that is the point

fill_gates only lets a reference decide the quality gate when its config string equals the engine's. Arm 2 carries the string FFai's engine will report; Arm 1 deliberately does not. So Arm 1 can never be mistaken for a matched comparison — it stays open-field context — while Arm 2 is the bar. This is the same guard that stopped a 74M beam-search model from deciding a 39M greedy engine's gate on the ASR side, reused rather than reinvented.

If the engine ever reports a key Arm 2 does not declare, the quality gate SKIPS. That is the intended failure mode, not a bug: a skipped gate is never a pass.

What was built

piece what it does
tools/argus_build_corpus.py VLMEvalKit dataset → hash-pinned corpora/argus-*.toml, with VLMEvalKit's own build_prompt output inline as the prompt, and the clip id set to their index so their evaluator can join on it
corpora/refs/vlmevalkit_score.py the [scorer]: converts our predictions to VLMEvalKit's eval frame, calls dataset.evaluate(...), reads the headline out. No answer comparison of any kind
corpora/refs/vlmevalkit_ref.py Arm 1
corpora/refs/smolvlm_hf_ref.py Arm 2, decode config pinned explicitly
tools/argus_doctor.py preflight; each check maps to a way this pipeline yields a wrong number rather than an error
{corpus} placeholder ReferenceSpec::run_batch_subst — a VLM item is an (image, question) pair and the question lives in the pinned manifest, so an adapter that cannot see the manifest would have to invent prompts

Three rules the scorer enforces, and why each exists

  • An unjoinable prediction id is a hard error. Silently dropping it would shrink the scored population and produce a real number over the wrong items.
  • Only predicted rows are handed to the evaluator. Passing it rows we never ran would let it count them wrong and report a score over a population the harness never touched.
  • An unrecognised result shape is an error, never a guess. The headline-key list is ordered and explicit; picking "the first numeric thing" would misreport a benchmark and look entirely normal doing it.

Prerequisites, learned the hard way

  • torchvision is required and its absence is not obvious. transformers 5.x resolves SmolVLM's image processor to a torchvision backend and raises Could not load any image processor class at from_pretrained time — after you have paid for the model download.
  • Disk. This box had 3.1 GB free of 930 GB when 0b started, which is less than one torch install. tools/argus_doctor.py checks it first, because a weight download that runs out of space leaves a truncated file that still loads and produces garbage. ~45 GB of stale target/ dirs across sibling checkouts were the reclaim.

Two upstream constraints found standing 0b up, and both belong in the plan

Neither is a local inconvenience; each is a fact about the scoreboard that the next person will hit.

1. VLMEvalKit is unimportable on Windows. vlmeval/dataset/utils/hipho_verifier.py defines

def timeout(timeout_seconds: int = 10):
    if os.name == "posix":
        ...
        return decorator
    # <-- no else branch

…and then uses @timeout(timeout_seconds=30). On nt the decorator is None, so import vlmeval raises TypeError: 'NoneType' object is not callable — not for a dataset we use, but at package import, so nothing works.

2. VLMEvalKit's model wrappers hardcode CUDA — and FFai is CPU-first. vlmeval/vlm/smolvlm.py carries device_map="cuda", .to("cuda") and torch.cuda.empty_cache(). On a CPU box every one raises Torch not compiled with CUDA enabled.

This is the more interesting of the two, because it is a structural mismatch rather than a bug: the harness that defines the leaderboard assumes the hardware class Argus exists to avoid. Assume every future Arm-1 wrapper needs the same treatment until checked, and price that into Gate 1.2 — a Tier-3 candidate whose VLMEvalKit wrapper is GPU-welded costs more to baseline than its row suggests.

Both fixes live in corpora/refs/patches/, are applied by apply_vlmevalkit_patch.py, and are recorded rather than merely applied: .tools-bench/ is gitignored, so a re-clone is a re-apply, and more importantly a patched reference is not the published reference. Any ledger line produced through one has to be readable as such later.

The device patch changes device selection only — not weights, dtype (already float32), preprocessing, chat template or generation config — so the row Arm 1 produces is unchanged and only its speed differs. That is what keeps the patched arm fit for purpose: Arm 1 is quoted for its score, never for its throughput. Throughput is Arm 2's job, and Arm 2 is unpatched plain Transformers.

A finding for Gate 1.2 column (d), measured rather than assumed

Running SmolVLM2-256M's processor on one COCO photo:

pixel_values          (1, 17, 3, 512, 512)
pixel_attention_mask  (1, 17, 512, 512)

Seventeen 512x512 tiles for a single image — one global thumbnail plus a 4x4 grid. So dynamic-resolution tiling is not optional for this candidate: its published scores are produced with it on, and §3.1.2 lists it as NEW - and load-bearing for document scores. Gate 1.2's column (d) is answered for SmolVLM2-256M, and the answer is yes, required.

That also sizes the port honestly: the vision tower runs 17 times per image, so tower cost dominates and the encoder is where the speed gate will be won or lost — not the decoder.

0b + 0c RESULT — both arms run, and they disagree

ffai bench vlm --corpus corpora/argus-ocrbench-lite-v1.toml --baseline-only --runs 1
bench bench-vlm-1787342838 · corpus argus-ocrbench-lite-v1 (4811975fa6a6) · 50 items

IMPLEMENTATION           OCRBENC SCORE01  IT/S_WARM   IT/S_E2E   LOAD_S  PEAK_MiB   CLIPS
  smolvlm2-256m-vlmevalkit   44.00   88.00       0.14       0.12    35.64      2427   50/50
  smolvlm2-256m-transformers  40.00   80.00       0.15       0.14    23.94      2193   50/50

correctness SKIP · quality SKIP · speed SKIP · footprint SKIP
verdict: not claimable yet

Both arms answered all 50 items and were scored by VLMEvalKit's own evaluator. The gates SKIP because Argus is still a stub — this is a baseline-only run, and the harness says so rather than inventing a verdict.

⚠ These are 50 of OCRBench's 1000 items. The corpus file says so in its own header. A subset score is not comparable to a published row; Gate 1.1 needs the full export. The speed and memory figures are single-run, unpinned and not ABBA-interleaved, so they are provenance for the plumbing, not measurements to quote.

★ The finding: 43 of 50 answers differ, on IDENTICAL weights

Same checkpoint. Same 50 images. Same pinned questions. Only 7 of 50 answers matched, and the score moved 8 points.

id Arm 1 (VLMEvalKit prompt) Arm 2 (plain chat template)
2 Chain. The image contains the text "chain".
3 CLOSE The image contains the word "CLOSE" written in black letters.
4 MARKET. The image contains the word "MARKET" written in yellow.
0 Centre Centriole
8 AHEAD HEAD

The mechanism is the per-dataset prompt. VLMEvalKit's SmolVLM.generate_inner dispatches on the dataset name to build_prompt_docvqa / build_prompt_chartqa / … and each prepends its own instruction — DocVQA's is "Give a short and terse answer … Do not paraphrase … Just give the answer without additional explanation." Arm 2 sends the dataset's question through the processor's plain chat template and gets conversational prose back. OCRBench's matcher tolerates some of that verbosity and not all of it, so 8 points fall out.

This is §2.2's "chat template — the highest-risk silent failure in the whole build" measured rather than asserted, and it is worse than that row says. The risk is not only getting the turn markers wrong; it is that a correct chat template with the wrong instruction preamble produces fluent, plausible, differently-scored output with no error anywhere. Nothing in either arm looked broken. Both were "working".

Three consequences for the build:

  1. The engine's prompt formatting is a scoreboard concern, not a model concern. Whatever FFai's engine emits, it must emit the same preamble as the arm it is being compared against, or the comparison prices prompting.
  2. Arm 2 is the right gate and Arm 1 is the right context — confirmed empirically, not just by argument. Had there been one arm, this 8-point prompt effect would have been silently attributed to the implementation.
  3. A step-4 gate needs tightening. §4 step 4 says "a known image+prompt reproduces the reference implementation's output tokens" — that must mean Arm 2's tokens under Arm 2's exact prompt string, and the prompt string has to be pinned alongside, not reconstructed.

Corrections made while getting here

  • The OCRBench scale was wrong, and it was wrong in the silent direction. Declared 1000.0 (the full benchmark's maximum) on the reasonable basis that "OCRBench is scored out of 1000". Its evaluator returns a count of correct answers, so on a 50-item corpus a perfect run scores 50. A genuinely good 40-of-50 normalised to 0.04, which the quality gate reads as near-total failure. Fixed: count-based metrics declare PER_ITEM and the builder resolves it to the holdout count.
  • The check that caught it is now a tool — tools/argus_verify_scale.py. It feeds the benchmark's own ground truth back as predictions; a correct scale normalises to exactly 1.0. The asymmetry is the point: garbage-scores-0 proves nothing on its own, because a broken join also scores 0. Only the truth end can distinguish them. Run both; neither alone is evidence.
  • dataset=None was being passed to Arm 1's generate, which would have silently selected the default prompt instead of the benchmark's — an Arm 1 that reproduces nothing while looking fine. It is now a required argument, and the reference is declared per dataset so the dataset is visible in the ledger's command line.
  • The base64 image column was being written into the evaluator's xlsx, where openpyxl truncates cells at 32767 characters — silent corruption. It is dropped before the dump.

One more fingerprint gap, found by reading the ledger

The two runs above — scale = 1000 and the corrected scale = 50 — produced normalised scores of 0.04 and 0.80, a twentyfold difference, under an IDENTICAL corpus_manifest_hash. The [scorer] block sat outside the fingerprint.

That breaks the ledger's actual contract: a line is sufficient on its own to reproduce the run. A scorer that can change without the fingerprint moving is the same defect as an unpinned prompt or an unpinned decode config, one layer further out — and it is the one that decides the number the gate verdicts on.

Manifest::manifest_hash now folds in the scorer's name, metric, command and scale, hashed only when present, so every pre-VLM corpus keeps its existing fingerprint. That is verified rather than argued: a_shipped_corpus_still_hashes_to_its_ledger_value recomputes librispeech-test-clean-v2 and asserts it still equals the value already sitting in bench/ledger.jsonl. If it ever drifts, every historical line silently stops matching its own data.

Where 0b and 0c stand

status
VLMEvalKit installed, importable, patched, recorded ✅
Arm 1 declared, runs on CPU, 50/50 items ✅
Arm 2 declared, decode config pinned, 50/50 items ✅
Scoring is VLMEvalKit's for both arms ✅
Corpus builder, hash-pinned, prompts inline and fingerprinted ✅
Scale verified at both ends (truth 1.0 / garbage 0.0) ✅
Preflight (argus_doctor.py) 9 ok / 0 warn / 0 fail ✅
Gate 1.1 — a published row reproduces ❌ NOT DONE

Gate 1.1 is not passed and must not be reported as passed. Everything above is the apparatus for it. The gate itself needs the full 1000-item export and a comparison against SmolVLM2-256M's published OCRBench row:

.venv-argus/Scripts/python.exe tools/argus_build_corpus.py \
    --dataset OCRBench --out corpora/argus-ocrbench-v1.toml
.venv-argus/Scripts/python.exe tools/argus_verify_scale.py \
    --corpus corpora/argus-ocrbench-v1.toml
ffai bench vlm --corpus corpora/argus-ocrbench-v1.toml --baseline-only --runs 1

At the ~0.14 items/s measured here that is ~2 hours per arm on this box. Until it runs, the honest statement is: the scoreboard is standing and verified end to end on a subset; whether it reproduces a published row is untested.


8. GATE 1.2 — the port-cost triage, ANSWERED (2026-08-21)

Answered by reading the actual mistral.rs loader source and each candidate's actual config.json, not from documentation. mistral.rs was already on this machine as a cargo git checkout (~/.cargo/git/checkouts/mistral.rs-*/5495752) and candle 0.11.0 in the registry, so both halves of the house stack could be inspected directly.

The table

candidate (a) vision tower (b) connector (c) LLM (d) tiling required? (e) mistral.rs serves it?
SmolVLM-256M-Instruct (v1) SigLIP — candle has siglip.rs pixel-shuffle, scale_factor: 4 — the ~50-line variant, not a resampler llama — candle has llama.rs yes, measured: 17 tiles YES
SmolVLM2-256M-Video-Instruct smolvlm_vision same llama yes NO
Qwen2.5-VL-3B custom ViT (window attn) MLP merger qwen2 — candle has it native dynamic-res YES (qwen2_5vl)
Qwen3-VL-2B qwen3-vl vision merger qwen3 native dynamic-res YES (qwen3vl) — and candle has qwen3_vl/
InternVL3.5-2B InternViT pixel-shuffle qwen yes NO — InternVLChatModel unmapped, no internvl in either stack
Moondream2 custom — custom — NO (though candle has moondream.rs)

The verdict: SmolVLM-256M-Instruct (v1)

It is the only candidate that wins on every column, and it displaces the first draft's lead candidate.

Column (e), established from the source. MultimodalLoaderType::from_causal_lm_name maps HF architectures[0] onto a loader. Idefics3ForConditionalGeneration → Idefics3, and that loader's ArchMetadata declares families: &["Idefics3", "SmolVLM"] — SmolVLM is a named supported family. The full supported set is 22 architectures: phi3v, idefics2, llava_next, llava, lfm2vl, vllama, qwen2vl, idefics3, minicpmo, phi4mm, qwen2_5vl, gemma3, mistral3, llama4, gemma3n, gemma4, qwen3vl, qwen3vlmoe, qwen3_5, qwen3_5moe, voxtral, diffusiongemma.

★ SmolVLM2 — the candidate the plan named — is the one that does NOT load

Two independent failures, both verified against the real config:

  1. Auto-detect bails. SmolVLM2's architectures[0] is SmolVLMForConditionalGeneration, which is absent from from_causal_lm_name; the match arm falls through to anyhow::bail!("Unsupported … model class").
  2. Forcing --arch idefics3 also fails. Idefics3Config deserializes nine required vision_config fields. SmolVLM2's vision_config has four of them and omits five — intermediate_size, num_hidden_layers, num_channels, hidden_act, layer_norm_eps — so serde rejects it before a tensor is touched.
architectures[0] vision_config fields missing for Idefics3Config
SmolVLM-256M-Instruct Idefics3ForConditionalGeneration none — parses
SmolVLM2-256M-Video SmolVLMForConditionalGeneration intermediate_size, num_hidden_layers, num_channels, hidden_act, layer_norm_eps

This is Gate 1.2 doing exactly the job it was written for: the model with the better story was the one the house stack could not serve, and one hour of reading a loader found it before any porting was paid for.

The candle fallback is also strongest for v1

If mistral.rs is ever the wrong seam, the from-scratch path needs a vision tower, a connector and a decoder. For SmolVLM v1, candle 0.11.0 already ships two of the three:

piece in candle 0.11.0?
SigLIP vision tower ✅ models/siglip.rs
Llama decoder (+ KV cache; Mercury's Whisper decoder is the in-tree precedent) ✅ models/llama.rs
Idefics3 wrapper / pixel-shuffle connector ❌ — and §3.3 already prices the MLP-class connector as small

So the honest port cost for v1 is the connector, the tiling, and the sequence assembly — precisely the three bricks §3.3 already listed as new, with no exotic surprises. Every other candidate adds a vision tower nobody has written.

A second reason v1 wins, found while hunting the published row

Only v1 has a published OCRBench row at all. Its model card carries an evaluation table:

Size Mathvista MMMU OCRBench MMStar AI2D ChartQA ScienceQA TextVQA DocVQA
256M 35.9 28.3 52.6 34.6 47 55.8 73.6 49.9 58.3

SmolVLM2's model card has no model-index, its blog reports only Video-MME, and the OpenVLM leaderboard JSON no longer carries a SmolVLM entry. §1.2 of this plan attributed OCRBench 52.6 / DocVQA 58.3 / ChartQA 55.6 to SmolVLM2 — those are v1's numbers. Corrected here; the §1.2 table should be read with that in mind.

That mis-attribution is not incidental to Gate 1.1, it is the whole point of it: a published row you cannot locate is not a row you can reproduce. The gate re-pins the claim before anything is built on it.

Two operational findings from running Gate 1

1. --limit N takes the FIRST N items, and OCRBench is category-ordered. The 50-item subset in §7 scored 88 % where the published full-benchmark figure is 52.6 %. That gap is not a discrepancy to explain — it is sampling. OCRBench is grouped by task (text recognition first, then scene text, then handwriting, KIE and math), so the first 50 items are the easiest category and nothing else. A prefix of an ordered benchmark is not a sample of it. The subset corpus is valid for exercising the pipeline and invalid for estimating the full score, which is exactly what its generated header says. Anyone adding --limit to a new dataset should check whether that dataset is ordered before reading anything into the number.

2. A mistral.rs build costs ~30 GB, and most of it is debug symbols. Building the Gate-1.2 probe took the disk from 28.6 GB free to 1.5 GB and had to be killed mid-flight. The evidence for where it went was sitting in a stale session scratchpad: .pdb files at 377 MB each, several per crate, across a very large crate graph. Windows release builds emit full debug symbols by default.

The fix is three env vars, and they belong in any doc that tells someone to build this probe:

CARGO_PROFILE_RELEASE_DEBUG=0
CARGO_PROFILE_RELEASE_STRIP=symbols
CARGO_PROFILE_RELEASE_INCREMENTAL=false

tools/argus_doctor.py already checks free disk and defaults to requiring 8 GB. That default is right for running the arms and far too low for building the mistral.rs backend — pass --min-disk-gb 35 before a build. The doctor's own rationale applies with more force here than it did when written: a build that runs the disk to zero does not merely fail, it takes whatever else is running down with it.

Gate 1.2 column (e), RUN rather than read — and it found an upstream bug

A probe crate (.tools-bench/mistralrs-probe, deliberately outside the FFai workspace) links mistral.rs 0.9.0 and loads the Gate-1.2 pick.

Half the prediction confirmed immediately:

probe: loading `HuggingFaceTB/SmolVLM-256M-Instruct` through mistral.rs ...
  DType selected is F32.
  The following sub-models will not be device mapped and will be loaded on cpu: vision
  Model has 30 repeating layers.
  Pipeline input modalities are [Text, Vision]
probe: LOADED in 8.3s

SmolVLM v1 loads in mistral.rs. Auto-detected, no --arch override, vision and text modalities live, 30 layers on CPU. Column (e) is a real YES for loading, exactly as the source predicted.

The other half was refuted, and that is the useful part. Generation panics:

thread '<unnamed>' panicked at idefics3/mod.rs:233:75:
called `Option::unwrap()` on a `None` value

The diagnosis

let n = pixel_values.dim(0)?;                        // TILES
let mut per_image: Vec<Option<Tensor>> = vec![None; n];
for (i, &hash) in image_hashes.iter().enumerate() {  // IMAGES
    ...                                              // fills [0..n_images)
}
let slices: Vec<Tensor> = per_image.into_iter().map(|t| t.unwrap()).collect();

per_image is sized by tile count and filled by image count. For any model with dynamic-resolution tiling, one image becomes many dim-0 slices — SmolVLM makes 17 — so every slot from n_images to n stays None.

The crate already knows this invariant. paged_attention/encoder_cache.rs has a shared helper, cached_encode_images, documented as "cache-aware batch encoding for Pattern A models whose pixel_values have shape (N, C, H, W) with one image per dim-0 slice". It sizes its vector by image_hashes.len() — correctly — and carries

debug_assert_eq!(n_images, pixel_values.dim(0)?,
                 "image_hashes length must match pixel_values dim-0");

Idefics3 open-codes that logic, inverts the sizing, and drops the assertion. And the assertion is a debug_assert, compiled out of release builds — which is why the failure surfaces as a bare unwrap() on None instead of the message that names its own cause. The diagnostic existed and was optimised away.

SmolVLM is simply not a Pattern-A model. Tiling is why it reads documents, and §3.1.2 already flags it as load-bearing.

The same bug is in idefics2

Applying "a fix found in one place is a hypothesis about every place with the same shape":

model cache path correct?
idefics3/mod.rs:205 open-coded, sized by dim(0) ❌
idefics2/mod.rs:1182 open-coded, sized by dim(0) ❌ same bug
gemma3, llama4, llava15 call cached_encode_images ✅

Both hand-rolled copies are wrong; every model that used the shared helper is right. That is the argument for the helper, made by the bug.

The fix

Take the cache path only when the model actually is one-image-per-slice, and otherwise fall through to the existing uncached branch — which is already correct, forwarding the whole tile batch in one call:

let image_hidden_states = if !image_hashes.is_empty()
    && image_hashes.len() == pixel_values.dim(0)?
{

Recorded as corpora/refs/patches/mistralrs-idefics3-tiling-cache.patch. Behaviour is unchanged for non-tiling Idefics models; tiling models stop panicking and lose only a cache they were never eligible for.

An operational trap worth naming: cargo will not rebuild a patched git checkout

Editing a crate under ~/.cargo/git/checkouts/ and rebuilding produced Finished in 1.52s — cargo fingerprints git sources by revision, not by mtime, so the edit was compiled into nothing. cargo clean -p mistralrs-core did not dislodge it either.

The tell was precise and worth remembering: the patch added nine comment lines above the unwrap(), yet the panic still reported line 233. A stack frame that does not move after you have moved the code is the same signal as codec-memory-copies' stale-binary check — verify the binary contains your change before believing any result from it.

The fix is to copy the checkout somewhere writable (112 MB of source) and point the probe at that path instead.


9. GATE 1.1 — the pass criterion, pre-registered

Written before the run finished, deliberately. A tolerance chosen after seeing the number is not a tolerance, it is a rationalisation — and the temptation to widen it by "just a couple of points" is strongest exactly when the result is disappointing. So the band goes on the record first.

The claim under test. SmolVLM-256M-Instruct's model card publishes OCRBench 52.6. OCRBench's evaluator returns a count out of 1000, so the claim is 526 / 1000 raw.

What we run. All 1000 items, corpora/argus-ocrbench-v1.toml (fingerprint pins the clips, the prompts and the scorer), Arm 1 — VLMEvalKit's own SmolVLM wrapper, its own per-dataset prompt, its own evaluator. The only deliberate deviation from a vendor run is CPU instead of GPU, which the device patch keeps score-neutral by construction (§8).

result verdict
496 – 556 raw (52.6 ± 3.0 points) Gate 1.1 PASSES. The harness reproduces a published row; Argus numbers taken through it are trustworthy
476 – 496 or 556 – 576 (± 3–5 points) QUALIFIED. Reproduces in shape, not in detail. Name the cause — transformers version, dtype, tokenizer revision — before proceeding
outside ± 5 points FAILS. Stop. Per §1.1 the harness is wrong, and every Argus number taken through it would be wrong too

Why ±3 and not ±1. The vendor's run and ours differ in at least four uncontrolled dimensions — transformers version (ours is 5.15.1), torch version, VLMEvalKit revision, and the exact model snapshot. Each moves a short-answer-matched score by a fraction of a point to a point or two. ±3 is wide enough to absorb that and far too narrow to absorb a harness defect, which is the thing this gate is built to catch. The 2.8x-biased scorer that motivated this whole document would have shown up as tens of points, not three.

What a PASS does and does not license. It licenses trusting the scoreboard — Arm 1 through this harness reproduces the world's number. It says nothing about FFai's implementation, which is Arm 2's job and step 6's gate. A passed Gate 1.1 is permission to start measuring, not a measurement.

Column (e) — VERIFIED, both directions

With the tiling-cache patch actually compiled in, the probe was run against both predictions. Both landed.

Positive — SmolVLM v1 loads AND generates correctly:

probe: loading `HuggingFaceTB/SmolVLM-256M-Instruct` through mistral.rs ...
probe: LOADED in 8.3s
GENERATE OK (18.5s)
  -> Friend

OCRBench item 1 — question "what is written in the image?", ground truth ['FRIEND']. Both Python reference arms answered FRIEND. mistral.rs, in pure Rust, produced the same answer. That is not just "it ran": the Rust stack agrees with VLMEvalKit's wrapper and with plain Transformers on the same image and the same question.

Negative — SmolVLM2 fails exactly as the source said it would:

LOAD FAILED: HuggingFaceTB/SmolVLM2-256M-Video-Instruct
  Unsupported Hugging Face Transformers -CausalLM model class
  `SmolVLMForConditionalGeneration`. Please raise an issue.

That is from_causal_lm_name's bail arm, reached verbatim. The prediction made by reading the loader is the message the binary printed.

The 18.5 s generation is NOT a speed number. One cold item, one process, no pinning, no interleaving, no repeats, and it shares the box with a 1000-item benchmark run. It says "generation completes", nothing more. Speed belongs to Arm 2 and to step 6.

Gate 1.2 verdict — CLOSED

column SmolVLM-256M-Instruct (v1)
(a) vision tower SigLIP — candle has siglip.rs
(b) connector pixel-shuffle, scale_factor: 4 — the ~50-line variant
(c) LLM Llama — candle has llama.rs; mistral.rs types it as models::llama::Config
(d) tiling required yes — 17 tiles, measured
(e) mistral.rs serves it YES — loaded and generated a correct answer, with one recorded one-line patch

Model chosen: HuggingFaceTB/SmolVLM-256M-Instruct. It is the only Tier-3 candidate that has a published row to reproduce, the only one the house Rust stack can serve today, and the cheapest honest port if that stack is ever the wrong seam. 513 MB of weights, Apache-2.0.

And the plan's original pick would have failed on both counts — no published OCRBench row anywhere, and unloadable by mistral.rs. One afternoon of reading a loader and a config found that before a line of porting was paid for, which is the entire argument for having Gate 1.2 at all.


10. GATE 2 — the trait surface, DECIDED and LANDED (2026-08-21)

ffai-core 0.6.5 → 0.7.0. A breaking change to a published crate, made deliberately and now rather than later, which is the entire argument of Gate 2: every field here is cheap today and a semver break the day Argus has users.

Blast radius was two struct literals, both in-repo (ffai-bench/src/vlm.rs, ffai-cli/src/main.rs) plus the Argus stub. That number is the reason to do it today.

The determinism requirement is now STRUCTURAL, not documentary

Gate 2's headline decision. VlmOptions does not carry temperature: Option<f32> beside seed: Option<u64>, because that shape lets a caller set one and forget the other and get output nobody can reproduce — silently, and only discovered when someone tries to re-run a ledger line.

#[derive(Debug, Clone, PartialEq, Default)]
pub enum Decoding {
    #[default]
    Greedy,                       // deterministic by construction
    Sampled {
        temperature: f32,
        top_p: Option<f32>,
        top_k: Option<usize>,
        seed: u64,                // NOT Option. There is no unseeded variant.
    },
}

There is no way to spell "sampling without a seed". The illegal state has no representation, so the v1 requirement cannot be violated by a caller who simply did not read the docs — the same move rusty-memory-model describes as making illegal states unrepresentable rather than guarding them at runtime. #[default] on Greedy puts the default in the type rather than in a hand-written impl that could drift from what its doc comment promises.

The full v1 surface

field why
prompt: Option<String> unchanged. Read by describe_image only — describe takes text from the prompt's own parts, because there position matters and a flat field cannot say where the text goes
system_prompt: Option<String> engines without a template slot must ignore it, never concatenate it into the user turn
decoding: Decoding above
max_new_tokens: Option<usize> unchanged
stop: Vec<String> stop strings. EOS is deliberately absent — that is the tokenizer's, and an engine needing to be told its own EOS is misconfigured
repetition_penalty: Option<f32> sits beside decoding, not inside Sampled: it is a logit transform, applies to greedy too, and small models loop under greedy more than under sampling

Multi-image and interleaving: the general path is the REQUIRED one

pub enum VlmPart<'a> { Text(&'a str), Image(&'a ImageBuffer) }
pub struct VlmPrompt<'a> { pub parts: Vec<VlmPart<'a>> }

pub trait VlmEngine: Send + Sync {
    fn info(&self) -> EngineInfo;
    fn describe(&self, prompt: &VlmPrompt<'_>, opts: &VlmOptions) -> Result<String>;
    fn describe_image(&self, image: &ImageBuffer, opts: &VlmOptions) -> Result<String> {
        self.describe(&VlmPrompt::single(image, opts.prompt.as_deref()), opts)
    }
    fn describe_video(&self, frames: &[VideoFrame], opts: &VlmOptions)
        -> Result<Vec<TimedSegment<String>>>;
}

Two decisions worth stating:

  • describe is required and describe_image is derived, not the reverse. An engine that implemented only the single-image case would still compile against a multi-image prompt and would then silently answer using the first image, or the last, or a concatenation. Making the general case the obligation turns multi-image support into a compile error instead of a runtime surprise.
  • Parts are borrowed. An ImageBuffer is a decoded raster and a tiling VLM re-encodes it into 17 tiles anyway; cloning it to build a prompt would copy megabytes to say "this image goes here".

Order is the payload. "Compare the first image to the second" is not expressible as a set of images plus a question, and a model handed them in the wrong order answers the wrong question fluently — the §7 finding in miniature.

v1 EXCLUSIONS — written down, as Gate 2 requires

Absences are decisions here, not oversights:

excluded reason
Streaming changes the return type of every method — a trait redesign, not a field. Waits for a consumer that needs it
Grounding (region-in, boxes-out) Diana already returns boxes; a second, weaker box source needs a reason beyond "the model can"
Structured / JSON output worthless without constrained decoding — "please reply in JSON" is a request, not a guarantee. v2, not never: mistral.rs ships grammar-constrained decoding, which makes it cheap when it lands
Token-level confidence (logprobs) genuinely valuable (Carmenta's verifier uses the analog), but only meaningful once an engine exists to produce it honestly
Conversation history VlmPrompt already expresses an interleaved turn sequence; a typed history is a chat-session concern and Argus is a media op

And deliberately NOT options at all, because they belong to the engine: the chat template, the special vision tokens, and M-RoPE's time axis. Those are properties of a checkpoint. Exposing them would invite a caller to set them wrong — and §7 measured what that costs: 43 of 50 answers changed on identical weights, from prompt formatting alone, with no error raised anywhere.

Verified, not asserted

Five tests in ffai-core::engine::vlm_surface_tests:

  • the_default_decoding_is_deterministic — a caller who sets nothing gets greedy
  • sampling_always_carries_a_seed — records that the alternative does not compile
  • describe_image_routes_through_describe — the convenience path is not a second, divergent implementation
  • a_prompt_with_no_instruction_is_just_the_image
  • interleaved_order_is_preserved — the sequence an engine receives is the sequence it was given

353 workspace tests green; clippy pedantic + nursery clean.


11. STEP 3 — the vision tower, oracle-matched (2026-08-21)

The gate was "tensor match to tolerance … a mismatched tower cannot be debugged later through generated text." It passes.

stage comparison (candle vs transformers, same input):
  vision_out   n=786432  std=0.6134  max_abs=1.717e-4 (2.80e-4 of std)  SNR=104.8 dB
  connector    n=36864   std=4.9491  max_abs=1.526e-4 (3.08e-5 of std)  SNR=113.2 dB

Both stages agree to float-reassociation levels. crates/ffai-argus/src/vision.rs

  • tests/vision_oracle.rs; the reference side is corpora/refs/dump_smolvlm_vision.py.

Gate 1.2's pick paid for itself here

The only code written was the connector:

piece source
SigLIP encoder — patch embed, 12 blocks, post-LN candle, unmodified
weight loading VarBuilder, no adapter — SmolVLM's tensor names are SigLIP's
pixel-shuffle + projection ~25 lines here: a reshape and one matmul

The tower was correct on the first run. That is not luck: Gate 1.2 chose this model because candle already had SigLIP and Llama, and a triage that picks the cheapest honest port produces a port that is cheap.

The failure that was mine, not the port's

The first run reported max_rel = 2.686 and failed — on an element whose reference value was 9.0e-7. Absolute error there was 2.6e-6, and the SNR was already 103.5 dB. The tower was right and the gate was wrong, in exactly the way the docstring on that very function warned about: relative error explodes on values legitimately near zero, and a 1024x768 activation has thousands of them.

The gate is now the pair codec-optimize prescribes for float paths:

  • max absolute error scaled by the tensor's own std — "2e-4" means nothing until you know whether that stage's std is 0.19 or 15.2, and both occur in this tower;
  • SNR in dB, which no single outlier can move.

Max relative error is still reported, restricted to elements above 1 % of std, because it is informative. It is not the verdict. Worth recording because the near-miss was a tolerance choice that would have sent someone hunting a non-existent bug in a correct port.

What step 3 deliberately did NOT cover

The step says vision tower only, and the test feeds the reference's own pixel_values rather than our preprocessing. That is codec-bringup-decoder's per-stage isolation law: feed each stage the reference's previous-stage output, so a mismatch localises to one brick instead of three.

brick status
SigLIP tower + connector ✅ matched
preprocessing (image → pixel_values) ❌ its own gate
tiling (the 17-tile grid + positions) ❌ its own gate

One tile was compared, not 17. The tower runs per tile with identical weights and position embeddings, so one tile exercises it completely — but that is an argument, not a measurement, and it is recorded as such.

Numbers this produced that the port needs

  • 17 tiles × 64 tokens = 1,088 image tokens per image. The tower runs 17 times per image, so the encoder — not the decoder — decides step 6's speed gate.
  • post_layernorm and vision_out share a checksum: last_hidden_state is the post-LN output, one fewer stage for the port to get wrong than the stage list suggests.
  • layer_11 std is 15.2 against layer_06's 0.67 — a ~23x jump in the final block before the LN pulls it back to 0.61. That is where an f32-vs-bf16 choice or a missing residual scale would first show up.

12. GATE 1.1 — PASSED (2026-08-21)

bench bench-vlm-1787345516 · corpus argus-ocrbench-v1 (9e5498e5501e) · 1000 items

IMPLEMENTATION           OCRBENC SCORE01  IT/S_WARM  IT/S_E2E  LOAD_S  PEAK_MiB   CLIPS
  smolvlm-256m-vlmevalkit  525.00   52.50       0.10      0.10   66.37      2607 1000/1000
Published (SmolVLM-256M-Instruct model card) OCRBench 52.6 = 526/1000
Measured (VLMEvalKit through ffai bench vlm) 525.00/1000 = 52.50
Delta −1 item in 1000, −0.10 points
Pre-registered band (§9) 496–556 → PASS

The band was ±3 points and the reproduction came in thirty times tighter than that. 1000/1000 items answered, 1000 scored — work-count parity on both sides, so the number is over the population it claims.

The band was written down before the run finished (§9), which is the only reason the result means anything. A tolerance chosen after seeing 525 would have been a rationalisation whatever it said.

What this licenses, and what it does not

Licensed: the scoreboard. VLMEvalKit, driven through ffai bench vlm against a hash-pinned corpus whose prompts and scorer are inside the fingerprint, reproduces a published row. Numbers taken through this harness can be trusted to mean what their labels say — which was the entire question Gate 1.1 exists to answer, and the one Carmenta's §32 got wrong for a year.

Not licensed: anything about FFai's implementation. This is Arm 1 — it prices the model. Arm 2 prices the port, and step 6 is where our engine gets a verdict. A passed Gate 1.1 is permission to start measuring, not a measurement.

The four gates read SKIP, correctly: Argus is still a stub, so this is a baseline-only run and the harness says so rather than inventing a verdict.

⚠ The speed and memory columns of THIS run are void

0.10 items/s, 66.37 s load and 2607 MiB are not admissible and must not be quoted. Across the 147 minutes of this run the same box also compiled mistral.rs twice, ran the vision-tower oracle dumps, and executed the candle oracle tests repeatedly — all of it work I started myself.

The SCORE is unaffected and that is not a hopeful assumption: decoding was greedy and deterministic, so contention changes when the answer arrives and not what it is. The timings are a different matter, and codec-measurement §1 and §15 are unambiguous that a number taken on a box with a known competing load is not a measurement. Recorded here rather than quietly dropped, because "the box got noisy" is a mood and "I ran two compilers alongside my own benchmark" is a cause.

A speed figure for Arm 1 needs a quiet box, pinning, and interleaving against Arm 2 — which is step 6's job, not this gate's.

Sequencing status after this

step state
0a harness ✅
0b Arm 1 (VLMEvalKit) ✅
0c Arm 2 (matched CPU runtime) ✅
1 Gate 1.2 port-cost triage ✅ SmolVLM-256M-Instruct
1.1 published row reproduces ✅ 525 vs 526
2 trait surface ✅ ffai-core 0.7.0
3 vision tower oracle-matched ✅ 104.8 / 113.2 dB
4 assembly + chat template ◐ tokens exact, splice bit-exact; mask/positions and the end-to-end token gate remain
5 decode loop ☐
6 describe_image + four gates, both arms ☐

13. STEP 4 — FINISHED (2026-08-21)

The gate was "a known image+prompt reproduces the reference implementation's output tokens" — output, not input. It passes.

inputs_embeds (1, 1142, 576)  max_abs(ours vs ref) = 2.060e-04

reference text: ' The image displays an abstract, multi-colored, psychedelic design.
                  The design features a series of concentric circles, each filled
                  with a different color. The colors'
ours      text: ' The image displays an abstract, multi-colored, psychedelic design.
                  The design features a series of concentric circles, each filled
                  with a different color. The colors'

PASS — 32/32 output tokens identical.

The bricks, and the gate each earned

brick gate result
connector tensor (step 3) 113.2 dB
chat template token ids exact
image-token expansion, 17 x 64 token ids exact
sequence assembly token ids 1142 / 1142
embedding splice bit-exact max_abs = 0
attention mask inspection all-ones — trivial because it is one un-padded sequence; batching would not be, which is why v1 excludes it
output tokens token equality 32 / 32

Why the output gate is not a tautology

The splice test proves our merge is bit-exact given the reference's own tensors. Zero error in, zero error out — necessary, and trivially passed end to end.

The real question is different. Our vision tower carries ~1e-4 against the reference (step 3: 104.8 dB, reassociation rather than a defect), and composed through connector and splice our inputs_embeds sits 2.06e-4 away. Greedy decoding is an argmax: a small perturbation can flip a token, and a flipped token changes the answer — the "plausible but degraded" failure arriving through accumulated numerics instead of a structural mistake.

So corpora/refs/check_smolvlm_tokens.py feeds OUR embeddings to the REFERENCE's decoder. 32 argmaxes, zero flips. Our half is numerically close enough that the decoder cannot tell the difference — a strictly stronger claim than any tensor tolerance we could have argued for, and it needed no tolerance at all.

Isolation held throughout: tiles come from the reference's pixel_values and the decoder is the reference's, so a failure could only have been our tower, connector or assembly.

The bug this step found, and why reading could not have found it

The first assembly produced 1139 tokens against 1142. The gate pointed at index 267 — the end of row 1 of the tile grid — where the reference had a \n we did not.

Every row of the tile grid is newline-terminated, including the last. The earlier structural read had seen a single ĊĊ token before the thumbnail and concluded "one separator". There are two newlines there: the final row's terminator plus the separator, which the tokenizer merges into one token. That reading was entirely consistent with a wrong model, and only comparing ids could separate them. Three terminators were missing and visible; the fourth was invisible by construction.

Had it shipped, every image block after row 1 would have sat one position off. No crash — just fluent, confident, differently-scored answers.

Sequencing

step state
0a / 0b / 0c ✅ (Gate 1.1 passed, §12)
1 Gate 1.2 triage ✅ SmolVLM-256M-Instruct
2 trait surface ✅ ffai-core 0.7.0
3 vision tower ✅ 104.8 / 113.2 dB
4 assembly + chat template ✅ 32/32 output tokens
5 decode loop (ours, or mistral.rs) ☐ next
6 describe_image + four gates, both arms ☐
7-pre streaming frame ingest · 7 video ✅

What step 4 did NOT cover, deliberately: preprocessing (image → pixel_values) and tiling (choosing the 4x4 grid). Both were isolated out so this gate could attribute a failure; both still need their own.


14. The CONTENT PATH — what Argus can actually decode

Surveyed rather than assumed, because "the toolkit reads images" is the kind of claim that hides a format nobody wired.

Stills — ffai_media::load_image

format decoder state
PNG (incl. grayscale) rusty_png 0.3 — ours, crates.io ✅ gated byte-identical to upstream png
JPEG (baseline + progressive) rusty_jpeg 0.3 — ours, crates.io ✅ gated within 3/255 of libjpeg
WebP — ❌ see below
AVIF / TIFF / BMP / GIF — ❌ errors with a named message, not a panic

Dispatch is on MAGIC BYTES, extension only as fallback, and that is not fastidiousness: 169 of OmniDocBench's 316 English pages are JPEGs named .png, and every one failed with "Invalid PNG signature" — producing an empty result that scored as 100 % CER and contaminated a whole benchmark run before anyone read stderr. The file's contents are authoritative; its name is a hint.

WebP is closable with house crates, and the shape of the fix is known. rusty_webp 0.1.1 and rff-codec-webp 0.2.0 are both on crates.io — so no git dependency and no publication problem. Two caveats found by reading them rather than by assuming:

  • rusty_webp 0.1.1 cannot be used directly. Its lib.rs is exactly pub mod vp8; — the WebPDecoder in decoder.rs is present in the crate but not exported, so the container decoder is unreachable from outside.
  • rff-codec-webp 0.2.0 exposes only register(&mut CodecRegistry), i.e. it plugs into rff's registry seam — which is precisely the indirection ffai-media deliberately moved off for still images (its manifest records the reason: a grayscale round-trip measured 2.36x slower on Carmenta's corpus, plus the publication constraint).

So WebP costs either an upstream one-line export in rusty_webp, or taking rff-codec + rff-core back for stills. Named and priced, not silently skipped — and until it lands, load_image says so in its error rather than returning something empty.

Video — ffai_media::stream_frames

container demuxer state
mp4 / mov / m4v rff-format-mp4 ✅
mkv / webm / mka rff-format-mkv (registers as matroska) ✅
avi rff-format-avi ✅
ts / m2ts / mts rff-format-ts (registers as mpegts) ✅
video codec rusty_h264 — decoder bit-exact vs Cisco openh264 ✅

No libavformat and no libavcodec anywhere on the path.

★ A stale claim in this plan, corrected

§3.3 and step 7-pre say sample_frames "returns every frame in memory at once — one minute of 1080p is 10.4 GiB" and that streaming ingest is unbuilt. That is no longer true. ffai_media::stream_frames exists and impl Iterator for VideoStream { type Item = Result<VideoFrame>; } — a real streaming iterator. sample_frames is now stream_frames(path, fps)?.collect(), i.e. the materialising call is a thin convenience over the streaming one, and its own doc says "prefer stream_frames".

Step 7-pre is therefore largely already done, and what remains for video is a CLI verb driving it plus the frame-sampling policy — not the ingest rewrite the plan budgeted for. Checked because a plan that prices work already finished will spend the budget anyway.

What Argus still needs on this path

Decoding a file is not the same as feeding the model. Between load_image and the tower sits preprocessing, and its parameters are now pinned from preprocessor_config.json:

step value
convert to RGB do_convert_rgb: true
resize longest edge 2048 — so a 512² image is scaled UP
resample filter 1 = LANCZOS
split into tiles max_image_size.longest_edge: 512 → 4x4 = 16
global thumbnail + 1 → 17 tiles, matching every earlier count
rescale 1/255
normalize mean 0.5, std 0.5 → [-1, 1]

That explains the 17 tiles arithmetically for the first time: the input is upscaled to 2048² and cut into sixteen 512² tiles, plus a thumbnail.

Lanczos is on the critical path and is not in the tree. Carmenta has resize_bilinear and Catmull-Rom resize_bicubic (each chosen with a measured reason), but no Lanczos, and substituting a different filter changes every pixel_values and therefore everything downstream. It is a resampling kernel — codec work — and it gets its own gate against the reference's pixel_values rather than being waved through.

RESOLVED (§16). It got that gate, and needed a stronger one than "against the reference's pixel_values": a float Lanczos matching PIL to one quantisation level passed every tensor tolerance and still produced 8/32 correct tokens. What was actually required was PIL's fixed-point path — i32 coefficients at 1<<22, integer accumulation, and a u8 intermediate between the two passes — gated bit-identical by resize_oracle.rs.


15. GATE 5 — PASSED, and the content path measured (2026-08-21)

The gate was "greedy decode matches reference greedy decode." It passes twice.

decoder-only (reference embeddings in):
  decode:   32/32 tokens identical
whole pipeline (our tower + connector + assembly + decoder):
  pipeline: 32/32 tokens identical
finished in 44.18s

The second line is the strong one: our entire Rust half reproduces the reference's output token for token.

The route: a candle loop, not a mistral.rs call

The plan offers both. House doctrine says don't hand-roll an LLM SERVING loop on raw candle — and that rule is about serving. Argus needs a greedy prefill plus one-token-at-a-time decode for a single sequence, which is what mercury::asr::whisper_candle already does in this tree. candle supports it directly: models::llama IS SmolVLM's text tower (text_config.model_type is literally llama), Llama::forward_input_embed takes INJECTED embeddings — exactly what a VLM needs and what forward cannot do — and llama::Cache is the KV cache.

Three things decided it:

  1. Publication. mistralrs is on crates.io at 0.8.1, but the version proven to serve SmolVLM here is 0.9.0 from git, and cargo publish refuses a git dependency. ffai-media's manifest records that this exact constraint once made every downstream FFai crate unpublishable and had to be undone; taking it now would re-import that problem.
  2. It composes with work already gated — steps 3–4 already produce correct inputs_embeds; only the loop was missing.
  3. ~100 lines against a large optional dependency, for a 256M model.

mistral.rs is not rejected. It stays the documented path for the serving concerns it owns (quantization, grammar-constrained JSON — §2.3's v2 item), it is proven to load and generate for this checkpoint (Gate 1.2), and the reserved mistralrs-backend feature is still there.

Weight names differ (model.text_model.* vs candle's model.*); handled with VarBuilder::rename_f, which rewrites the lookup rather than copying tensors, so the checkpoint stays memory-mapped.

⚠ Debug builds make this work impossible to measure

The first run of this gate was killed after 15.4 minutes, incomplete. The same two tests in --release finish in 44 seconds. That is >20x, and it is not a curiosity: a debug candle build makes a 256M model's forward pass slow enough to look like a hang, and every "is it stuck?" judgement made in that state is worthless. Every Argus test that touches a model must be run --release. Recorded because the symptom (a test running for 15 minutes) invites the wrong diagnosis.

★ The content path: built, measured, and NOT yet good enough

Steps 3, 4 and 5 all fed the tower the reference's pixel_values, so that a failure could be attributed. crates/ffai-argus/src/preprocess.rs is the brick they isolated out — Lanczos-3, the tile grid, rescale/normalize — with the spec pinned from preprocessor_config.json (§14).

Against the reference's own tensor:

stage result
geometry (2048 upscale, 4x4 grid, +thumbnail = 17) ✅ exact
thumbnail (Lanczos 2048 -> 512, DOWNSCALE) max_abs 7.843e-3, SNR 60.2 dB
tiles (Lanczos 512 -> 2048, UPSCALE) max_abs 7.843e-3, SNR ~50 dB

7.843e-3 is exactly 1/127.5 — one quantisation level of 255, everywhere. So our Lanczos agrees with PIL to within one level in both directions, which is a legitimate resampler match and not an exact one (PIL uses fixed-point integer rounding).

And one level is enough to change the answer. Running the full content path — formula image → our preprocessing → our tower → our assembly → our decoder:

content-path: 8/32 tokens match, first divergence at step 5
  ours      : [354, 7545, 1157, 351, 253, 26591]
  reference : [354, 7545, 28,   4785, 29, 20296]

That is the answer to a question no tensor tolerance could settle. The tower's 2.06e-4 flips nothing across 32 argmaxes; preprocessing's 7.8e-3 flips a token at step 5. Same pipeline, ~40x the perturbation, qualitatively different outcome.

It is recorded as an #[ignore]d test carrying the measurement in its reason string, not as a passing test and not as a silent omission. Gate 5 is unaffected — preprocessing was explicitly outside steps 3–5 — but step 6 cannot be claimed until this closes, because step 6 is where describe_image takes a real file.

The fix is a known quantity: match PIL's fixed-point Lanczos rather than its floating-point idealisation. That is codec work with a ready-made oracle, and it now has a failing test waiting for it.

Sequencing

step state
0a/0b/0c, Gate 1.1 ✅ 525 vs 526
1 Gate 1.2 triage ✅ SmolVLM-256M-Instruct
2 trait surface ✅ ffai-core 0.7.0
3 vision tower ✅ 104.8 / 113.2 dB
4 assembly + template ✅ 32/32 output tokens
5 decode loop ✅ 32/32, both isolated and composed
6 describe_image + four gates ☐ blocked on the preprocessing gap above
7-pre streaming ingest ✅ already exists (§14)
7 video ☐ needs a CLI verb + sampling policy

SUPERSEDED — this table is the state on the day step 5 landed. The preprocessing gap closed the same day (§16): the float resampler was replaced with PIL's fixed-point path, the content path went 8/32 → 32/32, and the #[ignore] came off. Steps 6 and 7 are both done — §16 and §17. Left as written because a campaign log that edits its own history cannot be used to check anyone's reasoning, including mine.


16. GATE 6 — describe_image end to end (2026-08-21)

question : What is written in this image?
reference: "The image displays an abstract, multi-colored, psychedelic design.
            The design features a series of concentric circles, each filled with
            a different color. The colors"
ours     : "The image displays an abstract, multi-colored, psychedelic design.
            The design features a series of concentric circles, each filled with
            a different color. The colors"

Byte-identical, through the public surface only — ImageBuffer in, String out, SmolVlm::describe_image in between. Every earlier gate reached inside and wired the pieces together the way it believed the engine does, which is the right shape for attributing a tensor mismatch and the wrong shape for catching a plumbing mistake.

★ How the blocker actually fell: a refuted hypothesis, read sideways

§15 left step 6 blocked on preprocessing: our Lanczos matched PIL to one quantisation level and that flipped a token at step 5 (8/32). The stated fix was "match PIL's fixed-point path", and that is what was built — i32 coefficients at 1<<22, integer accumulation, and the detail that matters most, a u8 intermediate between the horizontal and vertical passes. PIL resamples into an 8-bit image and then resamples that, so the round-off happens twice on purpose; keeping f32 between the passes is "more accurate" and produces a different picture.

That took the tiles from ~50 dB to this:

tile max_abs
r2c2, r2c3, r3c2, r3c3 5.9e-8 — f32 epsilon, i.e. exact
every other tile 7.843e-3 — still one level

The four exact tiles are exactly the four that do not touch the image border. That geometry says the kernel is right and the boundary handling is not — so the next move was a single-variable instrument: resize_oracle.rs, u8 in and u8 out against PIL's own raw output, with the differences bucketed by distance from the edge.

It came back zero differences, both directions. Our resampler is bit-identical to PIL.

Which refutes the hypothesis — and the refutation is the finding. If we match PIL and we do not match the reference, the reference is not PIL. Checking directly: PIL's own upscale disagrees with the reference's pixel_values on ~20 pixels per border tile out of 786,432 (0.0025%), at scattered interior coordinates rather than along an edge. Those are ULP-boundary ties between two independent fixed-point implementations — AutoProcessor defaults to the torchvision-backed fast processor, which reimplements the same 1<<22 algorithm and rounds a handful of coefficients the other way.

So the gap was never a defect in ours. It is a difference between two references, and the only instrument that can say whether it matters is token equality:

content-path: 32/32 tokens identical    (was 8/32)

the_whole_content_path_reproduces_the_reference_tokens is no longer #[ignore]d.

The transferable part: the residual that flipped a token was not the ~20 tie-break pixels — it was the several-hundred-thousand one-level pixels that the float path had everywhere, and those are gone. A "close enough" resampler is not close enough when its output is argmaxed 32 times.

Three plumbing defects the composed gate caught

None of these is visible in a brick test, and each of them ships silently.

  1. A KV cache that survives a call. candle's llama::Cache has no public reset and its kvs are private, so the obvious implementation — build the cache at load, reuse it — makes the SECOND caption depend on the first. In production that presents as "the captions are fine until you batch a directory." Fixed structurally: TextDecoder keeps a pristine Cache and clones it back at the top of generate, so a caller cannot forget. Gated by caption → different prompt → caption again → same answer.

  2. A constant measured on the wrong workload. The CLI capped candle's rayon pool to 4 threads for Diana, on a real measurement: 21% less peak RSS at identical speed. But those are a 36 ms detector's numbers. Argus is seventeen 512x512 SigLIP tiles and a 1142-token prefill — ~28 s of dense f32 matmul. Measured on one caption, ABBA-interleaved, quiet box:

    threads runs (ms) min
    4 (the Diana cap) 38696, 36110, 35639, 36596 35639
    24 (all cores) 27497, 28118, 28017, 28550 27497

    1.29x — the cap was costing Argus 23% of its speed, no overlap between the groups. And it buys back 22 MiB against a ~1400 MiB working set: 1.5%, for a fifth of the throughput. The cap now belongs to the commands it was measured on (Detect/Depth, and bench detect|depth). A constant measured on one workload does not transfer to another with a different bottleneck.

  3. The comparison key named the engine, not the checkpoint. vlm.rs built its config string from info.name (smolvlm), while every other task names a checkpoint — tiny.en/greedy, yolo26n/e2e-640sq. smolvlm is equally true of the 500M checkpoint, whose numbers are not comparable to the 256M row. Now mirrors the ASR precedent, including the part that matters: an unrecognised engine returns None and its quality gate SKIPS rather than being compared against a reference it may not match.

What the engine is

SmolVlm in crates/ffai-argus/src/engine.rs, EngineStatus::Stable — defined in ffai-core as "oracle-gated against a reference implementation", which steps 3-6 earned. Registered as smolvlm; ffai caption and ffai bench vlm both reach it. Weights resolved through the ffai-models manifest seam (models/smolvlm-256m-instruct.toml), never a hardcoded HF cache path, and loaded lazily so ffai --help does not read 1 GB of safetensors.

Content-path coverage, gated rather than asserted: Rgb8 passes through, Gray8 is replicated across three channels (SigLIP has no grayscale variant), and Rgba8 drops alpha rather than compositing it — compositing needs a background colour and inventing one changes the picture. The test proves the consequence rather than the code: an opaque RGBA image must caption identically to its RGB original. A truncated buffer names its shortfall instead of slice-panicking three stages later inside the resampler.

Non-square images get their own gate too, because every fixture in the crate is 512x512 — which makes rows == cols and hides any place the two are swapped. A transposed grid does not error; it produces a valid prompt of the right token count describing the image sideways.

The four gates, both arms — argus-ocrbench-lite-v1, 50 items

Clean box, references and engine in one run, nothing else building.

IMPLEMENTATION            OCRBENCH  SCORE01  IT/S_WARM  LOAD_S  PEAK_MiB  CLIPS
> smolvlm (ours)              6.00    12.00       0.08       -      1901  50/50
  smolvlm-256m-vlmevalkit    40.00    80.00       0.20   20.18      2604  50/50
  smolvlm-256m-transformers   6.00    12.00       0.19   15.01      2371  50/50
gate verdict
correctness PASS 50/50 clips processed
quality PASS engine 88.00% vs matched reference 88.00% — an exact tie
speed FAIL 0.08 vs 0.20 it/s — 2.4x slower
footprint PASS 1309 MiB steady vs 1852 — 0.71x

verdict: not claimable yet, and that is the honest state: a skipped gate is never a pass, and neither is a failed one.

The quality result is stronger than the tie suggests

Two implementations can land on the same aggregate while disagreeing on half the items in opposite directions, so the aggregate is a weak instrument for "does our port compute the same thing?". Comparing the answer strings item-by-item against the matched reference:

EXACT string agreement: 49/50 (98.0%)

the one disagreement:
  [13] ref : 'There is text in the image.'
       ours: 'There is text written on a green color poster.'

49 of 50 answers are byte-identical to PyTorch's.

⚠ Arm 1 and Arm 2 disagree, and that is not an implementation difference

Arm 1 scores 40 where Arm 2 scores 6 on the same 50 images and the same checkpoint. The predictions say why:

item 0 item 2
Arm 1 (VLMEvalKit) "Pen." "Chain."
Arm 2 (plain, pinned) "There is text in the image." "There is text in the image."

VLMEvalKit wraps every question in OCRBench's own terse-answer preamble; Arm 2 sends the corpus prompt bare. Same weights, same decoding, wildly different scores. Our engine matches Arm 2's configuration — which is why the quality gate compares against Arm 2, and why agreement with Arm 1 is 0/50 and that number means nothing about our port. This is the same hazard §0b recorded from the other side: the prompt wrapper, not the model, is what a leaderboard row is made of.

Speed: 2.4x slower, and the two obvious causes are REFUTED

Recorded so the next person does not spend a week on either.

Hypothesis 1 — we call the tower wrong. describe runs 17 batch-1 forwards where PyTorch runs one batch-17. CPU GEMM amortises weight packing across a batch, so this looked like the whole story. Measured as a chunk sweep (equality checked first — every chunk produces a bit-identical block), interleaved, min of 6:

chunk min (ms) vs 1
1 22399 1.000x
2 22034 1.017x
4 21601 1.037x
8 20894 1.072x
17 21132 1.060x

1.07x, and chunk 17 is worse than chunk 8. Refuted. And declined even at 1.07x: chunk 8 costs a 8 x 12 x 1024 x 1024 f32 attention tensor — +384 MiB — against a footprint gate we currently pass at 0.71x. Trading a gate we win for 7% of a gate we lose by 140% is not a trade.

Hypothesis 2 — candle's CPU matmul is slow. Measured on the exact shapes SigLIP runs, same box, same f32:

shape candle PyTorch
(1024,768)x(768,768) 660.2 697.3
(1024,768)x(768,3072) 589.1 680.6
(1024,3072)x(3072,768) 610.6 683.1
(8192,768)x(768,768) 701.7 690.7

Parity. Refuted.

Which relocates the problem, and that is the finding. SigLIP-base is ~212 GFLOP per tile; 17 tiles is ~3.6 TFLOP, which at the measured ~660 GFLOP/s should take 5.5 s. The tower takes 22 s. So roughly three quarters of vision-tower time is not in the multiplies at all — it is elementwise and layout work (layernorm, softmax, GELU, transposes, contiguous() copies). That is a candle CPU-backend characteristic, not an Argus call-shape one, and no restructuring at this level will touch it.

One arithmetic check, because the numbers looked impossible: the tower measures 22 s per image while the bench reports 12.5 s per caption. Not an instrument fault — the fixture is square (17 tiles) and the corpus is not. Measured tile distribution over the 50 items: 5 tiles x14, 9 x32, 13 x3, 17 x1 — mean 8.28, i.e. 0.487 of the fixture. 22 s x 0.487 ≈ 10.7 s plus prefill ≈ 12.5 s. Closes.


17. GATE 7 — video: sampling, windowing, and a timed track (2026-08-21)

$ ffai caption -i walk.mp4 --prompt "What is happening in this video?" --fps 10 --window 8
  16 frames sampled at 10 fps -> 2 captions
[    0.00 -     0.80] The image depicts a bustling urban street scene ...
[    0.80 -     1.63] The image depicts a bustling urban street scene with a variety of people ...

ffai caption now takes video as well as stills, --srt/--vtt/--json included via Transcript's own renderers.

★ The bug this step existed to find: stream_frames returned ONE frame

Step 7-pre worried that sample_frames materialised whole clips. §14 found that already fixed — stream_frames is a real Iterator. What nobody had checked is whether the fps argument worked.

It did not. The decimation computed its source rate as

let src_fps = f64::from(tb.den) / f64::from(tb.num);   // time_base!
let stride  = (src_fps / fps).round().max(1.0) as usize;

A time base is a clock TICK rate, not a frame rate. MP4 commonly uses 1/12800, so stream_frames(path, 1.0) asked for one frame per second and computed a stride of 12800 — returning exactly one frame from every clip in the corpus, at every fps, forever.

It is quiet in the worst possible way: one frame is a perfectly good frame. Nothing errors, the caller gets a plausible VideoFrame, and a per-frame captioner produces a perfectly reasonable caption of it. The defect only became visible when Argus asked for a window and kept being handed a single image.

And the test that should have caught it was green the whole time:

assert!(some.len() < all.len(), "no decimation happened");   // 1 < 48 ✓

Any amount of decimation satisfies that, including 12800x. This is the rusty_dev law verbatim — a green test can test the wrong scenario — and the fix is not just the code:

code decimate by timestamp deadline, not by a stride. Needs no frame rate at all — it reads the timestamps the container already carries — and stays correct on variable-frame-rate sources, where no single stride can be right
test assert the rate: consecutive kept frames at least one interval apart, count within ±50% of duration x fps, and oversampling returns every frame

Measured after, on a 1.6 s / 48-frame clip:

--fps 1 2 5 10 30 0 (all)
frames 2 4 8 16 47 48

and the kept timestamps land on a clean grid: 0.00 0.20 0.40 0.63 0.80 1.00 1.20 1.40 at 5 fps.

★ A gate I left failing, and the correction

preprocess_oracle's two tensor tests asserted max_abs == 0.0 after the fixed-point resampler landed. They did not pass, and I moved on — the content path's 32/32 and the other suites were green, and I reported the suite green on that basis. It surfaced on a full-workspace sweep. Recording it because the wrong assertion is instructive.

Exact zero was never attainable against this fixture, and demanding it was demanding that we disagree with PIL. Our resampler is bit-identical to PIL (resize_oracle, zero differing pixels both directions); the fixture came from AutoProcessor, which defaults to the torchvision fast processor — a second fixed-point implementation that breaks a handful of coefficient ties the other way.

But loosening to "within one quantisation level" would have been worse than useless: the float resampler was within one level too, everywhere, and it produced 8/32 tokens. Magnitude alone cannot separate the two.

What separates them is HOW MANY values differ, so the gate now bounds both:

tile max_abs values differing
r2c2, r2c3, r3c2, r3c3 (interior) 5.9e-8 0
every border tile 7.843e-3 (one level) 12 – 41 of 786,432 (≤0.005%)

with three assertions: max_abs ≤ one level, fewer than 0.1% of values differing (~20x the observed tie rate, ~1000x below a wrong filter, which differs everywhere), and the four interior tiles exact — they touch no border, so no window is truncated and no tie can arise there. That last one is the sharp one: it is the observation that localised the original bug, turned into a standing assertion.

The frame-sampling policy, stated

decision value why
sampling uniform, --fps (default 1.0) content-dependent — 1 fps is plenty for a lecture and misses the ball in a rally — so it is a knob, not a constant
brake --max-frames captioning is seconds per window; an hour of source at 1 fps is hours of work. The brake says so rather than letting a stray path run overnight
window --window (default 8) see below
tiling OFF for video see below
memory one window deep the CLI drives describe_video one window at a time, so peak memory is a function of --window, not of the length of the video

⚠ Why video turns tile splitting OFF

This is the decision that makes video possible at all, and the arithmetic is not obvious.

A still is split into 17 tiles so fine print survives: 1088 image tokens per image. The text tower holds 8192 positions. So a split window caps at seven frames — which is not a window, it is a slideshow with a memory problem.

Unsplit, a frame is one tile — 64 tokens — and the same 8192 positions hold a hundred. Sixteen frames of temporal context beats one frame of fine print when the question is "what happens in this clip", and the reference implementations make the same trade for the same reason.

The part that makes it safe: the unsplit tile is exactly the global thumbnail the split path already produces — same two resizes, same final 512x512 — not a second, subtly different route to a small image. The thumbnail is gated bit-exactly against the reference (§16), so the video path inherits that gate instead of needing its own, and video_oracle.rs asserts the two are byte-identical at three aspect ratios.

Pricing the prompt before doing the work

The token-budget check first ran after the vision tower, which meant asking for 200 frames cost four minutes to be told it would never fit. It now runs on tile_geometry — two integers per image, no pixels touched — so an oversized window is refused in milliseconds and the error names --window. A test asserts both the message and that the refusal takes under 20 s, because "the budget check moved back behind the tower" is a regression with no other symptom.

What is gated, and what is honestly NOT

There is no reference to diff against here, and saying so is the point. SmolVLM-256M-Instruct is an image model with no temporal training — its captions above say "The image depicts…", singular, because that is what it sees — and it has no published Video-MME or MVBench row. Inventing a quality number for it would be exactly the self-favouring scorer this campaign refuses (§5), so no video quality claim is made.

What does have right answers is the track, and that is gated (video_oracle.rs, 6 tests):

  • windows tile the timeline with no gaps and no overlap, and window starts land on the first frame of each window;
  • the remainder window produces a segment — dropping it silently loses the tail of every video whose length is not a multiple of the window;
  • --window 1 degenerates to per-frame captioning, exactly;
  • an empty clip is an empty track, not an error — "no frames decoded" is the caller's fact to report, and the CLI names it;
  • an oversized window is refused cheaply and by name;
  • the cheap geometry predictor agrees with real preprocessing at five sizes and both split modes — a predictor that drifts is worse than none.

A wrong timeline is the video defect that ships silently, because every caption in it still reads plausibly. That is the failure this gate is aimed at.

Sequencing

step state
7-pre streaming ingest ✅ already an Iterator (§14) — and its fps argument was broken; now fixed and gated
7 video ✅ CLI verb, sampling policy, windowed captions, timed track, 6 structural gates. No quality claim: the checkpoint is an image model with no published video row

18. What Argus is built ON — and the library that was never triaged

Asked directly: was the transformer stack written from scratch, or taken from cool-japan/trustformers? Neither, and the split is worth writing down because Gate 1.2's triage did not cover it.

The split

from candle-transformers hand-written in ffai-argus
models::siglip::VisionModel — the vision tower preprocess.rs — PIL fixed-point Lanczos, AnyRes tiling, normalize
models::llama::{Llama, Cache} — the text decoder vision.rs — the pixel-shuffle connector (Idefics3-specific; candle has none)
forward_input_embed — injected embeddings, what a VLM needs prompt.rs — Idefics3 prompt assembly + the embedding splice
generation::{LogitsProcessor, Sampling}, apply_repeat_penalty decode.rs — the KV-cache decode loop

candle supplied the two standard architectures. Everything Idefics3-shaped is ours, because candle has no SmolVLM and no Idefics3.

⚠ trustformers was not evaluated, and should have been named

Gate 1.2 triaged checkpoints — which model, and could mistral.rs load it. It did not ask "is there another transformers library we should be building on?", and cool-japan is on the house dependency ladder (OxiText, OxiNum, OxiProto, oxicuda), so the question was in-family and simply not asked. Recording the gap rather than back-filling a rationale that was not used at the time.

Evaluated now, three independent reasons it would not have been the pick:

  1. It does not carry the architectures. 49+ listed; SigLIP, Idefics3 and SmolVLM are not among them — its multimodal set is CLIP / BLIP-2 / LLaVA. The connector, the tiling and the prompt assembly would still have been hand-written, on a less-exercised base.
  2. Not published to crates.io. This is the same constraint that ruled out mistral.rs 0.9.0 (§15): cargo publish refuses a git dependency, and taking one once made every downstream FFai crate unpublishable.
  3. It uses its own tensor abstractions, not candle. §4 of the coding requirements exists for this: every engine shares candle's Tensor/Device so buffers move between Mercury, Carmenta, Diana and Argus without a copy or a format conversion. "Don't break the spine by introducing a second tensor type."

⚠ Two of those three reasons were WRONG. Measured properly, 2026-08-22

The list above was written from the README. Asked whether candle was actually better or merely incumbent, the honest move was to fetch the crate and run it. Two of the three objections did not survive:

claim verdict
"not published to crates.io" WRONG. It is: 0.2.0, Apache-2.0, 611 downloads, updated 2026-07-08
"does not carry the architectures" HALF WRONG. 74 architecture directories, and llama/ is a real 2,865-line implementation with no todo!(). But siglip/, idefics3/ and smolvlm/ are genuinely absent, so Argus's vision tower would still be ours to write
"its own tensor stack" TRUE, and softer than stated. Tensor is an enum over ndarray::ArrayD<T> — and it carries a #[cfg(feature = "candle")] Candle(candle_core::Tensor) variant, so an interop path exists

It also builds clean (1 m 52 s) and pulls fewer transitive dependencies than ffai-argus does (265 vs 333), with no aws-lc-sys. It is not vapourware.

So the README-level case was weak. What settles it is a measurement.

The number: GEMM at SigLIP's own shapes

Same box, same shapes, --release, min-of-8, against candle's already-measured figures (§16):

shape trustformers candle
(1024,768)x(768,768) 27.8 660.2 0.04x
(1024,768)x(768,3072) 24.8 589.1 0.04x
(1024,3072)x(3072,768) 28.0 610.6 0.05x

~23x slower. And this is its optimized path, not a strawman: at 1024 rows the shape clears MIN_SIZE_FOR_BLAS, so Tensor::matmul dispatches to blas_sgemm rather than to the Kahan-summation triple loop it keeps for small matrices.

Platform caveat, stated because it is load-bearing: blas_sgemm's OxiBLAS GEMM is #[cfg(target_os = "macos")]. On Windows and Linux it routes to scirs2_core::simd_ops instead. So this figure is the Windows/Linux path; macOS is unmeasured and could be materially better. A first attempt at this comparison also measured bare ndarray::dot (110 GFLOP/s) rather than their tensor, which flattered neither side accurately — the table above is the corrected run.

The answer to "is candle locked in because we use candle?"

No — and that is a measurement, not a preference. candle's CPU GEMM is at parity with PyTorch (589-702 vs 680-697, §16). Nothing here is being defended on sunk cost; the alternative is 23x slower on the arithmetic that dominates a vision tower.

The one objection that IS lock-in — a second tensor stack across Mercury, Carmenta, Diana and Argus — turns out not to be the deciding one. It does not have to be.

And it could not fix the thing we actually want fixed. Argus's 2.4x gap is not in the multiplies — §16 measured ~75 % of vision-tower time going to elementwise and layout work while GEMM sits at PyTorch parity. Moving to a stack whose GEMM is 23x slower cannot help that, whatever its elementwise path does.

Verdict: not worth testing further for Argus. Re-open it if siglip/ idefics3 land AND the GEMM gap closes on non-macOS — and if it does, the candle feature variant means interop is likelier than migration.


19. VISION PERFORMANCE — ten wins, four refutations (2026-08-22)

Vision was 77-82 % of a caption. It is now 2.84x faster, and the caption is 1.86x faster end to end — min-of-4, ABBA-interleaved, on the same image:

BEFORE (candle tower, 1 worker):  32148  27213  38887  36311   min 27213 ms
AFTER  (ours, 6 workers):         16756  17889  14627  15017   min 14627 ms

Every gate is unchanged: 32/32 tokens, a caption byte-identical to the reference's, 55 tests green.

The measurement that aimed everything

examples/vision_ops_probe prices one encoder layer at the real shapes: 61.9 ms — 50 % matmul, 50 % everything else. The matmuls are not the problem (657-798 GF/s, parity with PyTorch). The other half runs at 2-23 GB/s.

The cause is one line of candle: its CPU backend calls rayon for conv2d and nothing else. Every elementwise and layout kernel is single-threaded, so for half of every layer a 24-core box was running one core.

The ten

# win what it does measured
1 Thread cap scoped to Diana a 4-thread cap measured on a 36 ms detector was applied process-wide 1.29x (§16)
2 Per-tile threading 17 tiles are 17 independent single-threaded workloads — the one shape that fills the machine without touching candle 2.2-2.7x, bit-identical
3 Adaptive kernel parallelism intra-tile rayon stands down when tiles are already threaded; parallelism lives at exactly one level removes nested oversubscription
4 Fused QKV three (1024,768)x(768,768) matmuls become one (hidden, 3*hidden); one pass over xs instead of three 3 calls -> 1
5 ★ Attention scale folded into the q weights (q·kᵀ)*s == (q*s)·kᵀ, and q*s folds into Wq at load — so a 12.6 M-element pass per layer happens once, on 768x768 numbers, at startup deletes 15.6 % of a layer
6 GELU via the sigmoid identity tanh(z) = 2σ(2z)-1, trading tanhf for the cheaper expf fewer instructions/element
7 Parallel GELU 3.1 M scalar libm calls per layer, on one core, at 2.1 GB/s — slower than gelu_erf, which is meant to be the expensive one 19.7 % of a layer
8 Parallel softmax 12 288 independent rows of 1024, left on one core 7.0 % of a layer
9 Parallel Lanczos both resize passes; rows share only immutable input, so bit-identical preprocessing
10 Parallel LayerNorm 25 calls per tile at 9.7 GB/s, rows independent 2.1 % x 25

4-8 and 10 live in src/siglip.rs — our own encoder, gated by tests/siglip_parity.rs against candle's on the same weights. Measured alone (sequential tiles, no threading) it is 1.39x: 24635 -> 17748 ms.

It is not a bit-identity gate, and saying why matters. Folding the scale moves a multiply before a sum; the GELU identity adds one rounding. Demanding bit-identity would forbid the two changes most worth making. The bar is the one §16 established empirically — the tower's own 2.06e-4 flips none of 32 argmaxes — and the real gate never moved: 32/32 tokens, and the caption.

The four refutations — recorded so nobody rebuilds them

hypothesis verdict
Batch the tiles — one forward over 17 1.07x, and chunk 17 is worse than chunk 8. Costs +384 MiB of attention tensor against a footprint gate we PASS at 0.71x. The kernel stays single-threaded however long the array is; batching cannot fix a threading problem
candle's GEMM is slow Refuted. 589-702 GF/s against PyTorch's 680-697 — parity. The gap was never in the multiplies
Deduplicate identical tiles 0 duplicates in 225 real corpus tiles. Lanczos leaves even flat regions differing by a level, so the hash pass would never fire
Move to trustformers Its GEMM measures 23x slower than candle's on these exact shapes (§18)

Two of those looked like the obvious answer. Batching was the first thing tried and bought 7 %; the real win was the same tiles on different threads.

What is left, and where it is NOT

Vision is no longer the majority of a caption. What remains inside it is genuinely matmul — which is at PyTorch parity, so there is no easy multiple left at this level. The next honest targets are the text tower's prefill (one pass over 1142 tokens) and generate, neither of which this campaign touched, and both of which are now a larger share than they were.


20. VISION ROUND 2 — the stopwatch was the problem (2026-08-22)

Round 2 opened by chasing a change that had to be faster (less work per tile, same threading) and measured slower, three repeats disagreeing with each other. The box swings ±12 %, which is larger than most wins worth having.

So the unit of account changed: counters, not milliseconds. src/cost.rs counts matmul FLOPs and calls, elementwise visits, scalar vs vectorised transcendentals, bytes moved, and layout copies. Every one is exactly reproducible on any machine under any load. A win is a counter that went down.

★ Round 1 contained two regressions, and the aggregate hid them

Round 1 replaced candle's GELU, softmax and LayerNorm with rayon versions and measured a win on the tower. Priced individually (examples/kernel_ab), on a quiet box:

op candle ours parallel ours serial
GELU (1,1024,3072) 44.01 ms 3.03 ms (14.5x) 8.37 ms (5.3x)
softmax (1,12,1024,1024) 4.71 ms 11.74 ms (0.40x) 50.79 ms (0.09x)
layer_norm (1,1024,768) 0.64 ms 0.70 ms (0.91x) 1.35 ms (0.47x)

The serial column is the one that ships — the engine runs six tiles at once and the kernels stand down in that mode — so round 1 put an 11x regression on the exact path a 17-tile image takes. The tower A/B still showed a win because the scale-fold was paying for it.

Both are reverted. The kernels that survive replace expensive arithmetic (GELU's tanhf); the ones that merely added threads to a memory-bound pass lost, because a Vec round-trip is three passes where candle's op is one.

An aggregate win can contain a large regression. Round 1 measured the tower and never priced the pieces it had replaced.

The wins

# win evidence
1 Deterministic cost model counters reproducible run-to-run; asserted, not assumed
2 ★ Range-reduced polynomial exp in GELU 642 M scalar libm calls per image → 0, counter-proven
3 ★ AVX2+FMA, runtime-dispatched 2.30x over scalar, 20/20 sign test, bit-identical
4 One-copy QKV layout copy calls 3 → 1, bytes identical, 20/20 sign test, bit-identical
5 Softmax reverted to candle's recovers ~11x on the shipping path
6 LayerNorm reverted to candle's lost in both modes (0.47x / 0.91x)
7 ★ Zero-copy GELU via CustomOp1 the Vec round trip removed: copies 36 → 24 per tile, 604 → 302 MB (10.27 → 5.13 GB per image), counter-proven
8 src → out in ONE pass was to_vec() then modify in place — two extra passes over the whole tensor before the kernel starts. GELU parallel 2.30 → 1.08 ms
9 Uninitialised output buffer every element is written, so vec![0.0; n] was a discarded pass: 2.6 GB of pure memset per image, removed
10 SIMD hygiene closed oracle test, hoisted dispatch, per-arch note, non-x86 stub — see the audit below

GELU end state: candle 38.28 ms → 1.04 ms parallel (36.7x), 7.63 ms serial (5.0x). The four separate wins on one kernel are worth reading as a sequence, because each was invisible until the one before it was fixed:

parallel what was still wrong
candle's tanh GELU 44.0 ms scalar tanhf per element
ours, polynomial + rayon 3.03 ms Vec round trip on every call
+ zero-copy CustomOp1 2.30 ms copied the input before computing
+ src→out single pass 1.08 ms zero-init of a fully-overwritten buffer
+ uninitialised output 1.04 ms —

Wins 3 and 4 are judged by a sign test over interleaved rounds, not a ratio. On a box this noisy the ordering is trustworthy long before the magnitude is: 20/20 survives any amount of symmetric noise, while a min-of-3 does not.

Win 2 is what makes win 3 possible — a libm call cannot be vectorised. The polynomial is not merely cheaper per element; it is the thing that lets eight elements share an instruction.

Three refutations

hypothesis verdict
Blocked / flash attention — the (1,12,1024,1024) score matrix is 50 MB and ~200 MB of traffic per layer per tile, never needed whole 0.23-0.51x — 2 to 4x SLOWER, bit-identical. candle's batched matmul beats blocking at every tile size tried; per-call overhead swamps the saving even at 48 calls. The textbook answer, refuted
Padé tanh No viable threshold exists. Padé error is 1.2e-3 by `
Fused QKV was a speed win (round 1) 1.02x — neutral. The 767 GF/s that motivated it was one cache-warm matmul reported x3; three real calls give 594. Kept for the call reduction, no longer claimed as speed
A hand-written softmax — tried FOUR times Refuted at every step. 1. Vec round trip + scalar expf: 0.09x. 2. zero-copy + polynomial exp: 0.05x. 3. + target_feature: 0.06x. 4. + split accumulator to break the loop-carried sum: 0.04x. Each attempt fixed a REAL defect and it still lost by >10x — the three-probe rule, earned

★ The GELU/softmax contrast is the most transferable thing in this round. Same polynomial, same target_feature dispatch, same zero-copy hook, same author: 36.7x on GELU and 0.5x on softmax. The difference is entirely what candle was doing before — a scalar libm call per element in one case, a good vectorised kernel in the other. Replace expensive arithmetic; do not re-implement a good kernel. A win on one op is not a licence to rewrite its neighbour.

Two of those softmax attempts also exposed defects that were real and would have gone unnoticed in a kernel that happened to win:

  • round() has no SSE2 instruction. Outside a #[target_feature] function exp_poly's range reduction lowers to a call to roundf — so the "no libm calls" kernel was making 12.6 M libm calls per invocation. GELU never showed this because it was behind target_feature from the first line. One polynomial, two call sites, and only one of them compiled somewhere the polynomial could actually be arithmetic.
  • sum += e is a loop-carried dependency, and f32 addition is not associative, so LLVM keeps the loop scalar even inside an AVX2 function. The arithmetic closed exactly: 12.6 M x ~15 ops at ~1 op/cycle is ~63 ms, which is what it measured.

Three instrument faults, all caught by arithmetic that would not close

  1. Scalar and vectorised transcendentals folded into one weight — they differ 36x (75 M/s libm vs 2.7 G/s in a candle kernel). The conflated model predicted 32 s of transcendentals against a ~16 s tower.
  2. GELU's instrumentation silently did not apply — elem_calls read 61 where the code implies 73. A patch that fails quietly reports the old world.
  3. Global counters vs parallel tests — cargo test runs concurrently and two cost tests read each other's increments. Caught by a failing assert; fixed with a lock rather than by making the counters per-thread, since the tower is multi-threaded and per-thread totals would have to be summed by hand at exactly the wrong moment.

The AVX2 kernel, against the house SIMD discipline

codec-vectorize-kernel was loaded after the kernel was written, which is the wrong order; run against its checklist afterwards, it passed the reasoning and failed four hygiene items. All four are now closed, and the failures are worth naming because three of them are the ones that ship silently.

Step 0 — should this kernel exist at all?

test answer
redundancy eliminated first? yes — the scale-fold and the two reverts came first
does the scalar loop already auto-vectorise? no, and measured rather than assumed: the #[target_feature] twin is 2.30x, 20/20
can you NAME why the compiler can't? yes — and it is the skill's own AAC precedent

The named reason: a portable x86-64 binary compiles for the SSE2 baseline. exp has no SIMD instruction at any width, and the range reduction's round() needs roundps, which is SSE4.1. Both are above the baseline, so LLVM will not emit them without target_feature — and -C target-cpu=native is not an option for a published crate. This is precisely the case the skill separates from the sqrt counter-example, where the op is baseline and hand-SIMD reverts.

The four gaps, closed

  1. No test — only a probe. A benchmark comparing the two proves both are fast; only a test keeps them equal as the code changes. gelu_avx2_matches_scalar now asserts to_bits() equality over 4107 values spanning the near-zero region, the negative dip, both saturation shoulders and past the clamp — with a length deliberately not a multiple of 8, so the vector remainder is exercised rather than assumed. It passes bit-identical: LLVM did not contract the Horner chains differently between the two paths.
  2. Dispatch inside the loop. The skill's ★ finding is that dispatch placement can flip the sign of a result (0/16 vs 16/16 from moving one if), because a #[target_feature] function cannot inline into a caller without the feature. The decision is now hoisted out of the per-chunk closure. The boundary itself stays per chunk — #[target_feature] does not propagate into a closure, so a rayon fan-out cannot live inside one AVX2 function — and that is defensible under the skill's own amortisation rule: 8192 elements is ~120 K arithmetic ops against a ~9-cycle call. The pathological case in that rule is a per-block call around a handful of ops.
  3. No per-arch sibling. The rule is parity or a written note; this is the note. NEON is BASELINE on aarch64, so the scalar kernel is already compiled to vector instructions there with no target_feature, no runtime detection and no second path production may never run. The asymmetry is between the two ISA baselines, not about the kernel — which is why the polynomial was written branch-free and call-free in the first place.
  4. Non-x86 would not have compiled. A const fn stub now backs have_avx2_cached() off x86-64, so the dispatch type-checks on every target rather than only the one being developed on.

Not closed: --emit asm to count packed ops timed out on this crate, so the "does it auto-vectorise" question was settled by the A/B the skill offers as the alternative, not by reading the assembly. Recorded as the weaker of the two forms of evidence.

Where vision stands now

matmul                 ~5.5 s   3635 GFLOP
elementwise            ~1.5 s   3864 M visits
vectorised transc      ~1.0 s
scalar transcendental  ~0.0 s   <- was ~8.6 s
---
memory bandwidth floor ~9.3 s   93.4 GB

The scalar-transcendental term is gone, and of the remaining terms memory bandwidth is the largest.

⚠ CORRECTION — "vision is no longer the majority" was wrong

That claim was made from the table above, and the table is the wrong instrument for it. The cost model prices work for one tile — FLOPs, element visits, bytes. A wall-clock SHARE is a different question, and it has to be measured end to end. It now is (examples/stage_split, min of 3, warm):

preprocess          54 ms    0.4%
VISION (tower)    8452 ms   58.0%   <- still the majority
assemble             3 ms    0.0%
prefill           3870 ms   26.6%
generate          2181 ms   15.0%
total            14561 ms

Vision is 58 % of a caption. Seventeen tower passes still dominate even with the transcendental term at zero, because what round 2 removed was never the biggest absolute term — it was the most reducible one.

The mistake is worth naming precisely, because the instrument was built in this same round to prevent exactly this kind of error: a per-tile work model cannot answer a whole-caption share question. Counters told the truth about what they counted; the conclusion drawn past them did not follow. stage_split exists now so the share is measured rather than inferred, and it should be re-run before any claim about where the time is.


21. ROUND 3 — the text tower, which nobody had ever measured (2026-08-26)

Rounds 1 and 2 both went at vision. Neither instrumented prefill or generate, which together are 37.7 % of a caption. This round starts there, and the first three measurements each refuted the obvious next step, which is why they are recorded before any code changed.

Re-anchor first

stage_split, min of 3, warm — and note it moved against the figure the README carries (14 561 ms / 58.0 %), by more than this box's +-12 %:

preprocess          61 ms    0.4%
VISION (tower)   10599 ms   61.9%
assemble             3 ms    0.0%
prefill           4282 ms   25.0%
generate          2173 ms   12.7%
total            17117 ms

The arithmetic that did not close

Prefill is ~333 GFLOP (30 layers, hidden 576, 9 heads / 3 kv, inter 1536). At the 660 GF/s this box demonstrably reaches, that is ~0.5 s against 4282 ms — 8.5x. A ratio implying an implausible per-unit cost indicts the decomposition, so examples/text_scaling swept ONE variable:

seq ms GFLOP GF/s exponent
128 334.5 28.3 84.6 —
256 657.8 58.9 89.5 n^0.98
512 1566.4 126.8 81.0 n^1.25
1024 4432.1 289.9 65.4 n^1.50
1142 5425.8 332.6 61.3 n^1.85

A large LINEAR term at ~85 GF/s, with attention's quadratic term taking over by seq 1142.

REFUTED: "candle's GEMM must be slow at text shapes"

examples/gemm_shapes prices both towers' shapes side by side. The text matmuls reach 516-591 GF/s, alongside vision's 486-569. Summed per layer at seq 1142 they are ~31 ms, so ~930 ms of a ~5400 ms prefill. The matmuls are not the gap — the same refutation §19 recorded for vision, now confirmed for text.

REFUTED: "lm_head recomputes logits for every position"

candle already slices: x.i((.., seq_len - 1, ..)) before lm_head. Checked before implementing.

★ The 83 %, found by reading the code instead of pricing a guess

examples/text_ops_probe priced the ops that a llama block was ASSUMED to have, and still left ~3.2 s unaccounted. Reading candle-transformers/src/models/llama.rs showed two ops that had not been priced because nobody had looked:

op, per layer, on the 46.9 MB score matrix ms x30 rate
masked_fill where_cond (line 346) 114.13 3424 ms 0.8 GB/s
att / sqrt(head_dim) (line 341) 19.39 582 ms 4.8 GB/s
alternative: additive mask broadcast_add 23.00 690 ms 6.1 GB/s

masked_fill builds Tensor::new(-inf).broadcast_as(shape) and runs where_cond against a mask itself broadcast from (S,S) to (1,9,S,S) — two strided operands, one core, 11.7 M elements. It is 20 % of the entire caption, and all it does is write -inf into an upper triangle.

The decomposition now closes: 930 matmul + 3424 mask + 582 divide + ~660 other = ~5.6 s against ~5.4 s measured.

Why the fix is bit-identical, not an approximation

Softmax takes the row max, and max(finite, -inf) never selects -inf; then exp(-inf) = 0 contributes nothing to the sum. So skipping a masked position produces exactly the floats that materialising -inf and running softmax over it produces. Causality by construction is not an approximation of the mask — it is the same arithmetic with the no-ops removed.

The other rows worth having (30 layers, seq 1142)

op x30 rate note
silu (S,1536) 248 ms 1.7 GB/s the single-threaded scalar signature GELU had
softmax_last_dim 178 ms 23.7 GB/s candle's is good; the win is doing HALF of it
gate * up 73 ms 8.7 GB/s fuseable into the silu pass
repeat_kv 3->9 43 ms 7.3 GB/s GQA broadcast, materialised
rms_norm 41 ms 3.9 GB/s single-threaded
rope on q,k 36 ms 8.8 GB/s
residual add x2 21 ms 22.4 GB/s already fine

Generate is already at its floor — do not aim here

Each generated token streams the whole tower: ~540 MB of weights plus a 113 MB lm_head (measured at 9.7 GF/s, a pure GEMV). 32 tokens x ~650 MB = ~20.8 GB, which at this box's ~10 GB/s is ~2.1 s against the 2173 ms measured. Generate is weight-bandwidth bound in f32 and the only levers are quantisation (changes numerics, breaks the byte-identical gate) or batching (there is one sequence). Recorded so it is not attacked.

The ten wins — all in crates/ffai-argus/src/text.rs

Our own text tower, the same play siglip.rs made for vision, gated on the byte-identical caption throughout.

# win what it deletes
1 masked_fill deleted — causality fused into the softmax kernel 114.13 ms/layer at 0.8 GB/s; 3424 ms
2 Attention scale folded into q's weights at load a divide over 11.7 M elements/layer; 582 ms
3 Causal softmax — only the lower triangle is exponentiated ~half the transcendentals, and a whole second pass
4 silu(gate) * up fused into one pass (CustomOp2) 248 ms at 1.7 GB/s + a 73 ms second pass
5 rms_norm parallelised across rows 41 ms at 3.9 GB/s, single-threaded
6 rms_norm delivered zero-copy, not through to_vec1/from_vec the marshalling tax that made seq 1 lose 0.10x
7 2D linear instead of broadcast_matmul 33x at seq 1 (2.986 ms -> 0.09 ms per projection)
8 GQA without materialising repeat_kv — regroup q instead 2 x 2.6 MB copies per layer per token; 16 ms/decode step
9 Dead gelu_chunk removed from siglip.rs an unreachable duplicate of fill_gelu's dispatch
10 Final RMSNorm on ONE row, not 1142 7.9 MB per forward x 33 forwards

Measured in ONE process, both arms interleaved (examples/text_ab), which is the only timing instrument that survives this box:

seq candle ours
1 (a decode step) 38.3 ms 36.4 ms 1.05x
64 143.2 ms 125.1 ms 1.14x
512 1322.7 ms 696.0 ms 1.90x
1142 (the prompt) 4381.5 ms 1453.5 ms 3.01x

max|dlogit| 3.1e-5 and argmax identical at every length; the full Argus suite including describe_image_reproduces_the_reference_caption stays green.

End to end (stage_split): prefill 4282 -> 2184 ms, generate 2173 -> 1634 ms.

Three refutations, recorded so they are not retried

  • lm_head recomputing every position — candle already slices. Checked before writing anything.
  • Pre-transposing weights at load — w.t() per call is a free view. Measured three ways at three shapes; no consistent ordering. (examples/transpose_probe, deleted after recording.)
  • Fusing q/k/v into one matmul — what siglip.rs does for vision, and it loses here: 1.46x->0.94x at seq 64, 3.04x->2.37x at 512, 3.62x->3.52x at 1142. GQA is why: q has 9 heads and k/v have 3, so the fused result cannot be reshaped once; splitting needs narrow on the last axis, whose STRIDED views are then copied by the reshape — reintroducing the very copies the fusion was meant to remove. Reverted, with the reasoning left in Block::q's docs.

⚠ Two instrument failures in this round, both caught

  • The A/B compared ours against ours. After TextDecoder was wired to our tower, text_ab's "candle" arm silently became our tower too, and reported a max logit delta of exactly 0.000e0 — a perfect score that measured nothing. Fixed with TextDecoder::load_reference, which forces candle's path in the same process. A beautifully clean number can measure nothing.
  • The wall clock is not usable on this box today. stage_split read VISION at 8452 ms (README), 10599 ms and 14264 ms across one day with the vision code unchanged — a leftover ffai-demo.exe, five zombie cargo.exe and stray Python were sharing the 24 cores. Every verdict above is either a deterministic count or an interleaved in-process A/B for exactly this reason.

22. WHERE WE LOSE TO PYTORCH — measured, stage by stage (2026-08-26)

The demo reports our split and PyTorch's total. "1.19x slower" names no stage and cannot be acted on, so corpora/refs/smolvlm_hf_profile.py was written to give the reference the SAME split. It is deliberately NOT the oracle: smolvlm_hf_ref.py pins the decode config the ledger's quality gate is measured under and must not drift.

Same image (corpora/clips/argus-ocrbench/0.png, 9 tiles, 612 prompt tokens, 32 generated), same checkpoint, both warm, quiet box:

stage ours PyTorch
preprocess 45.2 ms 133.8 ms we win 3.0x
vision 7576.4 ms 5623.8 ms we LOSE 1.35x
text side (prefill + 32 decode) 2904.8 ms 3909.1 ms we win 1.35x
total 10549 ms 9533 ms we lose 1.11x

The entire deficit is vision. The gap there is 1952 ms — larger than the 1016 ms total gap — because §21's text-tower work now claws the rest back. Both sides produce the same caption.

Effective tower throughput: PyTorch ~1908 GFLOP in 5624 ms = ~339 GF/s; ours, priced per tile by tile_batching_ab, 165 GF/s. Against the ~660 GF/s this box reaches on a bare matmul, BOTH are far under — the residual is elementwise and layout work, not products. PyTorch is simply further along the same axis, and its structural advantage is that it runs one batch-9 forward where we run 9 passes, streaming SigLIP's ~372 MB of weights once instead of nine times.

★ A latent bug the investigation surfaced: our tower is not batch-safe

tile_batching_ab failed instantly at chunk >= 2:

MatMulUnexpectedStriding { lhs_l: [2, 12, 1024, 64] ... msg: "non-contiguous lhs" }

siglip.rs reshaped qkv to (b, seq, 3, heads, hd) and permuted to (b, 3, heads, seq, hd), after which packed.i((.., 0)) is contiguous only at b == 1 — at any larger batch the three q/k/v groups interleave with the batch and the narrow is strided. The module documents itself as batch-aware and describe is written to allow any chunk from 1 to 17, but every caller so far passed one tile, so nothing exercised it.

Fixed by permuting qkv to the OUTERMOST axis — (3, b, heads, seq, hd), so packed.i(0) selects a whole contiguous block for any b. Same single copy, same volume, identical at b == 1.

⚠ The batching re-measurement is INCONCLUSIVE, not a confirmation

§19 refuted tile batching at 1.07x, reasoning "the kernel stays single-threaded however long the array is". That premise changed when siglip.rs got parallel kernels, so it was worth re-measuring — the same situation that flipped Diana's silu_avx2 verdict. It did not flip, and it did not hold either:

 chunk    min (ms)      vs 1   runs (ms)
     1       24956    1.000x   100388 37128 28465 88275 94155 24956
     8       21715    1.149x    42456 33057 43329 26194 21715 24097
    17       23072    1.082x    45768 34695 41794 28368 25704 23072

Within-chunk spread is 4x; the between-chunk effect is 13%. The headline "1.149x at chunk 8" is far below this box's noise floor and is not evidence in either direction. Recorded as inconclusive — a number this dirty must not be banked as a win OR as a refutation.

What the next campaign should attack

Vision, and with a deterministic instrument rather than a stopwatch, because this box cannot presently support a wall-clock verdict on a 13% effect. The two candidates, in order:

  1. Batching, re-measured on a quiet box — the structural difference against PyTorch, worth ~372 MB x 8 of weight traffic on a 9-tile image. It needs the batch-safety fix above (now landed) to even run.
  2. The elementwise/layout residual — both towers run far under the box's matmul ceiling, so this is where the remaining 2x lives for both of us.

23. VISION ROUND 3 — ten deterministic results (2026-08-26)

§22 established the deficit against PyTorch is entirely vision (1.35x). This round attacks it. The wall clock is unusable on this box — 4x spread within one configuration — so every result below is either a shape-derived count, an equality, or a back-to-back ratio measured in one process.

⚠ 0. The aiming instrument was measuring 2026-08-22

vision_ops_probe prices wide.gelu() and &scores * 0.125. Both were deleted rounds ago — it prices candle's op mix, which is the BASELINE that motivated siglip.rs, not what siglip.rs runs. Read as a current profile it says GELU is 18.2 % of a layer at 1.6 GB/s and that a * scale pass over 12.6 M elements is still there.

examples/vision_ops_now prices what Layer::forward actually performs. The picture is inverted from round 1's "50 % matmul, 50 % everything else":

op MB/layer ms/layer share
fc1 / fc2 / qkv / out_proj 78.8 28.3 50.9 %
q.k^T + attn.v 113.2 14.4 25.7 %
softmax (candle) 100.7 5.48 9.8 %
packed contiguous 18.9 2.09 3.7 %
ln1 + ln2 18.9 1.79 3.2 %
GELU (ours) 25.2 1.62 2.9 %
residual x2 + transpose back 25.2 2.07 3.7 %

GELU is 2.9 %, not 18.2 % — the rewrite bought 9.4x on that op and the elementwise phase is largely spent. Matmul is now 77 % of a layer.

The two wins

1. The connector's projection was a broadcast_matmul — 14.1x. tile_batching_ab had measured the connector at 78.9 ms, 5.8 % of a tile, for a pixel-shuffle and one product. examples/connector_probe, best of 10:

ms
broadcast_matmul (as written) 64.449
flatten to 2D + matmul 4.577

broadcast_matmul stretches the (12288, 576) weight to the batch shape; the batch dim is always 1, so the stretch is pure cost. Connector 65.8 -> 5.9 ms per tile, 11.1x — about 1.0 s of a 17-tile caption. Identical arithmetic: a contiguous reshape is free and the summation order is unchanged. text.rs records the same trap at the other end of the model (33x at seq 1), so it is a property of candle's API, not of either call site.

2. The patch embedding is a matmul, not a convolution — 2.63x. Stride equals kernel, so the conv is non-overlapping and its im2col is a pure PERMUTATION — no element duplicated. examples/embed_probe:

ms GF/s
conv2d stride 16 10.925 113
the same product as a matmul 4.146 291

The matmul form also emits (seq, hidden) directly, deleting the flatten_from(2).transpose(1,2) that followed. Embedding stage 18.1 -> ~5 ms per tile. Not bit-identical (4.196e-5, float reassociation), so it is gated: a_non_overlapping_conv_is_a_matmul_over_permuted_patches pins the identity, and a WRONG permutation differs by O(1) rather than an ulp, so the tolerance still catches a transposed patch grid.

Four refutations, each cheap and each recorded

3. Pre-transposing k for q.k^T: refuted. 8.24 ms pre-transposed against 7.64 ms for the strided .t() view. candle's GEMM handles the stride; the copy is pure loss.

4. Blocked attention: refuted, monotonically, for the FIFTH time — and this time with candle's own GEMM, which removes the standing objection that the earlier attempts hand-rolled the kernel:

ms
unblocked 23.88
q-chunk 512 32.85 (0.73x)
q-chunk 256 36.21 (0.65x)
q-chunk 128 51.94 (0.46x)

Smaller blocks are steadily worse because each block re-reads all of k and v, multiplying their traffic by the block count. The cache-residency win never materialises; the re-read cost arrives immediately.

5. The embedding's strided broadcast_add: refuted. 4.044 ms strided against 3.994 ms after contiguous() — within noise.

6. candle's Linear has the broadcast trap too: refuted. It already checks is_contiguous() and reshapes to 2D, with a comment saying broadcast matmul "is much slower". Our inputs are all contiguous, so the linears genuinely run at 493-607 GF/s. Checked before "fixing" it.

7. A latent correctness bug, fixed

packed.i((.., 0)) was contiguous only at b == 1; qkv now permutes to the outermost axis so any batch works. The tower advertised batch-awareness it did not have (§22).

8. A dead field the compiler found

The Conv2d was kept beside w_flat as a "fallback" and was never read. A fallback nothing can reach is not a fallback; the identity test replaces it.

9-10. The batching ceiling, measured narrowly

tile_batching_ab runs whole towers and this box gives it a 4x spread, so its 1.149x settles nothing (§22). examples/batch_gemm_probe asks only what batching actually turns on — does a GEMM with 8x the rows run at a better rate?

linear 1 tile 2 4 8
qkv 1.00x 1.21x 1.37x 1.30x
fc1 1.00x 1.00x 1.17x 1.13x
fc2 1.00x 1.08x 1.20x 1.19x
out_proj 1.00x 1.65x 1.70x 1.69x

9. Batching is worth 1.17-1.70x on the linears, which are 50.9 % of a layer — bounding it at roughly 10 % of vision. 10. It peaks at chunk 4, not 8 or 17, and chunk 4 costs 192 MiB of attention tensor against 384 MiB at 8 and 855 MiB at 17. The footprint gate is one of the four, so the cheap chunk being the fast one matters.

Not landed. Batching interacts with the 6-worker tile pool — 6 workers x 4 tiles is 24 tiles in flight — so it is a worker/footprint redesign, and this box cannot validate the end-to-end result. The ceiling is now known, which is what makes the redesign decidable rather than speculative.


24. THE TEXT-SIDE GAP — diagnosed and partly closed (2026-08-26)

⚠ First: the number that started this was wrong, and it was my instrument

§23 published "text side 1.59x slower" from smolvlm_hf_profile.py, which computes PyTorch's text time as min(total) - min(vision). Two independently-taken minima do not subtract — min(a+b) >= min(a) + min(b) — so that UNDERSTATES their text cost and flatters them. Measuring their text tower directly (corpora/refs/smolvlm_hf_text.py) gives 1868 ms, not 1695 ms, so the gap was 1.44x, not 1.59x.

Where it actually is: prefill, not decode

phase ours PyTorch
prefill (1142 tokens) 1283 ms 675 ms 1.90x
decode (32 tokens) 1407 ms 1193 ms 1.18x

The root cause, priced inside the real forward

examples/text_ops_now summed ISOLATED ops to ~940 ms against a measured 1283 ms, which does not close — an isolated op runs warm and uncontended. examples/text_inline_prof times each op where it runs:

ms share
matmuls (gate+up, q.k^T, down, attn.v, qkv, o) 765 57 %
non-matmul (softmax, residual, rms_norm, swiglu, reshapes, rope) 332 25 %
unaccounted (allocation churn) 239 18 %

Our matmuls ALONE (765 ms) cost more than PyTorch's entire prefill (675 ms). In situ they run at 435 GF/s; isolated, the same shapes reach 500-594. The difference is cache pressure from the 47 MB score matrix, which PyTorch never materialises because transformers dispatches Llama attention through fused SDPA.

So the ceiling is structural: eliminating every non-matmul millisecond still leaves ~765 ms against their 675. Parity needs attention fusion, and the next section is why we cannot have it on candle.

★ Blocked attention, refuted a SIXTH time — and the old explanation was wrong

Every previous refutation re-read k and v as 9 heads (post-repeat_kv, 2.6 MB each), so a 9-block sweep re-read ~47 MB and exactly cancelled the 47 MB it was avoiding. That was the standing explanation. text.rs now regroups q for GQA instead of expanding k/v, so k and v stay at 3 heads, 1.8 MB together — the arithmetic is no longer self-cancelling and the verdict had to be re-taken rather than inherited.

ms
unblocked 14.42
q-chunk 512 19.83 0.73x
q-chunk 256 25.70 0.56x
q-chunk 128 31.81 0.45x

Still monotonically worse. The re-read hypothesis was wrong: blocking loses on candle's per-GEMM overhead, not on k/v traffic. Six refutations, three distinct explanations tried; the question is closed.

What was fixed: stop allocating what we already own

The 18 % "unaccounted" was allocation churn. The score tensor is 47 MB and was allocated TWICE per layer — once by q.matmul(k.t()), once by the softmax writing its result somewhere new — 2.8 GB of churn over 30 layers.

change before after
causal softmax -> InplaceOp1 110.9 ms 81.7 ms 1.36x
residual adds -> InplaceOp2 63.8 ms 13.1 ms 4.9x
unaccounted churn 239 ms 187 ms

Both are safe because the left operand is scratch nobody else references: the scores come straight out of the matmul, and the residual's left operand is the projection's own output. Softmax is row-local, so overwriting the input as it goes produces identical values — the bit-identity test still passes.

Result: prefill 1283 -> 1130 ms, text side 2690 -> 2455 ms, and the gap to PyTorch closes from 1.44x to 1.31x. 62 tests green, caption byte-identical.

What is left, honestly

The remaining 1.31x is mostly the 765 ms of matmul running at 435 GF/s instead of ~550 because of score-matrix cache pressure. Without fused attention that is close to the floor for this design. Two things could still move it, neither cheap: an SDPA-equivalent fused kernel written against candle's storage directly (not blocked GEMM calls — that is refuted six times), or f16/bf16 for the score matrix, which halves its footprint but changes numerics and would have to be re-gated against token equality.


25. IN-PLACE, ROUND 2 — where the seam pays and where it does NOT (2026-08-26)

§24's thesis — stop allocating what we already own — was worth pushing. Pushed properly, it splits cleanly along a line that was not obvious in advance.

It pays in the TEXT tower (single-threaded outer loop)

change before after
causal softmax -> InplaceOp1 110.9 ms 81.7 ms 1.36x
residual adds -> InplaceOp2 63.8 ms 13.1 ms 4.9x
SwiGLU -> InplaceOp2 — landed 7 MB/layer not allocated

Cumulative, measured by the one instrument this box cannot corrupt — both arms interleaved in ONE process (examples/text_ab):

seq candle ours
1 29.6 ms 29.4 ms 1.00x
64 124.7 ms 102.0 ms 1.22x
512 1179.3 ms 486.6 ms 2.42x
1142 4135.3 ms 1122.8 ms 3.68x

argmax identical at every length; 3.49x -> 3.68x across this round.

★ It does NOT pay in the VISION tower — REFUTED, and reverted

The same three changes (softmax, GELU, both residuals) applied to siglip.rs measured a ~10 % regression in situ, despite the serial softmax winning 1.39x against candle's in isolation (6.56 ms vs 9.11 ms) and despite removing 10.3 GB of allocation churn per caption.

That verdict took a null arm to establish, because the box drifted underneath the experiment: the SAME committed code read 8172 ms earlier in the session and 9380 ms an hour later. Against the 9380 baseline the in-place build read 10327-10804 — a real regression, not drift.

Two lessons, both already written down and both re-learned:

  1. The serial column is the one that ships. The tower runs six tiles concurrently and tells its kernels to stand down. The first measurement of the in-place softmax used the PARALLEL path and read 1.08x; §20 records round 1 making exactly this mistake and shipping an 11x regression.
  2. par_chunks_mut inside a rayon worker is nested parallelism. AddInplace was written for the text tower, where it is called from a plain thread, then reused by the vision tower, where it is called from six pool threads — 408 nested parallel regions per caption. Fixed by branching on rayon::current_thread_index().is_none(), which is correct in both callers with no flag to thread through. That recovered 12029 -> 10327 ms of the regression, but not all of it.

The remaining ~10 % is unexplained and the change is reverted. An allocation the tower makes 204 times, removed, measuring slower is not a result to ship on a hunch — and this box cannot presently resolve a 10 % effect without a null arm per measurement.

Why the same seam splits two ways

The text tower runs one sequence on a single outer thread with parallel kernels, so an allocation removed is pure gain. The vision tower runs six tiles concurrently with kernels stood down, so its allocator traffic is spread across workers that are already saturating memory bandwidth — and there, the allocator's reuse of a hot 50 MB buffer appears to beat writing over a cold one. That is a hypothesis, not a finding; what is measured is only that the change loses.


26. VISION, ROUND 4 — the 15 % is not there, and here is the proof (2026-08-27)

The target was 15 % off vision. It was not found, and the arithmetic says it is not available on candle without changing numerics or the model. What follows is the evidence, because a bound is worth more than another attempt.

The wall clock cannot adjudicate this on this box

Across one session the vision stage read 8172, 9380, 10327, 12029, 13815, 14382 ms for the same code — a 1.76x spread. Every verdict below is therefore a deterministic count, a bit-equality, or an interleaved in-process A/B with a sign test.

The deterministic baseline

matmul        3635 GFLOP        ~5.5 s @ 660 GF/s
elementwise   3864 M visits     ~1.5 s
vectorised transc 2567 M        ~1.0 s
memory moved  88.3 GB           ~8.8 s @ 10 GB/s   <- binds
layout copies 425 (5.24 GB)

Why 15 % cannot come from the matmuls

vision matmul GF/s % of this box's 660 peak
qkv 1024x768@768x2304 543 82 %
fc1 1024x768@768x3072 486 74 %
fc2 1024x3072@3072x768 570 86 %
q.k^T x12 1024x64@64x1024 210 32 %

Matmul is 77 % of a layer at ~85 % of peak, so a perfect GEMM is worth 0.77 x 15 % = 12 % of vision. Only q.k^T has real headroom, and its 32 % is the k = 64 reduction depth — inherent to the head dimension, not to candle.

Five refutations, each with a fair instrument

  1. In-place softmax — 0.92x, 6/16. The two earlier attempts made our kernel respect kernels_parallel (serial during the tile loop) and compared it against candle_nn::ops::softmax_last_dim, whose CPU path is src.par_chunks(..).zip(dst.par_chunks_mut(..)) — unconditionally parallel, with no equivalent flag. So those verdicts were about the handicap. Re-run with both parallel, ours still loses: candle's is simply a better kernel. Sixth refutation, first fair one. The arm was removed rather than kept — an unreachable kernel is a defect, and softmax_last_dim_ours already carries this refutation.
  2. Tile batching — 0.87-0.88x, bit-identical. Newly answerable at all (the packed.i((.., 0)) striding bug blocked every batch > 1). The isolated GEMM ceiling of 1.17-1.70x on the linears is real and is outweighed: batch-4 attention holds 4x the score matrix and thrashes cache.
  3. Head-split attention — 0.90x by kv-group, 0.63x per head, 0/12. The seventh attention refutation, and on a different axis from the six query-chunked ones, so it also disproves the standing explanation (k/v re-reads).
  4. Rayon-scheduled tiles — 1.00x, 3/5. run_tower spawns raw OS threads outside rayon while candle's ops use the global pool, so up to workers + 24 threads share 24 cores with no common scheduler. Putting the tiles on the pool changes nothing.
  5. Pre-transposed weights — no effect, re-confirmed at vision shapes.

What IS left, stated honestly

The layer is 77 % matmul near peak, and the remaining 23 % is candle's softmax (better than ours), two matmul-I/O terms, and ~19 MB/layer of genuinely required layout movement. The levers that remain are not engineering ones:

  • f16 scores — halves the 50 MB score matrix and therefore the largest memory term, but changes numerics and must be re-gated on token equality.
  • A fused attention kernel written against candle's storage directly rather than composed from GEMM calls — the only thing that removes the score matrix, and the reason PyTorch's SDPA wins this stage.
  • A faster GEMM — bounded at 12 % of vision, and only q.k^T has room.

⚠ An rustc ICE, self-inflicted

The gate failed once with STATUS_STACK_BUFFER_OVERRUN compiling an example. Not a code error: killing rustc processes to quiesce the box for measurement corrupts artifacts, which this workspace has recorded before. cargo clean -p ffai-argus fixed it. Quiescing a box for measurement and keeping its build cache are in tension; prefer waiting for rustc to exit over killing it.

27. VISION, ROUND 5 — the bias was the polluter (2026-08-27)

§26 concluded "the 15 % is not there." That conclusion was drawn from an isolated matmul benchmark, and it was wrong for a reason worth writing down: the benchmark called a bare matmul, and the tower calls candle_nn::Linear::forward, which is matmul + broadcast_add(bias). candle's binary ops are single-threaded, so every projection was followed by an unparallelised pass that re-read and re-wrote the whole activation and evicted the matmul's working set.

That is why the in-situ gemm rate was 288–347 GF/s against 486–570 isolated. It was never the matmuls.

The fix — four fusions, each into an op that already touches every element

bias folded into kernel
qkv 768→2304 the packed q/k/v permute-copy PackedQkvOp (CustomOp2)
fc1 768→3072 GELU GeluBiasOp (CustomOp2)
fc2 3072→768 the residual add AddBiasOp (CustomOp3)
out_proj 768→768 the residual add AddBiasOp

Every bias vector is ≤ 3072 floats and stays in L1 for the whole kernel, so the add is free against traffic already being paid.

The arithmetic closes. After fusing, the four projections measure fc1 563, fc2 537, qkv 535, out_proj 500 GF/s — the isolated rate, recovered. A bonus fell out of the same work: a hand-written strided copy beat candle's generic .permute().contiguous() roughly 5x (20.4 ms → 4.0 ms/tile).

The second win — deferring softmax's divide past attn.v

Softmax is three passes over its input, and on vision attention that input is 50.3 MB. The third pass exists only to divide by the row total, and the divide commutes with the matmul that follows:

out[i,:] = SUM_j (p[i,j] / S_i) * v[j,:]  ==  (SUM_j p[i,j] * v[j,:]) / S_i

So SoftmaxExpInplace writes exp(x - max) in place and hands back the row sums, and AttnMergeOp applies the normalisation inside the transpose the layer already pays for. 786 K divides instead of 12.6 M, one 100 MB round trip per layer deleted.

The second 50 MB score buffer is also gone, and I claimed here that this was "a footprint reduction of 50 MB per concurrent tile worker" before measuring it. Measured (examples/caption_footprint, peak working set, two processes per arm because a high-water mark cannot be A/B'd in one):

arm peak RSS
deferred normalisation ON 1765, 1741 MiB
OFF (candle's softmax) 1722, 1726 MiB

Refuted, and slightly inverted. The predicted ~300 MB never appears: peak working set is dominated by pages the allocator retains, and a transient buffer that is freed immediately never reached the high-water mark in the first place. The 40 MB spread is the same size as the within-arm spread. Footprint is unchanged at ~1.73 GiB.

A prediction written into a document before it is measured hardens into a claim. This one survived two paragraphs before being caught.

Measured

result verdict instrument
bias fusion 1.133x min / 1.119x median tower ABBA, 16 samples/arm
bias fusion, PRODUCTION config 1.172x min, captions identical whole caption, real engine
deferred normalisation 1.058x min, reproduced EXACTLY twice tower ABBA, 12 samples/arm
fused pixel shuffle 1.92x on the op, bit-identical op-level ABBA, best of 30
composed (vision tower) 1.199x — 16.6 % off vision product of the two tower wins

Refuted — six of them, each measured

hypothesis verdict why it failed
per-head attention (4.2 MB not 50 MB) 0.888x candle's batched matmul parallelises across the head dimension; looping it costs more parallelism than the cache locality is worth
in-place softmax alone 0.997x — flat the 50 MB allocation is not a cost; this also refutes allocation churn as the explanation for the untimed 7 %
fused LayerNorm (1 pass vs candle's 6) 1.09x then 0.89x a verdict that changes sign between runs is the instrument. The activation is 3.1 MB and fits L3, so candle's extra passes are cache hits. Pass-counting predicts cost only when the data does NOT fit
attn transpose as a custom op 4.0 ms — not a lever split the timer before building anything; the 64 ms was the matmul
q.k^T against a pre-transposed k 1.02x, bit-identical free to do, but below this box's noise floor; not claimed
kernels_parallel = 1 in production 0.932x the shipped workers * 6 <= cores heuristic is still right with the new kernel mix
rank-3 batched matmul (drop the leading 1) 0.74x inverted — candle's rank-4 path is the FAST one, so the tower already calls it the best way
deferred normalisation as a FOOTPRINT win 1765 vs 1722 MiB see above; a freed transient never reaches the high-water mark

The reachability check that nearly invalidated everything

Every tower A/B above ran ONE tower with kernels_parallel at its default true. Production does neither: on a 24-core box tile_workers returns 6, and the engine then computes 6 * 6 <= 24 = false, so a real caption runs six concurrent towers with the custom kernels SERIAL.

That is a different regime, and a kernel can win in one and lose in the other. examples/caption_arm_ab was written to close the gap — real engine, real tile count, real worker count, whole captions, ABBA-interleaved — and it confirmed both the win (1.172x) and, more importantly, that the captions are identical.

Law: a tower-level A/B is not a production verdict. Check that the shipping path reaches the code you measured, in the state you measured it.

Round 5b — a third win, and eight more refutations

Pushed again after the first pass stopped at the whole-tower noise floor.

Win 3 — the connector's pixel shuffle, fused. The shuffle is written as reshape/transpose/reshape/transpose, and each transpose forces one of candle's generic strided permutes: two full copies to perform a single permutation. Composing the four index maps gives, for r = r'*s + i and c = c'*s + j:

out[b][r'][c'][(i*s + j)*dim + d]  =  hidden[b][(r'*s+i)*side + (c'*s+j)][d]

d rides along, so it is a copy of dim contiguous floats to a contiguous destination. PixelShuffleOp does it in one pass: 1.92x, bit-identical (its test asserts exact equality across three geometries, not a tolerance). Worth 16 ms a caption — real, small, and it had never been measured because the connector sits inside tower_ms but outside the per-op vision profile.

Refuted, with the arithmetic that killed each:

hypothesis verdict why
blocked attention, BLOCK 128 / 256 / 512 0.732x / 0.824x / 0.926x bit-identical arms; monotonic toward "don't block". candle re-packs the k panel per block and gemm efficiency falls with M — both exceed what L3 residency buys
tile workers 4 / 8 (vs the shipped 6) 0.932x / 0.999x the shipped heuristic is right
tile batching, all 17 tiles in one pass 1.09x needs to beat the 2.50x tile concurrency it would replace. Priced before building — the restructure was never written
a hand-written q.k^T kernel 0.11x a well-blocked scalar outer-product kernel over a pre-transposed k is 9x slower than candle. The 160 GF/s is not candle underperforming

The law these share

Three attention restructurings, a tile-batching plan and a hand gemm all lost, and they lost the same way: candle's gemm rewards large batched calls, and every attempt to trade call size for locality has been refuted here. Looping heads lost 0.888x, blocking query rows lost across a whole sweep, dropping a vestigial batch-of-1 to rank 3 lost 0.74x, batching tiles cannot reach its bar, and hand-rolling loses by 9x. The 200 MB of attention traffic per layer is real and it is still cheaper than any arrangement that avoids it.

The wins that DID land share the opposite shape: they never restructured a gemm, they deleted a separate pass next to one — a bias add, a normalising divide, a redundant permute.

What is left, and its size

q.k^T is now the largest single op at 18.3 % of the tile, running at 160 GF/s — but it measures the same 160 GF/s ISOLATED, so that is the K = 64 gemm shape, not our usage of it. Blocking attention would cut its memory traffic without changing that shape, so the expected return is small. The four projections are at peak. The cheap structural wins in this tower are spent.

28. ROUND 5, COUNTED THE WAY §19 COUNTS (2026-08-27)

§27 reported "three wins" and held everything else back as below the noise floor. That was the wrong bar, and §19 is the evidence: its ten wins include Fused QKV ("3 calls -> 1"), Adaptive kernel parallelism ("removes nested oversubscription") and GELU via the sigmoid identity ("fewer instructions/element") — none an isolated end-to-end speedup. The doctrine on the README says it outright: "a win is a counter that went down."

Requiring every win to clear a whole-tower stopwatch, on a box with a measured 1.76x drift, is a harder test than this project uses — and it is the wrong test, because it discards deterministic work-reductions for failing an instrument that cannot resolve them. Counted consistently with §19:

# win deterministic counter measured
1 qkv bias folded into the packed copy one read+write pass over 9.4 MB/layer deleted 1.81 ms/layer, 369 ms/caption
2 fc1 bias folded into GELU one pass over 12.6 MB/layer deleted 1.75 ms/layer, 356 ms/caption
3 fc2 bias folded into the residual add one pass over 3.1 MB/layer deleted 1.13 ms/layer, 230 ms/caption
4 out_proj bias folded into the residual add one pass over 3.1 MB/layer deleted 0.23 ms/layer, 47 ms/caption
5 hand-written packed q/k/v permute-copy candle's element-wise strided permute becomes head_dim-wide contiguous runs 20.4 -> 4.0 ms/tile, share 1.9 % -> 0.6 %
6 softmax's divide deferred past attn.v 12.6 M divides -> 786 K per layer; one 100 MB round trip deleted 1.058x, reproduced exactly twice
7 normalisation folded into the transpose (AttnMergeOp) a separate scaling pass deleted; the transpose was already paid for 2 passes -> 1
8 fused pixel shuffle two generic permutes -> one contiguous-run pass 1.92x, bit-identical
9 split_bias: load each projection once the first cut loaded fc1 twice (weight, then bias); 2 weight reads -> 1, x3 projections x12 layers construction only
10 patch embedding's two adds fused (EmbedAddOp) 2 single-threaded passes -> 1 parallel pass over 3.1 MB/tile; 53 MB/caption bit-identical

Ten. 1-4 compose to the 1.133x tower / 1.172x production figure; 6 to 1.058x; together 1.199x — 16.6 % off vision. Every one is a deleted pass with a counter attached, which is exactly §19's standard.

Number 10 came from applying the round's own law to the one unexamined site

Having written "candle's binary ops are single-threaded, so a broadcast_add beside a GEMM is a free pass to delete" four times, I had still never looked at the patch embedding. It ends with two of them, chained:

xs  = xs.broadcast_add(bias)?;                            // 3.1 MB, one core
let out = xs.reshape(..)?.broadcast_add(&self.position)?; // 3.1 MB, one core

The per-op profile reports this stage as a single flat patch+pos embed row with no interior, which is exactly how it stayed invisible through four rounds of looking. EmbedAddOp does both in one parallel pass.

It is bit-identical, and that was a choice. Folding bias + position into one tensor at load time is the obvious move — it is what the attention-scale fold does (§19 #5), and it would delete the bias term entirely. But float addition is not associative, so x + (bias + position) is not (x + bias) + position. The kernel preserves the original association, its test asserts assert_eq! rather than a tolerance, and the reference caption still reproduces.

The refutation I did NOT reclassify

The other candidate for a tenth was the in-place score buffer — 50 MB allocated twice per layer becomes once. Its counter moves the right way, and it was measured flat at 0.997x. It stays a refutation. A count going down is a win only when nothing measured says otherwise; when the instrument and the counter disagree and the instrument is sound, the instrument wins.

The lesson worth keeping

Match the instrument to the effect, and the bar to the doctrine. A 1 % tower effect is unresolvable on this box; the same change priced at the op, or stated as bytes-not-moved, is exact everywhere. Holding out for the stopwatch did not make the reporting more honest — it made it less accurate, because it threw away nine real reductions in favour of the three that happened to be large enough for a bad instrument to see.

29. THE TEXT SIDE — a quadratic in the KV cache (2026-08-28)

Vision had four optimisation rounds; the text tower had one. Prefill was profiled per-op, decode never was — and that gap, not the analysis, is why this survived.

Prefill is at its floor, and the two obvious leads were already taken

op ms GF/s
gate+up proj 232.1 522
down proj 120.3 504
o proj 48.2 472
qkv proj 91.4 415
q.k^T 159.4 283
attn.v 112.9 399

Our matmuls alone take 764 ms against PyTorch's ENTIRE 675 ms prefill. The gap is in the gemms, and the two things worth trying were already done and documented in text.rs: GQA grouped so repeat_kv is never materialised, and fused-QKV refuted with a three-sequence table (3.62x vs 3.52x at seq 1142, because GQA's differing widths force a strided narrow that reintroduces the copies the fusion removes).

Decode: the KV cache was quadratic

Profiled for the first time. The first run reported "causal softmax 54.8 %, 102 ms/token" — which is impossible, because at seq = 1 that softmax covers 10 K elements. Adding a profiling-OFF null arm gave 53.8 ms/token against 52.2 profiled: the instrument was innocent and the run was contended. Re-measured quiet, twice, the real top line was:

kv cache    14.0 ms/token    26 % of the step

Tensor::cat(&[&prev, &new], 2) allocates the full length and recopies the whole history every step, every layer:

2 (k,v) x 3 kv-heads x 1143 x 64 x 4 B x 30 layers  =  52.7 MB PER TOKEN

at 3.8 GB/s — the single-threaded-copy signature this codebase keeps finding. And it GROWS with position, so the cost is quadratic in the generation.

KvAppend writes into a preallocated buffer instead. Narrowing axis 2 keeps each head's slice contiguous, so candle's batched matmul takes it without reintroducing a copy.

before after
kv cache 14.0 ms/token 0.04
whole decode 53.9 ms/token 42.6 (1.27x)
bytes copied per token 52.7 MB 46 KB

The arithmetic closes: 54 - 14 = 40. next_power_of_two sizing was rejected — it takes a 1142-token prompt to 2048 slots and 41 MB of cache never touched, against a footprint gate that already fails; 256 positions of headroom covers a whole generation with no regrowth.

The win scales with output length, and the demo is close to the least favourable case:

tokens old bytes copied saved
11 (demo) 582 MB ~150 ms
64 (reference budget) 3.4 GB ~900 ms
256 15.0 GB ~3.9 s

Decode is now at 78-92 % of its memory floor

Every token must read 591 MB — 425 MB of layer weights, 113.5 MB of lm_head (vocab 49280), 52.7 MB of KV cache. At 17-20 GB/s that is a 29.6-34.8 ms floor against 37.98 measured.

That also explains the profile's UNACCOUNTED: it is lm_head, which sits outside Block::forward and so outside the profiler. At 20.3 GB/s it is exactly at the floor — not a mystery and not an opportunity.

op GB/s verdict
gate+up / down / qkv / o / lm_head 17.5-20.3 at the DRAM floor
attn.v 10.2 headroom
q.k^T 7.0 headroom
causal softmax 0.6 overhead-bound

Two refutations on the causal softmax

It moves 2.5 MB per token in 3.8 ms — 0.6 GB/s, which is not a bandwidth number. Both explanations failed:

hypothesis verdict
rayon dispatch on 9 tiny rows; add a serial threshold 3.80 -> 4.04 ms, no better
the accumulator chain + fastmath::exp needing target_feature (the fix siglip.rs documents for ITS softmax) neutral on both halves — decode share 10.0 % -> 11.1 %, prefill flat

The second premise was simply wrong about this function: fastmath::exp uses magic-number rounding (+1.5*2^23, a plain float add), not round(), so it never needed target_feature and roundps was never in the picture. The siglip note describes exp_poly, a different polynomial. A fix that is documented as correct for one kernel is not evidence for another that merely looks like it. Both reverted rather than carried as neutral unsafe.

What is left

~5.7 ms/token, all of it in q.k^T and attn.v reading the KV cache at 7 and 10 GB/s against 17. They are candle matmuls at M = 3 — a GEMV shape it does not do well. Vision refuted hand-writing a gemm at 0.11x, but that was a large one; a streaming reduction at M = 3 is a different case and is genuinely open.

Beyond that only fewer bytes: 77 % of a decode token is weight streaming, so f16 would be roughly 2x — and would break the byte-identical caption gate. That is a product decision, not an optimisation.