Collector

Struct Collector 

Source
pub struct Collector {
    pub tensors: Vec<TensorSnapshot>,
    /* private fields */
}
Expand description

Collects tensor views from modules without copying data.

This collector traverses a module hierarchy and creates lightweight views of tensors that can be materialized to TensorData on demand.

§Examples

§Collect all tensors

let collector = Collector::new(None, None);
// Use with module.visit(&mut collector);
let all_tensors = collector.tensors;

§Filter with single pattern

let filter = PathFilter::new().with_regex(r"^encoder\..*");
let collector = Collector::new(Some(filter), None);
// Use with module.visit(&mut collector);
// Only collects tensors starting with "encoder."

§Filter with multiple patterns (OR union)

let filter = PathFilter::new()
    .with_regex(r"^encoder\..*")  // Match all encoder tensors
    .with_regex(r".*\.bias$");    // OR match any bias tensors
let collector = Collector::new(Some(filter), None);
// Use with module.visit(&mut collector);
// Collects tensors matching ANY of the patterns

Fields§

§tensors: Vec<TensorSnapshot>

Collection of tensor views

Implementations§

Source§

impl Collector

Source

pub fn new( filter: Option<PathFilter>, adapter: Option<Box<dyn ModuleAdapter>>, ) -> Self

Create a new tensor view collector with an optional filter and adapter.

§Arguments
  • filter - An optional PathFilter to determine which tensors to collect. When None, all tensors are collected.
  • adapter - Optional adapter to transform tensors based on container types. Applied to all collected tensors before returning.
§Examples
// Collect all tensors without adapter
let collector = Collector::new(None, None);

// Use PathFilter builder
let filter = PathFilter::new()
    .with_regex(r"^encoder\..*")
    .with_full_path("decoder.weight");
let collector = Collector::new(Some(filter), None);
Source

pub fn into_tensors(self) -> Vec<TensorSnapshot>

Apply the adapter to collected tensors and return the result.

Trait Implementations§

Source§

impl Default for Collector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<B: Backend> ModuleVisitor<B> for Collector

Source§

fn enter_module(&mut self, name: &str, container_type: &str)

Called when entering a submodule. Read more
Source§

fn exit_module(&mut self, _name: &str, _container_type: &str)

Called when exiting a submodule. Read more
Source§

fn visit_float<const D: usize>(&mut self, param: &Param<Tensor<B, D>>)

Visit a float parameter in the module. Read more
Source§

fn visit_int<const D: usize>(&mut self, param: &Param<Tensor<B, D, Int>>)

Visit an int parameter in the module. Read more
Source§

fn visit_bool<const D: usize>(&mut self, param: &Param<Tensor<B, D, Bool>>)

Visit a bool parameter in the module. Read more
Source§

fn visit_float_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D>, )

Visit a float tensor with its full module path. Read more
Source§

fn visit_int_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D, Int>, )

Visit an int tensor with its full module path. Read more
Source§

fn visit_bool_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D, Bool>, )

Visit a bool tensor with its full module path. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V