Skip to main content

ProbePool

Struct ProbePool 

Source
pub struct ProbePool<'a> { /* private fields */ }
Expand description

Pools a probe head’s first softmax as positions arrive, so the cells are never all held at once.

Materialising them costs seq * cells * d_model floats — 504 MB at full context on the shipped model, which is not survivable in a browser tab. This holds cells * probes * d_model regardless of sequence length: 252 KB.

The trick is the online softmax. r = Σ_t softmax(s)_t · cell_t is computed by carrying a running maximum, denominator and numerator, and rescaling both whenever a larger score appears — algebraically identical to the two-pass form, which ProbeHead::forward still does and the tests compare against.

Implementations§

Source§

impl<'a> ProbePool<'a>

Source

pub fn new(head: &'a ProbeHead, d_model: usize) -> Self

Source

pub fn observe(&mut self, cell_index: usize, cell: &[f32])

Feed one position’s cell for one cell index (0 is the input embedding).

Order does not matter — the pooling is a sum over positions — so a caller may stream all positions for one cell before moving to the next, which is how the forward pass is laid out.

Source

pub fn finish(self) -> Vec<f32>

Finish the pooling and run the head’s second softmax and projection.

Auto Trait Implementations§

§

impl<'a> Freeze for ProbePool<'a>

§

impl<'a> RefUnwindSafe for ProbePool<'a>

§

impl<'a> Send for ProbePool<'a>

§

impl<'a> Sync for ProbePool<'a>

§

impl<'a> Unpin for ProbePool<'a>

§

impl<'a> UnsafeUnpin for ProbePool<'a>

§

impl<'a> UnwindSafe for ProbePool<'a>

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.