English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español | Français | Deutsch | Português | Русский | العربية
Official PyTorch implementation of Spatio-Temporal Homomorphic Self-Bootstrapping for Tiny Recurrent Models by Ruilong Fu (furuilong2@gmail.com).
- Paper: paper/main.pdf (LaTeX source in
paper/main.tex) - Model Weights:
FURUILONG/loop-hsb-m-final(bootstrappedLoopTRM, 4.09M params) andFURUILONG/loop-hsb-m0-atomic(atomic base M0) — Hugging Face Collection
Can a 4.09M-parameter weight-tied recurrent Transformer trained strictly on single-instruction semantics (H ≤ 1) expand its algorithmic reasoning horizon without any external verifier, interpreter, or teacher model during self-improvement?
Standard verifier-free self-training methods such as majority voting and entropy minimization suffer from correlated error collapse: when a small model encounters out-of-distribution depth, repeated stochastic rollouts fail along identical shortcuts and reinforce hallucinations. Loop-HSB breaks this failure mode on a 65,536-state Z164 register virtual machine through four components:
- Static Oracle Air-Gap (
src/tiny_vm/airgap.py): Automated source-level verification guaranteesvm_oracle.pyis never imported intohsb_views.pyorbootstrap_loop.py. Atomic base pretraining is hard-bounded to H ≤ 1 with zeroWHILE_NZloops. - Direct-Free 2+2 Heterogeneous Homomorphic Views (
src/tiny_vm/hsb_views.py): Evaluates unlabeled programs along four algebraically distinct semantics-preserving graphs (π1, π2 staggered cuts with flatIFNZunrolling and distinct S4 permutation fallback at Bmax = 1; π3 reversible S4 register permutation; π4 algebraic opcode dualization and hazard-free statement swaps), accepting pseudo-labels only under ≥ 3/4 consensus. - Zero-Oracle Midpoint Latent Supervision (
src/model/loop_trm.py): Extracts high-confidence intermediate states (smid, α ∈ [0.3, 0.7]) directly from winning canonical chunk boundaries at zero extra compute, supervising both intermediate step Ytmid and terminal steps {YT-1, YT} via a shared 4-step causal autoregressive readout head. - Reset-to-M0 Balanced Compilation (
src/train/bootstrap_loop.py): Re-compiles each round from M0 on 18,000 unlabeled programs per round using 45% new frontier / 25% stratified history / 30% atomic anchor replay and 10% pseudo-validation early stopping, running natively on a single consumer GPU (< 1.1 GB peak VRAM).
All metrics report mean ± std across 3 random seeds (42, 43, 44) under an identical 18,000-program/round budget (H ≥ 4 uses strictly disjoint OOD control-flow skeletons).
| Method | H=1 EM (%) | H=2 EM (%) | H=2 pass@64 (%) | H=4 pass@64 (%) | Eff. CF Pair Acc (%) ↑ | Dead False-Flip (%) ↓ |
|---|---|---|---|---|---|---|
| B0 (Atomic Base) | 100.0 ± 0.0 | 6.2 ± 1.8 | 6.7 ± 0.9 | 0.0 ± 0.0 | 1.3 ± 0.6 | 24.5 ± 3.6 |
| B1 (Majority Voting) | 96.6 ± 3.6 | 5.7 ± 1.2 | 7.5 ± 1.1 | 0.0 ± 0.0 | 1.3 ± 0.6 | 18.2 ± 4.7 |
| B2 (FlatGPT + HSB) | 97.7 ± 0.1 | 39.6 ± 3.6 | 59.3 ± 6.6 | 4.0 ± 1.9 | 5.2 ± 2.4 | 42.3 ± 5.5 |
| FlatGPT + Mid-Aux | 98.5 ± 0.4 | 52.1 ± 2.4 | 71.7 ± 0.6 | 8.2 ± 1.7 | 9.7 ± 4.1 | 35.3 ± 4.2 |
| Loop-HSB (w/o Mid-Sup) | 96.9 ± 1.6 | 26.2 ± 3.0 | 50.2 ± 6.5 | 3.5 ± 2.2 | 1.5 ± 0.7 | 39.7 ± 6.3 |
| Loop-HSB (Full) | 98.7 ± 0.8 | 29.2 ± 2.0 | 60.5 ± 5.8 | 5.8 ± 2.1 | 5.3 ± 1.7 | 21.7 ± 4.1 |
| Upper (Oracle) | 97.5† | 14.5† | 27.0† | 9.0† | 1.5† | 8.0† |
† Evaluated on primary seed 42; all other rows report mean ± std over seeds 42, 43, 44.
- Error Decorrelation: On unseen H ∈ {2, 4} (Bmax = 1), 2+2 homomorphic consensus lifts M0 from 3.75% direct accuracy to 99.83% at 100.00% pseudo-label purity (vs. 4.31% for direct majority voting), suppressing unconditional wrong-answer collision by >5,000x (κuncond = 0.00014 vs. 0.7782). Across multi-round bootstrapping, Loop-HSB sustains 92.7% mean purity (κ = 0.0358) while majority voting collapses to 1.4% (κ = 0.8918).
- Support Expansion and Sample Complexity: Scaling unlabeled collection from 3k to 18k/round with 30% anchor replay and midpoint supervision raises H=1 retention from 70.5% to 98.7% and expands
pass@64well beyond M0's ceiling at both H=2 and OOD H=4, while matching the 100%-label oracle bound's saturation boundary at H ≥ 4.
Python 3.11+ and PyTorch 2.4+ are required. GPU training runs comfortably within 1.1 GB VRAM; unit tests and inference also run on CPU.
git clone https://github.com/furuilon/loop-hsb.git
cd loop-hsb
# Option A: standard pip
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"
# Option B: uv (faster isolated setup)
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"import torch
from src.model.hf_export import LoopTRMHubModel
from src.tiny_vm.isa import BasicOp, BasicStmt, Program, encode_input
model = LoopTRMHubModel.from_pretrained("FURUILONG/loop-hsb-m-final")
model.eval()
# Initial registers: R0=3, R1=7, R2=2, R3=9
prog = Program((
BasicStmt(BasicOp("ADDI", 0, 5)), # R0 <- (3 + 5) mod 16 = 8
BasicStmt(BasicOp("ADDI", 0, 3)), # R0 <- (8 + 3) mod 16 = 11
))
ids = encode_input((3, 7, 2, 9), prog)
x = torch.tensor([ids], dtype=torch.long)
mask = torch.ones_like(x)
pred = model.predict(x, mask, num_steps=4, temperature=0.0)
print("Predicted registers (R0..R3):", pred[0].tolist()) # [11, 7, 2, 9]Or run the bundled demo script comparing single-pass prediction with 2+2 HSB consensus:
python scripts/demo_inference.py --repo FURUILONG/loop-hsb-m-final# 1. Verify all 11 unit, semantic-homomorphism, midpoint-gradient, standalone-HF, and Air-Gap tests
pytest -v
# 2. Run the full 3-seed benchmark (seeds 42, 43, 44; resumable)
python -u run_experiments.py --seeds 42 43 44
# 3. Regenerate all 6 publication figures (vector PDF + 300 DPI PNG)
python -m src.eval.plot_paper_figs
# 4. Compile the LaTeX paper PDF
cd paper
pdflatex -interaction=nonstopmode main.tex
bibtex main
pdflatex -interaction=nonstopmode main.tex
pdflatex -interaction=nonstopmode main.texloop-hsb/
├── .github/ # CI workflow, PR template, and issue templates
├── configs/default.yaml # Architecture, 18k bootstrap, and evaluation config
├── docs/i18n/ # Multilingual README translations (10 languages)
├── src/
│ ├── tiny_vm/ # isa.py, vm_oracle.py, program_gen.py, hsb_views.py, airgap.py
│ ├── model/ # loop_trm.py (4.09M), flat_gpt.py (4.14M), modeling_loophsb.py, hf_export.py
│ ├── train/ # stage0_pretrain.py, bootstrap_loop.py, baselines.py
│ └── eval/ # eval_suite.py, plot_paper_figs.py
├── tests/ # Automated invariant, model, Air-Gap, and export tests
├── scripts/
│ ├── demo_inference.py # Minimal single-pass vs. 2+2 HSB demo
│ └── upload_to_hf.py # Hugging Face Hub uploader
├── paper/ # main.tex, references.bib, main.pdf, tables/, figures/
├── results/ # 3-seed aggregated_eval.json, v2_18k/, baseline_3k/
├── run_experiments.py # Resumable multi-seed experiment runner
├── CITATION.cff # GitHub native citation metadata
├── CODE_OF_CONDUCT.md # Contributor Covenant v2.1
├── CONTRIBUTING.md # Contribution and Air-Gap review guidelines
├── SECURITY.md # Security vulnerability disclosure policy
├── LICENSE # MIT License
├── requirements.txt # Minimum runtime and test dependencies
└── pyproject.toml # Package and pytest configuration
If you find this work useful, please cite:
@article{fu2026loophsb,
title = {Spatio-Temporal Homomorphic Self-Bootstrapping for Tiny Recurrent Models},
author = {Fu, Ruilong},
year = {2026},
url = {https://github.com/furuilon/loop-hsb}
}- Code and Model Weights: Released under the MIT License.
- Paper, Figures, and Benchmark Results: Released under Creative Commons Attribution 4.0 International (CC BY 4.0).

