Skip to main content

rlt_core/
lib.rs

1//! Recurrent Looped Transformer (RLT).
2//!
3//! A causal encoder builds global key–value memory; a recurrent decoder merges each
4//! token's encoder representation with the previous decoder output and maintains the
5//! complete state `H_t = (s_t, C_t^D)` (recurrent output + per-layer SWA caches)
6//! across every prompt and response token. See `Recurrent_Looped_Transformer.pdf`
7//! (Zhang, 2026) for the reference semantics.
8//!
9//! ```
10//! use rlt_core::{Rlt, RltConfig, ByteTokenizer, Device};
11//! # fn main() -> rlt_core::Result<()> {
12//! let model = Rlt::new(RltConfig::default(), Device::Cpu)?;
13//! let tok = ByteTokenizer::new(258)?;
14//! let (logits, state) = model.prefill(&tok.encode("Hi", true, false))?;
15//! assert_eq!(logits.len(), 3);
16//! # Ok(()) }
17//! ```
18
19pub mod checkpoint;
20pub mod config;
21pub mod error;
22pub mod execution;
23pub mod model;
24pub mod nn;
25pub mod replay;
26pub mod sampling;
27pub mod state;
28pub mod tokenizer;
29
30pub use candle_core::{Device, Tensor};
31pub use checkpoint::{load_checkpoint, save_checkpoint};
32pub use config::RltConfig;
33pub use error::{Result, RltError};
34pub use model::Rlt;
35pub use replay::{replay, ReplayResult, Rollout, SamplingMetadata};
36pub use sampling::{sample_from_logits, SampledToken, Sampler};
37pub use state::{GroupKv, LayerKv, RltState};
38pub use tokenizer::{ByteTokenizer, BOS_ID, EOS_ID, MIN_VOCAB};