Struct tch::CModule

source ·
pub struct CModule { /* private fields */ }
Expand description

A jit PyTorch module.

These modules can be created via the TorchScript python api.

Implementations§

source§

impl CModule

source

pub fn load<T: AsRef<Path>>(path: T) -> Result<CModule, TchError>

Loads a PyTorch saved JIT model from a file.

source

pub fn load_on_device<T: AsRef<Path>>( path: T, device: Device ) -> Result<CModule, TchError>

Loads a PyTorch saved JIT model from a file onto the given device.

This function loads the model directly on the specified device, which means it also allows loading a GPU model on the CPU without having a CUDA enabled GPU.

source

pub fn load_data<T: Read>(f: &mut T) -> Result<CModule, TchError>

Loads a PyTorch saved JIT model from a read instance.

source

pub fn load_data_on_device<T: Read>( f: &mut T, device: Device ) -> Result<CModule, TchError>

Loads a PyTorch saved JIT model from a read instance.

This function loads the model directly on the specified device, which means it also allows loading a GPU model on the CPU without having a CUDA enabled GPU.

source

pub fn forward_ts<T: Borrow<Tensor>>( &self, ts: &[T] ) -> Result<Tensor, TchError>

Performs the forward pass for a model on some specified tensor inputs. This is equivalent to calling method_ts with the ‘forward’ method name, and returns a single tensor.

source

pub fn forward_is<T: Borrow<IValue>>( &self, ts: &[T] ) -> Result<IValue, TchError>

Performs the forward pass for a model on some specified ivalue inputs. This is equivalent to calling method_is with the ‘forward’ method name, and returns an arbitrary ivalue.

source

pub fn method_ts<T: Borrow<Tensor>>( &self, method_name: &str, ts: &[T] ) -> Result<Tensor, TchError>

Runs a specified entry point for a model on some given tensor inputs.

source

pub fn method_is<T: Borrow<IValue>>( &self, method_name: &str, ts: &[T] ) -> Result<IValue, TchError>

Runs a specified entry point for a model on some given ivalue inputs.

source

pub fn create_class_is<T: Borrow<IValue>>( &self, clz_name: &str, ts: &[T] ) -> Result<IValue, TchError>

Create a specified custom JIT class object with the given class name, eg: __torch__.foo.Bar

source

pub fn f_set_eval(&mut self) -> Result<(), TchError>

Switches the module to evaluation mode.

source

pub fn set_eval(&mut self)

Switches the module to evaluation mode.

source

pub fn f_set_train(&mut self) -> Result<(), TchError>

Switches the module to training mode.

source

pub fn set_train(&mut self)

Switches the module to training mode.

source

pub fn to(&mut self, device: Device, kind: Kind, non_blocking: bool)

Moves the module to a different device and converts the kind.

source

pub fn save<T: AsRef<Path>>(&self, path: T) -> Result<(), TchError>

Saves a module to a given path.

source

pub fn named_parameters(&self) -> Result<Vec<(String, Tensor)>, TchError>

Loads some named tensors from a module

source

pub fn create_by_tracing<F>( modl_name: &str, fn_name: &str, inputs: &[Tensor], closure: &mut F ) -> Result<CModule, TchError>
where F: FnMut(&[Tensor]) -> Vec<Tensor>,

Create a new module by tracing the application of the specified function on the given inputs.

Trait Implementations§

source§

impl Debug for CModule

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for CModule

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Module for CModule

source§

fn forward(&self, xs: &Tensor) -> Tensor

source§

impl Send for CModule

source§

impl Sync for CModule

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> ModuleT for T
where T: Module,

source§

fn forward_t(&self, xs: &Tensor, _train: bool) -> Tensor

source§

fn batch_accuracy_for_logits( &self, xs: &Tensor, ys: &Tensor, d: Device, batch_size: i64 ) -> f64

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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