rlt-core
Recurrent Looped Transformer (RLT) in pure Rust (candle):
a causal encoder builds global key–value memory; a recurrent decoder merges each
token's encoder representation with the previous decoder output and carries the
complete state H_t = (s_t, C_t^D) (recurrent output + per-layer sliding-window
KV caches) across every prompt and response token.
Reference: Recurrent Looped Transformer (Zhang, 2026).
Features
- Paper-faithful execution: parallel causal encoder prefill, recurrent decoder over every token, incremental one-token stepping, no prompt/response state reset.
- Gated merge feedback (paper Eq. 2.9–2.11) with learned initial state s⋆.
- Sliding-window decoder self-attention + encoder-memory cross-attention.
- Tied configuration (paper §2.6): decoder SWA/FFN reuse compatible encoder weights.
- Full-BPTT training with optional SFT-style loss masking (nothing detached).
- Current-policy RL replay:
replay()rebuilds the full history under current parameters and returns log-probs + importance ratios for action tokens. - Byte-level tokenizer, greedy/temperature/top-k sampling, safetensors checkpoints.
- CPU by default;
cudafeature for NVIDIA GPUs (experimental, not validated in CI).
Quickstart
use ;
use StdRng;
use SeedableRng;
Training
use ;
use AdamW;
forward_loss(tokens, Some(&mask)) applies an SFT-style mask (1.0 = supervise);
masked tokens still update state (paper §5.2).
RL replay
use ;
Behavior log-probabilities must describe the actual sampling distribution; for
stochastic sampling record Sampler::behavior_logprob(&logits, token) per step
(paper §5.3).
License
MIT OR Apache-2.0.