Verace Topos: v3 code
Invariant-checked Python subsystems built around a transformer KV cache with content-addressed paging and symplectic volume steering.
- Active window: Short window of recent tokens kept in the cache
- Bounded resident set: The LRU pager holds 16 blocks by default
- Chunked KV offload: Oldest chunk stored with a soliton signature
- Geometric-key retrieval: Top-k blocks recalled by query geometry
Overview
The v3 code is the main Python implementation of Verace Topos: one package, verace_v3, with examples, pipelines and tests, built around V3Engine, V3Config and an application factory create_app(). It addresses one question. Can a transformer's key-value cache be replaced by a bounded, geometrically paged memory whose keys never collapse onto a single direction? Around that cache sit numbered conditions, I0 to I22, that subsystems check, each subsystem with its own frozen configuration, a health() report and telemetry under v3.<subsystem>.* names. Some of these checks are heuristics, and some have no effect under default settings.
The core is ToposKVCache, which joins three parts. Soliton Wave Memory (SWM) tags offloaded chunks with a 16-dimensional signature. The Holographic Tensor Store (HTFS) keeps chunks under SHA-256 addresses with zstd compression and an LRU working-set pager. Dynamic Symplectic Steering (DSS) keeps an SVD-based logic volume at or above , which is Invariant I6. Further subsystems implement other invariants: AST-level metamorphic rewriting (I17), SU(2) Wilson-loop pointer auditing (I18), sheaf gluing for merges (I19), a loop quantum cosmology solver (I11), a Landauer erasure auditor (I21) and thermal noise damping (I22). Others cover hysteretic GPU thermal control, a quarantine controller with a two-operator quorum, and a DNA soliton model.
The test suite runs the subsystems against real tensors from GPT-2, an outside pre-trained model, and a demo streams 512 GPT-2 layer-0 key and value tensors into the cache in 32-token chunks. The lab's generalization audit ran on an RTX 4050 laptop GPU. GPT-2 was distilled on 24 problems from eight benchmark sets, and 16 held-out problems were kept apart. Static distilled weights scored 100% on training problems and 0 of 16 held out. Adding the Topos KV cache and DSS left accuracy at 0 of 16 with logic volume 0.220. Only the full hybrid engine, with Z3 (an outside SMT solver), a C++ sandbox and calculators as external oracles, scored 16 of 16, with volume 4.273. The lab's own code audit found that this oracle regime mostly returns hardcoded or expected answers, and that in the second regime the cache is only logged, so the result does not show generalisation.
The cache, the steering controller, the store and the invariant subsystems are implemented and exercised by tests and demos. The lab's own code audit shows several gaps between names and computation. SWM stores and returns raw bytes, and soliton invariance is asserted rather than simulated. The volume penalty used in distillation has no gradient path. The monodromy check is a loop-count heuristic. The cosmology shear damping is a no-op under default settings. The 8x to 30x memory savings appear in the lab's records, with no measurement found in the lab's own code audit. The 16 of 16 held-out result does not show generalisation.
Status
Experiments. The subsystems are implemented and tested against GPT-2 tensors, and the lab recorded a three-regime held-out evaluation on 16 problems.
Simulator
A row of tokens is read two ways at once: the newest token looks back at every earlier one, and every token is also written into one memory of fixed size that fades.
- looking back: one arc for every earlier token
- fixed memory: how much of each token it still holds
- newest token at the right
- Looking back, this token
- 23 comparisons
- Looking back, whole sequence
- 276 comparisons
- State kept: looking back / fixed
- 24 tokens / 1 state
- Fixed memory: a token is half faded after
- 4.3 tokens
Lengthen the sequence: the arcs multiply, the fixed memory stays one state. Lower the decay and it forgets sooner.
This simulator is an illustration of the principle, with made-up numbers. It does not run the lab's code or show the lab's data, and nothing in it is a measurement.
Architecture
ToposKVCache
A drop-in replacement for a transformer KV cache. It keeps a short active window, offloads older chunks to the tensor store and recalls the most relevant blocks by query geometry.
Soliton Wave Memory buffer
SolitonBufferstores float32 chunk bytes under SHA-256 content addresses together with a fitted soliton signature that is used as the chunk's retrieval key.Holographic Tensor Store and pager
A sharded, zstd-compressed, reference-counted block store with an LRU pager. The pager faults the top-k relevant blocks into a bounded resident set.
Dynamic Symplectic Steering controller
DSSControllermeasures the logic volume of a key or hidden-state matrix. When the volume falls below the floor, it injects a PID-scaled counter-flow along low-variance directions.Real Metamorphic Engine
RealMetamorphicEnginerewrites a Python function's syntax tree with semantics-preserving passes. It accepts a variant whose outputs match the original on sampled inputs within tolerance and whose syntax tree differs.Invariant auditors
Subsystems check the numbered invariants: a Wilson-loop pointer auditor (I18), a sheaf collator (I19), a monodromy translation engine (I20), a Landauer erasure auditor (I21) and a kernel integrity auditor (I16).
Physics engines
A loop quantum cosmology solver for the bounce and the Wheeler-DeWitt equation (I11), a modular-form check (I12), a five-manifold symplectic simulator and a DNA base-pair soliton model.
Hardware thermal manager
HTMManagerpolls each GPU and enforces the thermal limit of Invariant I9 with a hysteretic clock control loop, emitting telemetry and alerts.Quarantine and sanitization
An epistemic quarantine controller simulates network severing, requires a two-operator signed quorum, then zeroizes keys and runs a verified three-pass overwrite.
Reasoning distillation pipeline
distill_reasoning_math.pyfine-tunes GPT-2 on reasoning problems. It is the training side of the generalization audit.
Implementation
Mechanisms as they are implemented in the source code, with the constants the code uses.
- SVD logic volume
volume.pynormalises each row of a matrix to unit norm, mean-centres the rows, takes the SVD and reports the mean singular value as the volume . approaches 0 when representations collapse onto one direction, and Invariant I6 requires with .- PID symplectic counter-flow injection
steering.pycomputes , accumulates the integral of , and sets the gain . It adds to the hidden states, where is the mean row norm, for , and holds the smallest-variance right singular vectors. Defaults are , , 12 substeps and , and the strict preset raises to 0.20.- DSS volume floor in the cache
- The cache measures the volume of the flattened key matrix. If the volume is below , times a margin of 1.2 during updates, the keys are replaced with the output of
steer_hidden. The design intent is to prevent softmax flattening. - Chunked KV offload with geometric paging
cache.pykeeps the active window at mostchunk_sizeplusrecent_tokens_pinnedtokens, 16 plus 16 by default. It offloads the oldest chunk as raw float32 bytes tagged with a 16-dimensional soliton signature, then recalls the top-k blocks by query geometry and prepends them. Thelong_context_1mpreset doubles these sizes.- Geometric-key cosine retrieval
- The pager scores each block by against its
geometric_key. Prefixes are compared on a dimension mismatch, and blocks without a key score 0. - Content-addressed store with reference-count GC
- A block address is the SHA-256 of its raw bytes, and a duplicate put increments a reference count. Payloads are zstd-compressed at level 3 by default, and the shard is
int(hex[:8],16)modulo the shard count (4, or 8 in production). Garbage collection drops zero-reference blocks older than the retention time of 1 hour, or 24 hours in production. - LRU working-set pager
pager.pybounds anOrderedDictbyresident_budget_blocks(16 by default, 32 in production). Hits are moved to the end, misses fault in from compressed storage, andpopitem(last=False)evicts the least recently used block.- Pseudo-spectral split-step KdV integrator
kdv.pysolves with wavenumbers . The dispersion half-step is applied exactly as in Fourier space, and the nonlinear term is a first-order Euler step using a spectral derivative. The position invariance claimed for context chunks is asserted by identity, not simulated.- Metamorphic invariant I17
- Five AST transformers apply algebraic identities, parameter renaming, dead XOR assignments, an always-true opaque predicate and state-machine control-flow flattening. A variant passes if sampled outputs match the original within rtol and atol of 1e-5, the SHA-256 AST hash differs, and token Jaccard divergence is at least 0.20.
- Answer-only distillation with volume barrier
- Only answer tokens carry labels, and the prompt prefix is set to -100. The learning rate follows . The loss is with the geometric mean of singular values, but is computed in numpy, so the penalty has no gradient path.
- Hidden-norm regularizer labelled symplectic
train_gpt2_gsm8k_symplectic.pydescribes its extra term as Hamiltonian conservation. It actually computes over layer-6 hidden states, and the importedleapfrog_stepis never called.- SU(2) Wilson loop pointer safety
gauge.pyforms over pointer events, where allocation and free cancel as . Use-after-free multiplies by and double free by . I18 requires within 1e-4, a value hardcoded even thoughWLSConfigdefines its own tolerance.- Sheaf gluing merge
- Local sections are dictionaries over key covers, and an overlap is the set of shared keys. If every pairwise overlap agrees within an absolute tolerance of 1e-6, the union is returned as the unique global section. Otherwise the merge raises
SheafMergeConflictError. - Loop quantum cosmology bounce
solver.pyintegrates and with , using a fourth-order Ruth-Yoshida scheme with . Gravitational entropy vanishes at the bounce. The stiff-matter shear damping factor equals 1 under the default settings, so it has no effect.- Polymer Wheeler-DeWitt difference operator
dewitt.pybuilds a tridiagonal matrix with coefficients and solves it by dense eigendecomposition. It selects the eigenvalue nearest zero, although a code comment says lowest positive.- Landauer bound via rank deficiency
thermodynamics.pycounts erased bits as , with an SVD tolerance of 1e-7, and the minimum heat as at K. An operator counts as reversible only if it is square and full rank.- Symplecticity and reversibility test
benchmarks.pyrequires for the forward-difference Jacobian of one phase-space step, which is I1. It also requires a forward-then-reverse error of at most 1e-10 (I2) and a manifold departure of at most 1e-6, on Euclidean, Poincaré-ball, sphere, torus and projective geometries.- Peyrard-Bishop-Dauxois DNA model with telomere halting
- Base-pair opening follows a Morse potential with eV for G/C, eV for A/T, and , plus nonlinear stacking with , and . Each leapfrog step consumes at least one telomere unit from a budget of 5000, and more under relative energy drift, so the code stops a run within 5000 steps (I13).
- Hysteretic thermal DVFS control
- A GPU enters RED at and YELLOW at , with C. It leaves each zone only after cooling a further . Clocks are cut by 100 MHz in yellow and 300 MHz in red, with a floor of 300 MHz.
- Two-man quorum for irreversible actions
- A nonce is , valid for 300 s in production. Both trusted operators must sign it as before keys are zeroized and memory is overwritten in three passes: a pattern, its inverse, then zeros.
- Well-founded descent recursion guard
- Each pushed frame must satisfy and a depth of at most 64. A violation raises
UncheckedRecursionError, and the kernel integrity auditor uses this guard for Invariant I16.
Results
From the lab's own experiments and records. They have not been independently replicated.
Distilled GPT-2 memorised but did not generalise
In the lab's audit, GPT-2 trained to a loss below 0.0002 scored 100% on its 24 distilled problems and 0 of 16 on held-out problems.
Topos KV cache and DSS alone did not recover accuracy
With the Topos cache and the I6 volume floor active, the evaluation records report a logic volume of 0.220 and I6 satisfied, but held-out accuracy stayed at 0 of 16. The lab's own code audit found that in this regime the cache is only logged.
Hybrid engine's 16 of 16 does not show generalisation
The lab recorded 100% on the 16 held-out problems, with logic volume 4.273 and Invariants I6 and I17 passed, when steering, metamorphic verification and external solvers were all active. The lab's own code audit found that the oracle regime mostly returns hardcoded or expected answers, so the result does not show generalisation.
Memory savings stated but not measured
The lab's records give 8x to 30x RAM savings for the Topos cache. The lab's own code audit found no measurement of that range.
Soliton memory stores raw bytes
The lab's own code audit shows that
SolitonBufferreturns the exact stored bytes rather than decoding from the soliton signature, and that soliton position invariance is asserted by identity rather than simulated.Volume penalty in distillation has no gradient
The 0.01-weighted volume barrier is computed in numpy, so it cannot influence training. A second regulariser labelled symplectic is a hidden-norm penalty, and its imported integrator is unused.
Several checks are weaker than their names
The monodromy isomorphism reduces to equal loop counts, the LQC I1 check perturbs one Jacobian entry, and the default shear damping factor is exactly 1. MinHash deduplication has no LSH banding despite its docstring, and the Dirac clock is lock-based although described as lock-free.
Concepts
- Key-value cache
- The store of attention keys and values a transformer keeps for past tokens so they are not recomputed. Its memory grows with context length, which is the cost the Topos cache targets.
- Logic volume
- The lab's scalar measure of how spread out a set of representations is: the mean singular value of the row-normalised, centred matrix. It falls toward zero when vectors collapse onto one direction.
- Invariant I6
- The condition with . The lab ties it to preventing attention softmax flattening and mid-context collapse.
- Symplectic map
- A phase-space transformation whose Jacobian has determinant 1, so it preserves volume and is reversible. DSS describes its counter-flow in these terms, and the test suite checks the property on integrators.
- KdV soliton
- A solitary wave of the Korteweg-de Vries equation that keeps its shape, energy and speed as it travels. SWM uses it as a model for position-invariant chunk signatures.
- Lost-in-the-middle
- The tendency of long-context models to neglect information placed in the middle of the context. The lab presents soliton memory as its remedy.
- Content addressing
- Naming a block by a cryptographic hash of its bytes, so identical content is stored once and any change gives a new address. HTFS and SWM both use SHA-256 for this.
- Working-set pager
- A bounded resident cache of blocks drawn from larger compressed storage, with misses faulted in and the least recently used block evicted, as in operating-system paging.
- Invariants I0 to I22
- Numbered conditions that subsystems check, from a constitutional floor at I0 through volume, thermal, purge and physics checks to the later safety and code conditions I15 to I22. Some of the checks are heuristics, and some have no effect under default settings.
- Held-out evaluation
- Testing on problems that received no gradient updates or steering projections during distillation. In the lab's audit these were the last 2 rows of each of eight datasets.
- External formal oracles
- Deterministic checkers that verify a deduction before it is emitted. In the lab's full hybrid engine these were a Z3 SMT solver, a C++ sandbox and scientific calculators.
- Metamorphic verification
- Producing program variants that differ in form but must agree in behaviour, then checking that agreement on sampled inputs. This is the basis of Invariant I17.
- Wilson loop holonomy
- The product of group elements accumulated around a closed path. The pointer auditor encodes memory events as SU(2) elements so that a correct allocate-free history multiplies back to the identity.
- Sheaf gluing
- The rule that local data agreeing on every overlap combine into exactly one global object. The collator uses it to merge partial dictionaries, and it is Invariant I19.
- Loop quantum cosmology bounce
- A model in which quantum geometry corrections halt collapse at a critical density and reverse it, replacing the Big Bang singularity. Invariant I11 checks that gravitational entropy vanishes there.
- Landauer bound
- The minimum heat dissipated per erased bit. The erasure auditor counts erased bits from the rank deficiency of a linear operator.
- Telomeric halting
- A countdown budget of which each cycle consumes at least one unit, and more under numerical instability, so the code stops a simulation within the initial budget. Invariant I13 is the condition tied to this budget.
- Three evaluation regimes
- The lab's comparison of static distilled weights, static weights with the Topos KV cache and DSS, and the full hybrid engine with steering, metamorphic verification and oracles.
About this page
Written from the lab's own documents and source code. Figures and results are the lab's measurements as it recorded them at the time, and have not been independently replicated.
Published under the PolyForm Noncommercial License 1.0.0: free for noncommercial use.