| Crates.io | intellichip-rs |
| lib.rs | intellichip-rs |
| version | 0.1.0 |
| created_at | 2025-12-23 03:53:44.197039+00 |
| updated_at | 2025-12-23 03:53:44.197039+00 |
| description | Tiny Recursive Models for fast opcode routing and sequence prediction |
| homepage | https://github.com/blackfall-labs/intellichip |
| repository | https://github.com/blackfall-labs/intellichip |
| max_upload_size | |
| id | 2000719 |
| size | 160,054 |
Rust implementation of Tiny Recursive Models (TRM) for fast, accurate opcode routing and sequence prediction
IntelliChip-RS is a high-performance Rust implementation of Tiny Recursive Models (TRM), designed for:
Think of it as a neural ISA (Instruction Set Architecture) where small recursive models chain together to make routing decisions 34x faster than traditional LLMs at 214x smaller model size.
Add to your Cargo.toml:
[dependencies]
intellichip-rs = "0.1"
Or install CLI tools:
cargo install intellichip-rs-cli
Validate the implementation against Python TinyRecursiveModels:
# Train on Sudoku (target: 75-87% accuracy)
cargo run --release --bin train_sudoku
# Monitor training
tail -f /tmp/sudoku_training.log
# Train opcode router
cargo run --release --bin train_opcode \
--data training_data/opcodes.jsonl \
--epochs 10 \
--checkpoint-dir checkpoints_opcode
# Evaluate on test set
cargo run --release --bin evaluate_opcode \
--checkpoint checkpoints_opcode/final_model.safetensors \
--test-data training_data/test.jsonl
use intellichip_rs::{TinyRecursiveModel, TRMConfig};
use candle_core::{Device, Tensor};
// Load model
let config = TRMConfig {
vocab_size: 256,
num_outputs: 50,
hidden_size: 512,
h_cycles: 3,
l_cycles: 6,
// ... other params
};
let device = Device::Cpu;
let model = TinyRecursiveModel::new(&config, &device)?;
// Load checkpoint
model.load_checkpoint("checkpoints/model.safetensors")?;
// Run inference
let input_ids = Tensor::new(&[...], &device)?;
let logits = model.forward(&input_ids)?;
let predicted_opcode = logits.argmax(D::Minus1)?;
The Tiny Recursive Model uses a recursive transformer architecture with:
See TRM-SPEC.md for detailed architecture specification.
For complex routing tasks, chain multiple TRMs:
Layer 0: Intent Classifier (1M params, 10ms)
↓
Layer 1: Trust Risk Assessor (500K params, 5ms)
↓
Layer 2: Opcode Router (7M params, 40ms)
↓
Layer 3: Confidence Validator (1M params, 10ms)
↓
Final Opcode Output (Total: ~65ms)
| Metric | IntelliChip-RS | LLM Baseline (Qwen 1.5B) |
|---|---|---|
| Latency | <100ms (CPU) | ~3.4s (CPU) |
| Accuracy | >71.4% | 71.4% (live), 80% (test) |
| Model Size | 7M params | 1.5B params (214x larger) |
| Speedup | 34x faster | baseline |
Validated against Python TinyRecursiveModels:
TRMConfig {
vocab_size: 256,
num_outputs: 50,
hidden_size: 512,
h_cycles: 3,
l_cycles: 6,
l_layers: 2,
num_heads: 8,
expansion: 4.0,
pos_encodings: "rope",
dropout: 0.0,
// ...
}
TrainingConfig {
batch_size: 8,
learning_rate: 1e-4,
lr_min: 1e-4,
warmup_steps: 2000,
weight_decay: 0.1,
grad_clip: Some(1.0),
ema_decay: 0.999,
// ...
}
Compatible with TinyRecursiveModels NumPy format:
dataset/
├── all__inputs.npy # [N, seq_len] int32
├── all__labels.npy # [N, seq_len] int32
├── all__puzzle_identifiers.npy # [M] int32
└── dataset.json # Metadata
{
"input": "multiply 45 and 12",
"candidates": [
{"opcode": "INVOKE_SKILL calculator.multiply"},
{"opcode": "INVOKE_SKILL calculator.add"},
{"opcode": "QUERY_USER clarify_intent"}
],
"target_opcode": "INVOKE_SKILL calculator.multiply",
"confidence_target": 0.95
}
intellichip-rs/
├── crates/
│ ├── tiny-recursive/ # Core TRM library
│ │ ├── src/
│ │ │ ├── config.rs # Model & training configuration
│ │ │ ├── layers/ # Attention, SwiGLU, embeddings
│ │ │ ├── models/ # TRM architecture
│ │ │ ├── training/ # Trainer, optimizer, EMA, checkpoints
│ │ │ └── data/ # NumPy & JSONL data loaders
│ │ └── Cargo.toml
│ └── tiny-recursive-cli/ # Training binaries
│ └── src/bin/
│ ├── train_sudoku.rs # Puzzle validation
│ ├── train_opcode.rs # Opcode routing
│ └── evaluate_opcode.rs
├── TRM-SPEC.md # Architecture specification
├── build_cuda.sh # CUDA build helper
└── README.md
Build with CUDA acceleration:
# Set up MSVC compiler for nvcc (Windows)
./build_cuda.sh train_sudoku
# Linux/Mac
cargo build --release --features cuda
Note: GPU training with TRM's recursive architecture (H=3 × L=6) can OOM even with small batches. CPU training with batch_size=8 is recommended for stability.
Validates Rust implementation against Python TinyRecursiveModels:
cargo run --release --bin train_sudoku
Expected Results:
Monitor model quality degradation:
cargo run --release --bin benchmark_drift \
--checkpoint checkpoints/model.safetensors \
--test-data dataset/test/
cargo test --workspace
cargo doc --open --no-deps
cargo clippy --all-targets --all-features
Original TinyRecursiveModels paper:
@article{tiny-recursive-models,
title={Tiny Recursive Models for Efficient Sequence Modeling},
author={...},
year={2024}
}
Licensed under either of:
at your option.
Contributions are welcome! Please:
cargo test and cargo clippyBuilt with ❤️ by Blackfall Labs