pub struct ReveEncoder {
pub model_cfg: ModelConfig,
pub device: Device,
/* private fields */
}Fields§
§model_cfg: ModelConfig§device: DeviceImplementations§
Source§impl ReveEncoder
impl ReveEncoder
Sourcepub fn load(
config_path: &Path,
weights_path: &Path,
device: Device,
) -> Result<(Self, f64)>
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}pub fn describe(&self) -> String
pub fn params(&self) -> &ParamMap
pub fn n_patches(&self) -> usize
Sourcepub fn prep_inputs(
&self,
signal: Vec<f32>,
positions_xyz: &[f32],
n_channels: usize,
n_times: usize,
) -> Result<(Vec<f32>, Vec<f32>)>
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.
Sourcepub fn run_at_layer(
&mut self,
signal: Vec<f32>,
positions_xyz: Vec<f32>,
n_channels: usize,
n_times: usize,
layer_end: usize,
) -> Result<ReveOutput>
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.
Sourcepub fn run_one(
&mut self,
signal: Vec<f32>,
positions_xyz: Vec<f32>,
n_channels: usize,
n_times: usize,
) -> Result<ReveOutput>
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§
impl !RefUnwindSafe for ReveEncoder
impl !Sync for ReveEncoder
impl !UnwindSafe for ReveEncoder
impl Freeze for ReveEncoder
impl Send for ReveEncoder
impl Unpin for ReveEncoder
impl UnsafeUnpin for ReveEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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