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
impl CModule
sourcepub fn load<T: AsRef<Path>>(path: T) -> Result<CModule, TchError>
pub fn load<T: AsRef<Path>>(path: T) -> Result<CModule, TchError>
Loads a PyTorch saved JIT model from a file.
sourcepub fn load_on_device<T: AsRef<Path>>(
path: T,
device: Device
) -> Result<CModule, TchError>
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.
sourcepub fn load_data<T: Read>(f: &mut T) -> Result<CModule, TchError>
pub fn load_data<T: Read>(f: &mut T) -> Result<CModule, TchError>
Loads a PyTorch saved JIT model from a read instance.
sourcepub fn load_data_on_device<T: Read>(
f: &mut T,
device: Device
) -> Result<CModule, TchError>
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.
sourcepub fn forward_ts<T: Borrow<Tensor>>(
&self,
ts: &[T]
) -> Result<Tensor, TchError>
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.
sourcepub fn forward_is<T: Borrow<IValue>>(
&self,
ts: &[T]
) -> Result<IValue, TchError>
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.
sourcepub fn method_ts<T: Borrow<Tensor>>(
&self,
method_name: &str,
ts: &[T]
) -> Result<Tensor, TchError>
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.
sourcepub fn method_is<T: Borrow<IValue>>(
&self,
method_name: &str,
ts: &[T]
) -> Result<IValue, TchError>
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.
sourcepub fn create_class_is<T: Borrow<IValue>>(
&self,
clz_name: &str,
ts: &[T]
) -> Result<IValue, TchError>
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
sourcepub fn f_set_eval(&mut self) -> Result<(), TchError>
pub fn f_set_eval(&mut self) -> Result<(), TchError>
Switches the module to evaluation mode.
sourcepub fn f_set_train(&mut self) -> Result<(), TchError>
pub fn f_set_train(&mut self) -> Result<(), TchError>
Switches the module to training mode.
sourcepub fn to(&mut self, device: Device, kind: Kind, non_blocking: bool)
pub fn to(&mut self, device: Device, kind: Kind, non_blocking: bool)
Moves the module to a different device and converts the kind.
sourcepub fn save<T: AsRef<Path>>(&self, path: T) -> Result<(), TchError>
pub fn save<T: AsRef<Path>>(&self, path: T) -> Result<(), TchError>
Saves a module to a given path.