Active development has moved to trix-z. This repo is preserved as the historical record with full git history, archived snapshots (TriXO/TriXOR), exploration journals, and mesa session notes.
See ARCHIVED.md for what changes belong here vs ../trix-z/.
TriX is a research-oriented library for routing-driven transformer FFNs and related "compute-as-routing" experiments.
The practical throughline is treating routing as a first-class artifact you can:
- observe and measure,
- edit deliberately ("surgery"),
- compile into deterministic contracts for known cases,
- and accelerate natively without changing semantics.
Core idea: Don't learn what you can read.
Related concept note: docs/SOFT_CHIP.md (cache-resident subroutines / "soft chip" idea for training efficiency).
Related systems note: docs/CACHE_COHERENCY.md (use coherency + bucketing as a CPU primitive).
- A set of PyTorch modules under
src/trix/nn/for sparse/conditional FFNs. - A small native kernel under
src/trix/kernel/for packing and fast CPU inference (optional). - A compiler-style lane under
src/trix/compiler/for composing verified "atoms" into circuits.
- A polished, production-ready framework.
- A single claim or benchmark; the repo includes experiments of varying maturity.
See CHANGELOG.md.
Recent work highlighted in the changelog:
- Mesa 13: XOR superposition signature compression (lossless routing decisions with large compression on similar signatures).
- Install PyTorch for your platform.
- Install TriX in editable mode:
pip install -e ".[dev]"python -m pytestNotes:
- Native acceleration is optional. Tests pass without the native library.
- Some experiment tests (e.g. GMP-backed number theory) are skipped if optional deps are missing.
This repo is archived, but we still keep a CPU-first, falsifiable path that a new reader can run quickly.
P0-1Archive historical snapshots: movedTriXO/+TriXOR/toarchive/to prevent accidentalpip install -e .namespace shadowing (they both declarename = "trix").P0-2Fix doc link rot: repaired references and copied Mesa 11/12/13 docs intodocs/archive/so older changelog entries remain navigable.P0-3Formalize tier boundaries: experiment-dependent tests now skip cleanly whenexperiments/(or optional deps) are absent.P0-4Add golden-output repro scripts:scripts/repro/turns key changelog claims into single-command checks that diff against saved.expected.jsonoutputs.
Quick repro commands (CPU):
trix doctor
python -m pytest -q
trix bench --outdir results/benchmarks_v1 --device cpu
python scripts/repro/repro_xor_compression.py
python scripts/repro/repro_compiled_dispatch.py
python scripts/repro/repro_dft_compilation.pyNotes:
repro_dft_compilation.pyrequiresexperiments/fft_atoms/; it printsSKIPin wheel installs.
If installed in editable mode, you can use the trix CLI:
trix doctor
trix bench --outdir results/benchmarks_v1 --device cpuSee docs/CLI.md.
Canonical benchmark entrypoints live in docs/BENCHMARKS.md.
Run suite v1 (CPU-first, emits JSON + JSONL artifacts):
python experiments/benchmarks/benchmark_suite_v1.py --outdir results/benchmarks_v1 --device cpuIf you're integrating TriX into an existing model, start here.
import torch
from trix.nn import DropInFFN, DropInConfig
x = torch.randn(2, 128, 512)
ffn = DropInFFN(
DropInConfig(d_model=512, num_tiles=64, tiles_per_cluster=8),
mode="dynamic", # or: contracted|packed
)
y = ffn(x) # drop-in: returns a tensor
# Optional training signal
y, routing_info, aux_losses = ffn(x, return_aux=True)
loss = some_task_loss(y) + aux_losses["total_aux"]import torch
from trix import SparseLookupFFN
x = torch.randn(2, 128, 512) # (batch, seq, d_model)
ffn = SparseLookupFFN(
d_model=512,
num_tiles=64,
tiles_per_cluster=8,
)
output, routing_info, aux_losses = ffn(x)
loss = some_task_loss(output) + aux_losses["total_aux"]from trix.nn import SparseLookupFFNv2, CompiledDispatch
ffn = SparseLookupFFNv2(d_model=128, num_tiles=16, ternary_weight=0.01)
output, info, aux = ffn(x, labels=class_labels)
compiler = CompiledDispatch(ffn)
compiler.compile_stable(threshold=0.5)
output, info, aux = compiler.forward(x, class_hint=0, confidence=0.9)See docs/QUICKSTART.md and examples/basic_usage.py.
dynamic: research mode; routing is computed each forwardcontracted: compile stable classes into a dispatch contract and guard itpacked: ternary address mode using XOR+POPCNT distances (inputs ternarized viasign(x))
Developer-first entrypoints:
trix doctor(self-check)trix bench(writessuite_v1.json+ telemetry)trix export-bundle/trix load-bundle(portable address plane)
See docs/CLI.md and docs/BUNDLE_SCHEMA.md.
Many routing variants in this repo reduce to a simple kernel:
signature = tile_weights.sum(dim=0).sign() # What the tile wants
score = input @ signature # How well input matches
route = (score == scores.max()) # Send to best matchThe work is in making this primitive stable and operable at scale (normalization, tie-breaking/top-k, load balancing, differentiable surrogates for training, and compilation/guardrails for deployment).
TriX includes a small C++ library used by trix.kernel for packing and a fast forward path.
Build:
cmake -S src/trix/kernel -B src/trix/kernel/build
cmake --build src/trix/kernel/build -jCorrectness note:
- When the native library is present,
tests/test_kernel_reference_harness.pyenforces native-vs-reference equivalence.
This repo also contains a standalone C++ routing benchmark harness under native/.
Build and run:
cmake -S native -B native/build
cmake --build native/build -j
./native/build/trix_routebench --benchmark routing
./native/build/trix_routebench --benchmark stability --flip-prob 0.01See native/README.md.
There is a benchmark script that compares FFN variants on TinyShakespeare:
python scripts/benchmark_ffn.pyTreat these numbers as a reproducible starting point, not as a universal claim.
src/trix/
nn/ # routing-driven FFNs and related modules
kernel/ # optional native kernel bindings + packing
compiler/ # circuit compilation lane
qat/ # quantization-aware training
tests/ # test suite
examples/ # usage examples
scripts/ # benchmarks and validations
experiments/ # research experiments (may require optional deps)
notes/ # process / journals / exploration
docs/ # documentation
native/ # standalone C++ routing tools
See CHANGELOG.md for version history.
MIT.