pub struct FullActivationCache { /* private fields */ }Expand description
Stores all-position activations from a forward pass.
Unlike ActivationCache which stores only the last-token activation
per layer, this cache stores the full residual stream at every token
position. Each tensor has shape [seq_len, d_model].
§Example
use candle_mi::FullActivationCache;
use candle_core::{Device, Tensor};
let mut cache = FullActivationCache::with_capacity(32);
// shape [seq_len=10, d_model=128]
cache.push(Tensor::zeros((10, 128), candle_core::DType::F32, &Device::Cpu).unwrap());
// Get a single position's activation for CLT encoding
let act = cache.get_position(0, 5).unwrap(); // shape [d_model]Implementations§
Source§impl FullActivationCache
impl FullActivationCache
Sourcepub fn with_capacity(n_layers: usize) -> Self
pub fn with_capacity(n_layers: usize) -> Self
Create an empty cache with capacity for n_layers layers.
Sourcepub fn push(&mut self, tensor: Tensor)
pub fn push(&mut self, tensor: Tensor)
Add a layer’s all-position activation to the cache.
The tensor should have shape [seq_len, d_model].
Sourcepub fn get_layer(&self, layer: usize) -> Option<&Tensor>
pub fn get_layer(&self, layer: usize) -> Option<&Tensor>
Get the full activation tensor for a specific layer.
Returns shape [seq_len, d_model], or None if the layer
is not in the cache.
Sourcepub fn get_position(&self, layer: usize, position: usize) -> Result<Tensor>
pub fn get_position(&self, layer: usize, position: usize) -> Result<Tensor>
Get the activation at a specific layer and token position.
Returns shape [d_model] — compatible with CLT encode().
§Errors
Returns MIError::Hook if the layer is not in the cache or
the position is out of range.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FullActivationCache
impl !RefUnwindSafe for FullActivationCache
impl Send for FullActivationCache
impl Sync for FullActivationCache
impl Unpin for FullActivationCache
impl UnsafeUnpin for FullActivationCache
impl !UnwindSafe for FullActivationCache
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
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>
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