pub struct TensorCapture { /* private fields */ }Expand description
Captures intermediate tensors during crate::LlamaContext::decode.
Attach with LlamaContextParams::with_tensor_capture before creating the
context. The same instance can be reused across decodes if you call
Self::clear between passes.
§Lifetime
The capture must outlive the crate::LlamaContext it is wired into;
LlamaContextParams::with_tensor_capture takes &mut TensorCapture to
enforce this at compile time.
Implementations§
Source§impl TensorCapture
impl TensorCapture
Sourcepub fn for_layers(layer_indices: &[usize]) -> Self
pub fn for_layers(layer_indices: &[usize]) -> Self
Capture transformer layer outputs "l_out-{N}" for the given indices.
This is the usual choice for hidden-state extraction. EAGLE-3 draft models
often use three layers at ~50%, 75%, and 100% depth — e.g. [13, 20, 27]
on a 28-layer model.
Sourcepub fn for_names(names: &[&str]) -> Self
pub fn for_names(names: &[&str]) -> Self
Capture tensors whose graph names match exactly.
Example names: "result_norm", "l_out-27".
Sourcepub fn for_prefix(prefix: &str) -> Self
pub fn for_prefix(prefix: &str) -> Self
Capture every tensor whose name starts with prefix.
Useful for families like "attn_out-*" or "attn_norm-*".
Sourcepub fn all() -> Self
pub fn all() -> Self
Capture all graph nodes.
Warning: memory use scales with model size and sequence length. Prefer
Self::for_layers or Self::for_names in production code.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop captured tensors but keep the filter (safe to call before another decode).
Sourcepub fn get(&self, name: &str) -> Option<&CapturedTensor>
pub fn get(&self, name: &str) -> Option<&CapturedTensor>
Lookup by full graph name (e.g. "l_out-13").
Sourcepub fn get_layer(&self, layer_idx: usize) -> Option<&CapturedTensor>
pub fn get_layer(&self, layer_idx: usize) -> Option<&CapturedTensor>
Lookup a layer output ("l_out-{layer_idx}").
Sourcepub fn has_layer(&self, layer_idx: usize) -> bool
pub fn has_layer(&self, layer_idx: usize) -> bool
Whether "l_out-{layer_idx}" was captured in the last decode.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &CapturedTensor)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &CapturedTensor)>
Iterate (name, tensor) pairs from the last decode.
Sourcepub fn captured_layers(&self) -> Vec<usize>
pub fn captured_layers(&self) -> Vec<usize>
Sorted layer indices present among captured "l_out-*" tensors.