Skip to main content

RILA: Recursive Indexed Language Architecture — a production-ready PyTorch implementation

Project description

pyrila

RILA: Recursive Indexed Language Architecture

A production-ready PyTorch implementation of the RILA architecture — a novel language model that combines contextual indexing, adaptive retrieval, recursive internal reasoning, and autonomous result verification.

Key Features

  • Contextual Indexing — Organizes input into Context Cells with a dynamic affinity graph for fast retrieval
  • Adaptive Retrieval — Learns what, when, and how much context to retrieve without specialized datasets
  • Recursive Reasoning — Internal reasoning loop with budget control, no intermediate text generation
  • Self-Verification — Multi-dimensional confidence evaluation before committing to output
  • Scale-Invariant — Same architecture from 2M to 1.3B+ parameters

How RILA Differs from Traditional Transformers

Traditional transformers apply dense attention over all tokens at every layer, scaling quadratically with context length. RILA replaces this with structured context cells and a learned affinity graph — only relevant cells are retrieved and processed deeply, enabling sub-quadratic scaling. The recursive reasoning loop allows the model to iteratively refine its understanding with autonomous budget control, something fixed-depth transformers cannot do.

Architecture

┌────────────────────────────────────────────────────────────────────┐
│                     RILA PIPELINE                                   │
│                                                                    │
│  Input Tokens                                                      │
│       │                                                            │
│       ▼                                                            │
│  [Tokenizer] → [Cell Builder] → [Cell Encoder]                    │
│                                       │                            │
│                                       ▼                            │
│                              [Context Index]  (affinity graph)     │
│                                       │                            │
│                                       ▼                            │
│                         [Recursive Context Explorer]               │
│                                       │                            │
│                                       ▼                            │
│                             [Working Context]                      │
│                                       │                            │
│                                       ▼                            │
│                        [Core Language Processor]                   │
│                           (iterative GRU + convergence)            │
│                                       │                            │
│                                       ▼                            │
│                         [Pre-Output Generator]                     │
│                                       │                            │
│                                       ▼                            │
│                   [Recursive Verification Engine]                  │
│                          confidence >= τ ?                         │
│                         /              \                           │
│                       Yes               No                        │
│                        │                 │                         │
│                        │      [Reasoning Loop]                    │
│                        │      (budget-limited)                    │
│                        │           │                              │
│                        ▼           ▼                              │
│                     [Final Decoder]                                │
│                          │                                        │
│                          ▼                                        │
│                    Output Tokens                                   │
└────────────────────────────────────────────────────────────────────┘

See docs/ARCHITECTURE.md for the full architecture explanation with mathematical formulas.

Installation

pip install pyrila

For development:

git clone https://github.com/bueormnew/pyrila.git
cd pyrila
pip install -e ".[dev]"

Quick Start

import torch
from pyrila import RILA, RILAConfig, rila_small

# Create a small model for testing
config = rila_small()
model = RILA(config)

# Forward pass with teacher forcing
input_ids = torch.randint(0, config.vocab_size, (1, 1024))
target_ids = torch.randint(0, config.vocab_size, (1, 64))
outputs = model(input_ids, target_ids=target_ids)

print(f"Logits shape: {outputs['logits'].shape}")
print(f"Confidence: {outputs['confidence'].mean().item():.4f}")
print(f"Budget used: {outputs['budget_used']} cycles")

Preset Configurations

Preset Parameters Use Case
rila_small() ~2M Testing and prototyping
rila_base() ~125M Research experiments
rila_large() ~350M Production workloads
rila_xl() ~1.3B Maximum capability

Training

from pyrila import RILA, RILATrainer, rila_small

config = rila_small()
model = RILA(config)
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4)
trainer = RILATrainer(model, optimizer, use_uncertainty_weighting=True)

batch = {
    "input_ids": torch.randint(0, config.vocab_size, (2, 1024)),
    "target_ids": torch.randint(0, config.vocab_size, (2, 64)),
}
result = trainer.train_step(batch)
print(f"Loss: {result['loss']:.4f}")

Error Handling

pyrila provides a hierarchy of custom exceptions for clear, actionable error messages:

from pyrila import PyRILAError, ConfigurationError, SequenceTooLongError

# All pyrila exceptions inherit from PyRILAError
try:
    output = model(input_ids)
except PyRILAError as e:
    print(f"pyrila error: {e}")

# Specific exceptions provide context
try:
    config = RILAConfig(hidden_dim=100, num_heads=12)
except ConfigurationError as e:
    print(e.param_name, e.value)  # "hidden_dim", 100

Available exceptions: ConfigurationError, IndexNotBuiltError, DivergenceError, GradientError, TeacherForcingError, SequenceTooLongError, BudgetExhaustedError, CheckpointError.

Documentation

Contributing

Contributions are welcome! To get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Install development dependencies: pip install -e ".[dev]"
  4. Run tests: pytest tests/ -v
  5. Submit a pull request

Please ensure all tests pass and follow the existing code style.

Citation

@software{pyrila2024,
  title={pyrila: Recursive Indexed Language Architecture},
  author={RILA Team},
  year={2024},
  url={https://github.com/bueormnew/pyrila},
  version={0.1.0}
}

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrila-0.1.0.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrila-0.1.0-py3-none-any.whl (45.6 kB view details)

Uploaded Python 3

File details

Details for the file pyrila-0.1.0.tar.gz.

File metadata

  • Download URL: pyrila-0.1.0.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrila-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdc822a3db01b33b99a9005bb253f98da38992507f96bc1f17f97381a0194017
MD5 f1f9e075115ff2bbbd98e96d33cac683
BLAKE2b-256 4267115cdf1457f2a4f65e84617d6162c52267bc1dc4098d475cfe3665edd611

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrila-0.1.0.tar.gz:

Publisher: publish.yml on bueormnew/pyrila

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrila-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyrila-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 45.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyrila-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06358c66e2b19742df20edb7c2b57e7864dd94e94bdf88b48335913dd3914162
MD5 47e1fc5a2b936e0380e4ad92c63e77ff
BLAKE2b-256 7b69c8f2efc81efce00864ae6d1b9f1693c3c09f0762ad8271419b45c521c288

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrila-0.1.0-py3-none-any.whl:

Publisher: publish.yml on bueormnew/pyrila

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page