Learning & research
Tiny Recursive Model Inspect recursive reasoning, model telemetry and a headless learning simulation.
Code & guide What to expect This directory includes code and documentation. Its guide defines dependencies, execution modes and what the results demonstrate.
Guides & runbooks 2
Registered commands 0 Environment setup ↗ Guided tour Inspect the sources Try it locally Architecture Complete library
A CLOSER LOOK
When does another reasoning pass help? For researchers and evaluators: explore a small recursive model, early halting, synthetic task accuracy and the cost of repeated computation.
01 02 Trace the executable journey The explain command introduces the model; simulate loads or creates the configured checkpoint, then compares synthetic trials under sentinel and thermostat controls.
demo/Tiny-Recursive-Model-v0/run_demo.py ↗ Inspect this source ↓ 03
REAL REPOSITORY MATERIAL
Inspect. Understand. Reproduce. Reading the exact source at revision 5b4cebb3. This browser inspection does not execute the demo.
demo/Tiny-Recursive-Model-v0/config/trm_demo_config.yaml
Select a walkthrough step to explore its source.
Show more fields ↓ Full source text owner:
address: "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
name: "AGI Jobs Superintelligence Steward"
thermostat:
target_roi: 2.0
window: 20
min_inner_cycles: 3
max_inner_cycles: 8
min_outer_steps: 2
max_outer_steps: 5
min_halt_threshold: 0.45
max_halt_threshold: 0.85
min_concurrency: 1
max_concurrency: 6
sentinel:
min_roi: 1.25
max_daily_cost: 75.0
max_latency_ms: 2000
max_total_cycles: 18
failure_backoff_limit: 5
ledger:
value_per_success: 100.0
base_compute_cost: 0.001
cost_per_cycle: 0.0001
daily_budget: 50.0
trm:
input_dim: 12
latent_dim: 32
hidden_dim: 48
output_dim: 2
inner_cycles: 6
outer_steps: 3
halt_threshold: 0.55
max_cycles: 18
ema_decay: 0.999
learning_rate: 0.0015
weight_decay: 0.0001
batch_size: 64
epochs: 4
device: "cpu"
telemetry:
enable_structured_logs: true
write_path: "demo/Tiny-Recursive-Model-v0/assets/telemetry.jsonl"
ethereum:
rpc_url: "https://mainnet.infura.io/v3/YOUR_KEY_HERE"
chain_id: 1
logging_contract: "0x0000000000000000000000000000000000000000"
confirmations_required: 2
report:
path: "demo/Tiny-Recursive-Model-v0/assets/trm_executive_report.md"
SHA-256 0635f054ae5c297dbd4ccee5725f05c495df26956f74fac6caea2bd6e88c0d56
The first source is shown in full. All walkthrough source links and the complete document library remain available without JavaScript.
{"revision":"5b4cebb309a83a7a6749d8911d8bf96a1921e042","sources":[{"file":"demo/Tiny-Recursive-Model-v0/config/trm_demo_config.yaml","content":"owner:\n address: \"0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF\"\n name: \"AGI Jobs Superintelligence Steward\"\nthermostat:\n target_roi: 2.0\n window: 20\n min_inner_cycles: 3\n max_inner_cycles: 8\n min_outer_steps: 2\n max_outer_steps: 5\n min_halt_threshold: 0.45\n max_halt_threshold: 0.85\n min_concurrency: 1\n max_concurrency: 6\nsentinel:\n min_roi: 1.25\n max_daily_cost: 75.0\n max_latency_ms: 2000\n max_total_cycles: 18\n failure_backoff_limit: 5\nledger:\n value_per_success: 100.0\n base_compute_cost: 0.001\n cost_per_cycle: 0.0001\n daily_budget: 50.0\ntrm:\n input_dim: 12\n latent_dim: 32\n hidden_dim: 48\n output_dim: 2\n inner_cycles: 6\n outer_steps: 3\n halt_threshold: 0.55\n max_cycles: 18\n ema_decay: 0.999\n learning_rate: 0.0015\n weight_decay: 0.0001\n batch_size: 64\n epochs: 4\n device: \"cpu\"\ntelemetry:\n enable_structured_logs: true\n write_path: \"demo/Tiny-Recursive-Model-v0/assets/telemetry.jsonl\"\nethereum:\n rpc_url: \"https://mainnet.infura.io/v3/YOUR_KEY_HERE\"\n chain_id: 1\n logging_contract: \"0x0000000000000000000000000000000000000000\"\n confirmations_required: 2\n\nreport:\n path: \"demo/Tiny-Recursive-Model-v0/assets/trm_executive_report.md\"\n","format":"text","sha256":"0635f054ae5c297dbd4ccee5725f05c495df26956f74fac6caea2bd6e88c0d56","bytes":1182,"download":"/AGIJobsv0/examples/0635f054ae5c297d-trm_demo_config.yaml","source":"https://github.com/MontrealAI/AGIJobsv0/blob/5b4cebb309a83a7a6749d8911d8bf96a1921e042/demo/Tiny-Recursive-Model-v0/config/trm_demo_config.yaml"},{"file":"demo/Tiny-Recursive-Model-v0/run_demo.py","content":"\"\"\"Command line interface for the Tiny Recursive Model demo.\"\"\"\nfrom __future__ import annotations\n\nfrom pathlib import Path\nfrom typing import Optional\n\nimport typer\nfrom rich import box\nfrom rich.console import Console\nfrom rich.table import Table\n\nfrom trm_demo.config import DemoSettings, load_settings\nfrom trm_demo.engine import TrmEngine\nfrom trm_demo.ledger import EconomicLedger\nfrom trm_demo.sentinel import Sentinel\nfrom trm_demo.simulation import run_simulation\nfrom trm_demo.thermostat import Thermostat\n\napp = typer.Typer(\n help=\"Tiny Recursive Model demo orchestrated by AGI Jobs v0 (v2)\",\n invoke_without_command=True,\n)\nconsole = Console()\n\n\ndef _load_settings(config_path: Optional[Path]) -> DemoSettings:\n base = Path(__file__).resolve().parent\n path = config_path or (base / \"config\" / \"default_trm_config.yaml\")\n return load_settings(path)\n\n\ndef _ensure_checkpoint(engine: TrmEngine, checkpoint_path: Path) -> None:\n if checkpoint_path.exists():\n console.print(f\"[green]Loading checkpoint {checkpoint_path}[/green]\")\n engine.load_checkpoint(checkpoint_path)\n else:\n console.print(\n \"[yellow]No checkpoint found. Run `python run_demo.py train` first for best results.[/yellow]\"\n )\n\n\n@app.callback(invoke_without_command=True)\ndef main(ctx: typer.Context) -> None:\n \"\"\"Show guidance when no command is provided.\"\"\"\n if ctx.invoked_subcommand is not None:\n return\n\n console.print(\n \"\"\"\n[bold cyan]Tiny Recursive Model Demo[/bold cyan]\nThis CLI powers the AGI Jobs v0 (v2) Tiny Recursive Model experience. Choose a command:\n• [green]train[/green] — learn a lightweight recursive reasoner on synthetic tasks.\n• [green]simulate[/green] — benchmark TRM versus baselines with guardrails engaged.\n• [green]explain[/green] — recap what operators can do with this demo.\n \"\"\"\n )\n typer.echo(ctx.get_help())\n\n\n@app.command()\ndef train(config: Optional[Path] = typer.Option(None, help=\"Path to config YAML.\")) -> None:\n \"\"\"Train the Tiny Recursive Model on synthetic reasoning puzzles.\"\"\"\n settings = _load_settings(config)\n engine = TrmEngine(settings)\n report = engine.train()\n console.print(\"[bold green]Training completed[/bold green]\")\n console.print(f\"Epochs: {report.epochs_run}\")\n console.print(f\"Train loss: {report.train_loss:.4f}\")\n console.print(f\"Validation loss: {report.val_loss:.4f}\")\n console.print(f\"Checkpoint saved to: {report.best_checkpoint}\")\n\n\n@app.command()\ndef simulate(\n config: Optional[Path] = typer.Option(None, help=\"Path to config YAML.\"),\n trials: int = typer.Option(128, help=\"Number of tasks to simulate.\"),\n seed: int = typer.Option(0, help=\"Random seed for reproducibility.\"),\n) -> None:\n \"\"\"Simulate TRM vs. baselines and display ROI metrics.\"\"\"\n settings = _load_settings(config)\n engine = TrmEngine(settings)\n checkpoint = engine._resolve_path(settings.training.checkpoint_path)\n _ensure_checkpoint(engine, checkpoint)\n\n ledger = EconomicLedger(\n default_success_value=settings.ledger.default_success_value,\n base_cost_per_call=settings.ledger.base_cost_per_call,\n cost_per_inner_step=settings.ledger.cost_per_inner_step,\n cost_per_outer_step=settings.ledger.cost_per_outer_step,\n )\n thermostat = Thermostat(settings.thermostat)\n sentinel = Sentinel(settings.sentinel)\n\n summary = run_simulation(\n engine=engine,\n thermostat=thermostat,\n sentinel=sentinel,\n ledger=ledger,\n settings=settings,\n trials=trials,\n seed=seed,\n )\n\n table = Table(title=\"TRM Demo ROI Comparison\", box=box.ROUNDED, show_lines=True)\n table.add_column(\"Model\")\n table.add_column(\"Success Rate\", justify=\"right\")\n table.add_column(\"ROI\", justify=\"right\")\n table.add_column(\"Avg Latency (ms)\", justify=\"right\")\n table.add_column(\"Total Cost\", justify=\"right\")\n\n def _add_row(name: str, metrics) -> None:\n success_rate = metrics.successes / metrics.trials if metrics.trials else 0.0\n table.add_row(\n name,\n f\"{success_rate * 100:.1f}%\",\n f\"{metrics.roi():.2f}\",\n f\"{metrics.avg_latency():.1f}\",\n f\"${metrics.total_cost:.4f}\",\n )\n\n _add_row(\"Greedy Heuristic\", summary.greedy)\n _add_row(\"Large LLM\", summary.llm)\n _add_row(\"Tiny Recursive Model\", summary.trm)\n\n console.print(table)\n if summary.sentinel_triggered:\n console.print(\n f\"[red]Sentinel halted TRM due to: {summary.sentinel_reason}[/red]\",\n style=\"bold\",\n )\n else:\n console.print(\"[green]Sentinel guardrails nominal[/green]\")\n\n console.print(\"\\nThermostat Parameter Trace (inner, outer, halt threshold):\")\n for idx, state in enumerate(summary.thermostat_trace[:10]):\n console.print(f\" Iteration {idx + 1}: {state}\")\n\n\n@app.command()\ndef explain() -> None:\n \"\"\"Explain how AGI Jobs v0 (v2) empowers non-technical builders.\"\"\"\n console.print(\n \"\"\"\n[bold cyan]Tiny Recursive Model Demo[/bold cyan]\nThis experience turns AGI Jobs v0 (v2) into a complete co-pilot that:\n• Auto-builds training pipelines for recursive reasoning networks.\n• Instruments ROI, thermostat control, and sentinel guardrails.\n• Provides no-code levers (config YAML + Streamlit UI) so operators steer economics.\n• Delivers transparent telemetry tables and diagrams for stakeholders.\n \"\"\"\n )\n\n\nif __name__ == \"__main__\":\n app()\n","format":"text","sha256":"8ee40f874d7acd909704d24872879844a48d28f2dc70a114c9b2c9e827e6385c","bytes":5533,"download":"/AGIJobsv0/examples/8ee40f874d7acd90-run_demo.py","source":"https://github.com/MontrealAI/AGIJobsv0/blob/5b4cebb309a83a7a6749d8911d8bf96a1921e042/demo/Tiny-Recursive-Model-v0/run_demo.py"},{"file":"demo/Tiny-Recursive-Model-v0/trm_demo/simulation.py","content":"\"\"\"Simulation harness comparing TRM to baselines.\"\"\"\nfrom __future__ import annotations\n\nimport random\nfrom dataclasses import dataclass, field\nfrom typing import Dict, List, Tuple\n\nimport numpy as np\nimport torch\n\nfrom .baselines import GreedyBaseline, LLMBaseline\nfrom .config import DemoSettings\nfrom .dataset import OperationSequence, generate_sequence\nfrom .engine import TrmEngine\nfrom .ledger import EconomicLedger\nfrom .sentinel import Sentinel\nfrom .thermostat import Thermostat\n\n\n@dataclass\nclass ModelMetrics:\n successes: int = 0\n trials: int = 0\n total_cost: float = 0.0\n total_value: float = 0.0\n latencies: List[float] = field(default_factory=list)\n steps_distribution: List[int] = field(default_factory=list)\n\n def register(\n self,\n *,\n success: bool,\n cost: float,\n value: float,\n latency_ms: float,\n steps_used: int,\n ) -> None:\n self.trials += 1\n if success:\n self.successes += 1\n self.total_value += value\n self.total_cost += cost\n self.latencies.append(latency_ms)\n self.steps_distribution.append(steps_used)\n\n def roi(self) -> float:\n return self.total_value / self.total_cost if self.total_cost else float(\"inf\")\n\n def avg_latency(self) -> float:\n return float(np.mean(self.latencies)) if self.latencies else 0.0\n\n\n@dataclass\nclass SimulationSummary:\n trm: ModelMetrics\n greedy: ModelMetrics\n llm: ModelMetrics\n sentinel_triggered: bool\n sentinel_reason: str | None\n thermostat_trace: List[Tuple[int, int, float]]\n\n\ndef _encode_sequence(sequence: OperationSequence, *, input_dim: int) -> Dict[str, torch.Tensor]:\n vocab = {\n \"add\": 0,\n \"subtract\": 1,\n \"multiply\": 2,\n \"max\": 3,\n \"min\": 4,\n \"noop\": 5,\n }\n feature_dim = input_dim\n steps: List[List[float]] = []\n for op in sequence.operations:\n vector = [0.0] * feature_dim\n vector[vocab[op.op]] = 1.0\n vector[-1] = op.arg / 10.0\n steps.append(vector)\n while len(steps) < input_dim - 1:\n vector = [0.0] * feature_dim\n vector[vocab[\"noop\"]] = 1.0\n steps.append(vector)\n steps = steps[: input_dim - 1]\n start_tensor = torch.tensor([sequence.start], dtype=torch.float32)\n steps_tensor = torch.tensor(steps, dtype=torch.float32)\n length_tensor = torch.tensor(len(sequence.operations), dtype=torch.long)\n return {\"start\": start_tensor, \"steps\": steps_tensor, \"length\": length_tensor}\n\n\ndef run_simulation(\n *,\n engine: TrmEngine,\n thermostat: Thermostat,\n sentinel: Sentinel,\n ledger: EconomicLedger,\n settings: DemoSettings,\n trials: int = 128,\n seed: int = 0,\n) -> SimulationSummary:\n rng = random.Random(seed)\n # Ensure deterministic behavior across numpy, torch, and Python's RNG so\n # the sentinel consistently reflects guardrail breaches during testing.\n np.random.seed(seed)\n torch.manual_seed(seed)\n greedy = GreedyBaseline()\n llm = LLMBaseline(rng=rng)\n\n trm_metrics = ModelMetrics()\n greedy_metrics = ModelMetrics()\n llm_metrics = ModelMetrics()\n thermostat_trace: List[Tuple[int, int, float]] = []\n sentinel_triggered = False\n sentinel_reason: str | None = None\n\n for _ in range(trials):\n sequence = generate_sequence(rng=rng)\n greedy_result = greedy.infer(sequence)\n greedy_metrics.register(\n success=greedy_result.success,\n cost=greedy_result.cost,\n value=settings.ledger.default_success_value,\n latency_ms=greedy_result.latency_ms,\n steps_used=greedy_result.steps_used,\n )\n\n llm_result = llm.infer(sequence)\n llm_metrics.register(\n success=llm_result.success,\n cost=llm_result.cost,\n value=settings.ledger.default_success_value,\n latency_ms=llm_result.latency_ms,\n steps_used=llm_result.steps_used,\n )\n\n thermostat_state = thermostat.update(ledger)\n thermostat_trace.append(\n (\n thermostat_state.inner_steps,\n thermostat_state.outer_steps,\n thermostat_state.halt_threshold,\n )\n )\n\n sample = _encode_sequence(sequence, input_dim=settings.trm.input_dim)\n inference = engine.infer(\n sample,\n max_inner_steps=thermostat_state.inner_steps,\n max_outer_steps=thermostat_state.outer_steps,\n halt_threshold=thermostat_state.halt_threshold,\n )\n success = inference.prediction == sequence.target\n if success:\n ledger_entry = ledger.record_success(\n steps_used=inference.steps_used,\n halted_early=inference.halted_early,\n latency_ms=inference.latency_ms,\n )\n else:\n ledger_entry = ledger.record_failure(\n steps_used=inference.steps_used,\n halted_early=inference.halted_early,\n latency_ms=inference.latency_ms,\n )\n\n trm_metrics.register(\n success=success,\n cost=ledger_entry.cost,\n value=ledger_entry.value,\n latency_ms=inference.latency_ms,\n steps_used=inference.steps_used,\n )\n\n sentinel_status = sentinel.evaluate(\n ledger=ledger,\n last_latency_ms=inference.latency_ms,\n last_steps=inference.steps_used,\n last_success=success,\n )\n if sentinel_status.halted:\n sentinel_triggered = True\n sentinel_reason = sentinel_status.reason\n break\n\n return SimulationSummary(\n trm=trm_metrics,\n greedy=greedy_metrics,\n llm=llm_metrics,\n sentinel_triggered=sentinel_triggered,\n sentinel_reason=sentinel_reason,\n thermostat_trace=thermostat_trace,\n )\n\n\n__all__ = [\"run_simulation\", \"SimulationSummary\", \"ModelMetrics\"]\n","format":"text","sha256":"bc242cb16214eb6a95eeedc5b4cb75d3d43ace5a409fb258bb428362141fd555","bytes":6012,"download":"/AGIJobsv0/examples/bc242cb16214eb6a-simulation.py","source":"https://github.com/MontrealAI/AGIJobsv0/blob/5b4cebb309a83a7a6749d8911d8bf96a1921e042/demo/Tiny-Recursive-Model-v0/trm_demo/simulation.py"}]}
FROM READING TO A REPRODUCIBLE RUN
Try the selected path. Python + CPU model dependencies Use Python 3.12 in an isolated environment. Install demo/Tiny-Recursive-Model-v0/requirements-core.txt with --extra-index-url https://download.pytorch.org/whl/cpu, then run python -m pip check. The optional dashboard has a separate dependency profile.
Copy the environment setup python3.12 -m venv .venv-tiny-recursive-model-v0
. .venv-tiny-recursive-model-v0/bin/activate
python -m pip install -r demo/Tiny-Recursive-Model-v0/requirements-core.txt --extra-index-url https://download.pytorch.org/whl/cpu
python -m pip checkCopy Dependency files for this demo and its variants (2) Complete environment setup ↗ SELECTED EXECUTION PATH Copy
python demo/Tiny-Recursive-Model-v0/run_demo.py explain
python demo/Tiny-Recursive-Model-v0/run_demo.py simulate --trials 24 --seed 7What you should observe The terminal shows strategy results, sentinel status and a thermostat trace. First execution may train a checkpoint; use the documented CPU dependency environment.
The source inspector above reads bundled repository material. Local commands run separately on your computer. Recorded examples may contain historical timestamps, placeholders and simulated metrics.
MAKE IT YOUR OWN
One useful experiment. Repeat with the same seed, then change the number of trials. Explain how sample size affects confidence in an apparent improvement.
THE SYSTEM, MADE VISIBLE
Architecture & relationships Architecture diagram · source preserved below
View original Mermaid source flowchart LR
Operators((Mission Owners)) --> demo_Tiny_Recursive_Model_v0[[Demo → Tiny Recursive Model v0]]
demo_Tiny_Recursive_Model_v0 --> Core[[AGI Jobs v0 (v2) Core Intelligence]]
Core --> Observability[[Unified CI / CD & Observability]]
Core --> Governance[[Owner Control Plane]]
WHEN SOMETHING DOESN’T MATCH
Troubleshooting Import or dependency error Confirm the active virtual environment and the selected demo’s requirements. Run python -m pip check; do not install unrelated demo requirements over a working environment.
Unexpected result or missing file Check the selected entry point, configuration and output argument. Keep the seed and implementation fixed before comparing outcomes.
TRACE THE CHECKS
Verification & next steps 9 tracked test source files are available in this directory. Inspect the tests and their environment before choosing a suite; file counts do not establish test results.
Browse the test sources For live commissioning, consult the production readiness record .
EVERY VARIANT, PRESERVED
Complete document library REPRODUCE & INSPECT
Registered commands Run commands from the repository root after following this demo's guide. Network and owner actions require their documented setup.
No root-level launch command is associated with this source path. Follow the guide or source directory for its own entry point.
Full command catalog and troubleshooting ↗