Skip to main content

ReveEncoder

Struct ReveEncoder 

Source
pub struct ReveEncoder {
    pub model_cfg: ModelConfig,
    pub device: Device,
    /* private fields */
}

Fields§

§model_cfg: ModelConfig§device: Device

Implementations§

Source§

impl ReveEncoder

Source

pub fn load( config_path: &Path, weights_path: &Path, device: Device, ) -> Result<(Self, f64)>

Examples found in repository?
examples/benchmark.rs (line 66)
61fn main() -> anyhow::Result<()> {
62    let args = Args::parse();
63    let dev = parse_device(&args.device)?;
64    let (config, weights) = locate_paths(args.config, args.weights)?;
65
66    let (mut enc, _) = ReveEncoder::load(&config, &weights, dev)?;
67
68    let n_chans = args.n_chans;
69    let n_times = args.n_times;
70    let signal = vec![0.0f32; n_chans * n_times];
71    let positions = vec![0.0f32; n_chans * 3];
72
73    for _ in 0..args.warmup {
74        let out = enc.run_one(signal.clone(), positions.clone(), n_chans, n_times)?;
75        anyhow::ensure!(
76            out.output.iter().all(|v| v.is_finite()),
77            "warmup produced non-finite values"
78        );
79    }
80
81    let mut times = Vec::with_capacity(args.repeats);
82    let mut last_dim = 0usize;
83    for _ in 0..args.repeats {
84        let t0 = Instant::now();
85        let out = enc.run_one(signal.clone(), positions.clone(), n_chans, n_times)?;
86        anyhow::ensure!(
87            out.output.iter().all(|v| v.is_finite()),
88            "run produced non-finite values"
89        );
90        last_dim = out.output.len();
91        times.push(t0.elapsed().as_secs_f64() * 1000.0);
92    }
93
94    let times_str: Vec<String> = times.iter().map(|t| format!("{t:.4}")).collect();
95    println!(
96        "{{\"times_ms\": [{}], \"backend\": \"{}\", \"ok\": true, \"output_dim\": {}}}",
97        times_str.join(", "),
98        backend_name(dev),
99        last_dim,
100    );
101    Ok(())
102}
Source

pub fn describe(&self) -> String

Source

pub fn params(&self) -> &ParamMap

Source

pub fn n_patches(&self) -> usize

Source

pub fn prep_inputs( &self, signal: Vec<f32>, positions_xyz: &[f32], n_channels: usize, n_times: usize, ) -> Result<(Vec<f32>, Vec<f32>)>

CPU-side pre-processing: per-channel z-score on signal, then patch-extract [n_channels, n_patches, patch_size] (flat [n_chans*n_patches, patch_size]) and emit the 4-D position vectors [n_chans*n_patches, 4] (the 4th axis is patch index). Both outputs are inputs to the RLX graph.

Source

pub fn run_at_layer( &mut self, signal: Vec<f32>, positions_xyz: Vec<f32>, n_channels: usize, n_times: usize, layer_end: usize, ) -> Result<ReveOutput>

Run REVE up to (but not including) layer_end of the transformer, returning the raw hidden state [s * embed_dim] flattened (s = n_channels * n_patches). Skips the final classification / attention-pool head. Caller is responsible for any downstream pooling. layer_end is clamped to depth.

Used for “intermediate-layer feature extraction” experiments where later layers may have specialised away from generic EEG structure.

Source

pub fn run_one( &mut self, signal: Vec<f32>, positions_xyz: Vec<f32>, n_channels: usize, n_times: usize, ) -> Result<ReveOutput>

Examples found in repository?
examples/benchmark.rs (line 74)
61fn main() -> anyhow::Result<()> {
62    let args = Args::parse();
63    let dev = parse_device(&args.device)?;
64    let (config, weights) = locate_paths(args.config, args.weights)?;
65
66    let (mut enc, _) = ReveEncoder::load(&config, &weights, dev)?;
67
68    let n_chans = args.n_chans;
69    let n_times = args.n_times;
70    let signal = vec![0.0f32; n_chans * n_times];
71    let positions = vec![0.0f32; n_chans * 3];
72
73    for _ in 0..args.warmup {
74        let out = enc.run_one(signal.clone(), positions.clone(), n_chans, n_times)?;
75        anyhow::ensure!(
76            out.output.iter().all(|v| v.is_finite()),
77            "warmup produced non-finite values"
78        );
79    }
80
81    let mut times = Vec::with_capacity(args.repeats);
82    let mut last_dim = 0usize;
83    for _ in 0..args.repeats {
84        let t0 = Instant::now();
85        let out = enc.run_one(signal.clone(), positions.clone(), n_chans, n_times)?;
86        anyhow::ensure!(
87            out.output.iter().all(|v| v.is_finite()),
88            "run produced non-finite values"
89        );
90        last_dim = out.output.len();
91        times.push(t0.elapsed().as_secs_f64() * 1000.0);
92    }
93
94    let times_str: Vec<String> = times.iter().map(|t| format!("{t:.4}")).collect();
95    println!(
96        "{{\"times_ms\": [{}], \"backend\": \"{}\", \"ok\": true, \"output_dim\": {}}}",
97        times_str.join(", "),
98        backend_name(dev),
99        last_dim,
100    );
101    Ok(())
102}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.