pub struct SensorEncoderConfig {
pub time_steps: usize,
pub num_channels: usize,
pub patch_h: usize,
pub patch_w: usize,
pub d_model: usize,
pub depth: usize,
pub num_heads: usize,
pub mlp_dim: usize,
pub dropout: f64,
pub pool_type: PoolType,
pub head_zeroinit: bool,
pub attn_chunk_size: usize,
}Expand description
Configuration for the Vision Transformer sensor encoder.
The encoder treats wearable sensor data as a 2-D grid
(TIME_STEPS × NUM_CHANNELS) and divides it into rectangular patches of
shape (patch_h × patch_w).
Fields§
§time_steps: usizeNumber of time-steps in the input signal (default: 1440 = 24 h × 60 min).
num_channels: usizeNumber of sensor channels (features) per time-step (default: 34).
patch_h: usizePatch height (time axis), default: 10 minutes.
patch_w: usizePatch width (channel axis), default: 2 channels.
d_model: usizeTransformer hidden dimension (ViT-B = 768).
depth: usizeNumber of transformer layers (ViT-B = 12).
num_heads: usizeNumber of attention heads per layer (ViT-B = 12).
mlp_dim: usizeFeed-forward MLP hidden dimension (ViT-B = 3072).
dropout: f64Dropout probability applied inside each transformer block.
pool_type: PoolTypeType of sequence pooling used after the transformer.
"map" (Multihead Attention Pooling) is the default and matches the
reference implementation. "gap" (global average pooling) is a
cheaper alternative.
head_zeroinit: boolWhether to zero-initialise the output projection in the MAP head.
attn_chunk_size: usizeChunked-attention window size (number of query rows per chunk).
Limits forward-pass peak attention memory from O(B·H·N²) to
O(B·H·chunk·N) and keeps individual WGPU GPU dispatches small
enough to avoid OS watchdog (TDR) timeouts.
⚠ Training caveat — chunking does NOT save backward memory.
Burn’s autodiff tape records every intermediate tensor produced inside
the chunk loop (q_chunk, scores, attn, chunk_out). All chunks
for all layers are kept alive simultaneously until loss.backward()
completes. True backward memory savings require gradient checkpointing,
which is not yet implemented.
Rule of thumb for GPU VRAM (fp32, ViT-B, N = 2448, H = 12):
| chunk | fwd attn @ B=4 | fwd attn @ B=8 |
|---|---|---|
| 2448 (off) | 4.3 GB | 8.6 GB |
| 256 | 450 MB | 900 MB |
| 128 | 225 MB | 450 MB |
| 64 | 112 MB | 225 MB |
Set to 0 to disable chunking (full N×N matrix — not recommended
on GPU due to TDR risk and peak memory).
Default: 64.
Implementations§
Source§impl SensorEncoderConfig
impl SensorEncoderConfig
Sourcepub fn num_patches(&self) -> usize
pub fn num_patches(&self) -> usize
Total number of patches = (time_steps / patch_h) × (num_channels / patch_w).
Channel dimension is padded up to the next multiple of patch_w if
num_channels is not evenly divisible.
Trait Implementations§
Source§impl Clone for SensorEncoderConfig
impl Clone for SensorEncoderConfig
Source§fn clone(&self) -> SensorEncoderConfig
fn clone(&self) -> SensorEncoderConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SensorEncoderConfig
impl Debug for SensorEncoderConfig
Source§impl Default for SensorEncoderConfig
impl Default for SensorEncoderConfig
Source§impl<'de> Deserialize<'de> for SensorEncoderConfig
impl<'de> Deserialize<'de> for SensorEncoderConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for SensorEncoderConfig
impl RefUnwindSafe for SensorEncoderConfig
impl Send for SensorEncoderConfig
impl Sync for SensorEncoderConfig
impl Unpin for SensorEncoderConfig
impl UnsafeUnpin for SensorEncoderConfig
impl UnwindSafe for SensorEncoderConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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