Trait Module

Source
pub trait Module {
    type Input;
    type Output;

    // Required methods
    fn forward(&self, x: &Self::Input) -> Self::Output;
    fn gather_params(&self, params: &mut HashMap<usize, Tensor>);
    fn update_params(&self, params: &mut HashMap<usize, Tensor>);
    fn gather_named_params(
        &self,
        prefix: &str,
        params: &mut HashMap<String, Tensor>,
    );
    fn update_named_params(
        &self,
        prefix: &str,
        params: &mut HashMap<String, Tensor>,
    );

    // Provided methods
    fn params(&self) -> HashMap<usize, Tensor> { ... }
    fn named_params(&self, prefix: &str) -> HashMap<String, Tensor> { ... }
    fn to_safetensors<P: AsRef<Path>>(&self, filename: P)
       where Self: Sized { ... }
    fn update_by_safetensors<P: AsRef<Path>>(
        &self,
        filenames: &[P],
        device: impl AsDevice,
    ) { ... }
}

Required Associated Types§

Required Methods§

Source

fn forward(&self, x: &Self::Input) -> Self::Output

Source

fn gather_params(&self, params: &mut HashMap<usize, Tensor>)

Source

fn update_params(&self, params: &mut HashMap<usize, Tensor>)

Source

fn gather_named_params( &self, prefix: &str, params: &mut HashMap<String, Tensor>, )

Source

fn update_named_params( &self, prefix: &str, params: &mut HashMap<String, Tensor>, )

Provided Methods§

Source

fn params(&self) -> HashMap<usize, Tensor>

Source

fn named_params(&self, prefix: &str) -> HashMap<String, Tensor>

Source

fn to_safetensors<P: AsRef<Path>>(&self, filename: P)
where Self: Sized,

Source

fn update_by_safetensors<P: AsRef<Path>>( &self, filenames: &[P], device: impl AsDevice, )

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T> Module for &'a T
where T: Module,

Source§

type Input = <T as Module>::Input

Source§

type Output = <T as Module>::Output

Source§

fn forward(&self, x: &Self::Input) -> Self::Output

Source§

fn gather_params(&self, params: &mut HashMap<usize, Tensor>)

Source§

fn update_params(&self, params: &mut HashMap<usize, Tensor>)

Source§

fn gather_named_params( &self, prefix: &str, params: &mut HashMap<String, Tensor>, )

Source§

fn update_named_params( &self, prefix: &str, params: &mut HashMap<String, Tensor>, )

Implementors§