reve-rs
Pure-Rust inference for the REVE (Representation for EEG with Versatile Embeddings) foundation model, built on RLX.
REVE is pretrained on 60,000+ hours of EEG data from 92 datasets spanning 25,000 subjects. Its key innovation is a 4D Fourier positional encoding scheme that enables generalization across arbitrary electrode configurations without retraining.
Architecture
EEG [B, C, T]
│
├─ Overlapping Patch Extraction (unfold)
│ → [B, C, n_patches, patch_size]
│
├─ Linear Patch Embedding
│ → [B, C*n_patches, embed_dim]
│
├─ 4D Positional Encoding (Fourier + MLP)
│ (x, y, z, t) → [B, C*n_patches, embed_dim]
│
├─ Transformer Encoder (RMSNorm, GEGLU, Multi-Head Attention)
│ → [B, C*n_patches, embed_dim]
│
└─ Classification Head (Flatten+LN+Linear or Attention Pooling)
→ [B, n_outputs]
Quick Start
use ;
use Device;
use Path;
let = load?;
let output = model.run_one?;
println!;
Build
# CPU (default)
# Apple Metal GPU
# Apple MLX
# HuggingFace weight download helper
CLI Inference
# Download weights (requires HuggingFace access)
# Run inference (CPU / Metal / MLX)
Benchmarks & validation
Full RLX suite (build backends, infer smoke tests, parity, JSON benchmarks):
This writes figures/benchmark_rlx_results.json and plots via bench_rlx.py. Example on Apple Silicon (22ch × 1000t, reve-base):
| Backend | Mean latency |
|---|---|
| RLX CPU | ~53 ms |
| RLX Metal | ~21 ms (steady state) |
| RLX MLX | ~21 ms |
Backend parity
CPU is the reference. Metal and MLX must match within tolerance on real reve-base weights:
Typical full-model drift (RLX 0.2.6): Metal max abs ≈ 8×10⁻⁴, MLX ≈ 2×10⁻³ (cosine ≈ 1.0). Metal uses MPSGraph with erf-based GELU (matching CPU) and unfused elementwise regions on deep graphs.
Features
| Feature | Description |
|---|---|
rlx, rlx-cpu (default) |
RLX CPU runtime |
rlx-metal |
Apple Metal |
rlx-mlx |
Apple MLX |
rlx-gpu, rlx-cuda, rlx-rocm, rlx-tpu |
Other RLX targets |
rlx-blas-accelerate, rlx-blas-openblas, rlx-blas-mkl |
BLAS for RLX CPU |
hf-download |
HuggingFace Hub weight download |
Pretrained Weights
Weights are on HuggingFace:
| Model | Params | Embed Dim | Layers |
|---|---|---|---|
brain-bzh/reve-base |
72M | 512 | 22 |
brain-bzh/reve-large |
~400M | 1250 | — |
Note: You must agree to the data usage terms on HuggingFace before downloading.
Citation
If you use this crate in your research, please cite both the REVE paper and this implementation:
Author
References
- El Ouahidi et al. (2025). REVE: A Foundation Model for EEG — Adapting to Any Setup with Large-Scale Pretraining on 25,000 Subjects. NeurIPS 2025.
- braindecode Python implementation
License
Apache-2.0