← All Engineering Notes / SCARLET Quadrilogy, Paper I

[systems] Paper I · SCARLET Quadrilogy · 29 November 2026

Transformers: Pastry, Not Pie

From stateless attention shells to O(1) persistent state, salience working memory and episodic SimHash graphs in pure Rust. A year ago this was a private architectural note; this is its first public release alongside the compiled runtime that bakes the filling.

Bit-exact ternary 2.1 MB sealed state Zero Python, zero C++ Limits stated

1. Abstract

Contemporary language-model engineering operates under a pastry-centric dogma: when a stateless next-token predictor exhibits amnesia, hallucination or fragility, the prescribed cure is a thicker crust. Context windows expand from 4K to 512K, KV caches balloon to 64–130 GB of datacenter VRAM, and power envelopes climb past 300 W per accelerator — all to sustain the polite fiction that a sliding token buffer is a mind.

Under SCARLET (Stateful Cognitive Architecture for Recurrent, Local-First, Expert Ternary) we demote stateless attention to one replaceable layer atop a unified zero-multiply POPCNT ternary substrate (TRT2), and implement four persistent state subsystems: flat 2.1 MB disk-persisted, keyed-BLAKE3 MAC-sealed BMS3 Radix SSM snapshots; an 8-slot Prefrontal Cortex salience working memory backed by an atomic .json + .bak Continuity Shunt; a 256-bit BLAKE3 SimHash episodic graph executing exact POPCNT recall in 112.9 μs per 10,000 entries; and deterministic on-device execution cross-compiled to Android arm64-v8a.

2. Why stateless attention hits a structural wall

Treating an isolated Transformer forward pass as a complete cognitive agent imposes four non-negotiable failure modes:

  1. The quadratic memory tax. Retaining long-horizon history via raw attention scales as O(T²) in compute and O(T) in KV-cache RAM, confining persistent context to rented datacenter clusters.
  2. Volatile buffer versus persistent state. A prompt window is an I/O buffer, not memory. When the process terminates or the window truncates, continuity evaporates.
  3. Unchecked state pollution. Softmax normalisation forces probability mass to sum to 1.0 across every token in scope, offering no native cryptographic boundary to reject tampered or low-provenance state.
  4. Runtime bloat. Production serving remains bound to multi-gigabyte Python and C++ stacks that cannot cold-boot in milliseconds on commodity laptops or mobile handsets.

3. The filling, compiled

Rather than bolting fragile Python orchestrators onto a cloud API, SCARLET compiles the oven, the crust and the filling into a single Rust binary with no Python and no C++.

Subsystem2025 internal spec2026 pure-Rust receipt
The oven (TRT2 kernel)Zero-multiply ternary inference on consumer CPUsUnified DualTrit { pos: u64, neg: u64 } POPCNT substrate across AVX-512, AVX2 Muła, ARM64 NEON and SWAR
The crust (unified mixture of models)Replace standalone cloud attentionBitNet 2B-4T at 12.19 tok/s on a NZ$3 2013 laptop; BitMamba-2 1B at 30.20 tok/s with max_err = 0; FM-MOSTEST Stitched v8 at 23.62 PPL and 10.36 tok/s
Working memoryGlobal-workspace executive slots8-slot Prefrontal Cortex (pfc.rs) plus crash-safe atomic .json + .bak Continuity Shunt sealed with keyed BLAKE3
Long-horizon stateConstant-RAM temporal persistenceFlat 2.1 MB keyed-BLAKE3 BMS3 Radix SSM disk snapshots: under 1 ms boot, bit-exact restore, O(1) RAM
Episodic recallAssociative content-addressable memory256-bit BLAKE3 SimHash graph executing exact POPCNT recall in 112.9 μs per 10,000 entries with a native gap_signal
Mobile edgeOn-device sovereign runtimeCross-compiled arm64-v8a libbitmamba_bridge.so with Android ARM64 test suites on Galaxy S25 Ultra

4. The oven: one zero-multiply substrate

Every ternary weight matrix w ∈ {−1, 0, +1} across dense transformers, O(1) state-space models and block-diffusion experts is stored as 64-byte aligned, word-interleaved DualTrit { pos: u64, neg: u64 } mapped via MADV_HUGEPAGE. Decomposing two's-complement INT8 activations into bit-planes, with support mask D = pos ⊕ neg and mk = neg ⊕ (D ∧ Bk), yields exact integer dot products with zero multiplications per weight:

sum_j w_j x_j = sum_{k=0..7} c_k popcnt(m_k) + popcnt(neg)

One kernel unifies BitNet 2B-4T (dense), BitMamba-2 1B (O(1) SSM, 228.6 MB native TRT2, max_err = 0, 30.20 tok/s on Intel i7-13620H) and FM-MOSTEST Stitched v8 (7-expert 64-token block diffusion, 273.39M parameters, coupled to frozen BitMamba-2 1B through a 2.1M-parameter surgical 2048 → 1024 StitchBridge, cutting clean validation perplexity from 30.66 to 23.62 at 10.36 tok/s on an AVX2 CPU).

5. Persistent O(1) state and salience working memory

Instead of allocating 64–130 GB for KV caches, SCARLET serialises the recurrent state of BitMamba-2 1B to a flat 2.1 MB BMS3 Radix SSM snapshot sealed with a 256-bit keyed BLAKE3 MAC. Snapshot restoration is bit-exact in under 1 ms with constant O(1) RAM regardless of conversation length.

Above the recurrent backbone sits an 8-slot Prefrontal Cortex salience working memory (pfc.rs) persisted through an atomic .json + .bak Continuity Shunt. Power loss or a crash mid-write cannot corrupt working state, and a single-bit change on disk or over the LAN triggers immediate cryptographic rejection — checked by unit tests and by live HTTP 403 on a forged MAC across a two-node AVX2 + AVX-512 LAN cluster running at 22.64 tok/s combined.

6. Content-addressable episodic recall

Rather than deploying heavyweight vector databases beside a local runtime, episodic traces are indexed into a 256-bit BLAKE3 SimHash graph. Retrieval reduces to four 64-bit XOR + POPCNT Hamming-distance instructions — the same hardware primitive driving weight inference — achieving exact recall in 112.9 μs per 10,000 entries with sub-millisecond cold boot while emitting a direct uncertainty signal (gap_signal) when query distance exceeds threshold.

7. Whakapapa as a cryptographic invariant

Data sovereignty cannot survive as a terms-of-service promise; it has to be enforced at the parser boundary. In SCARLET, whakapapa (lineage), tika (correctness) and pono (integrity) are concrete engineering constraints:

8. Honest boundaries

Three limits are stated plainly rather than left for a reader to discover:

Every figure here is an author build-log measurement on the named hardware with rustc 1.99.0 --release. None has been reproduced by a third party, and no external baseline is claimed.

References

  1. A. Vaswani et al., “Attention Is All You Need,” NeurIPS, 2017.
  2. S. Ma et al., “The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits,” arXiv:2402.17764, 2024.
  3. T. Dao and A. Gu., “Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality,” ICML, 2024.
  4. M. Arriola et al., “Block Diffusion: Interpolating Between Autoregressive and Diffusion Language Models,” ICLR, 2025.
  5. M. S. Charikar, “Similarity Estimation Techniques from Rounding Algorithms,” STOC, 2002.
  6. J. O'Connor et al., “BLAKE3: One Function, Fast Everywhere,” blake3.io, 2020.
  7. D. Kelly, “TritCore v1.4: One Zero-Multiply POPCNT Kernel for Dense Ternary, O(1) State-Space and Recurrent Block-Diffusion Models,” Paper IV, 29 Nov 2026.