pub trait Model: Display {
type Input;
type Output;
// Required methods
fn forward(
&mut self,
input: Self::Input,
) -> Result<Self::Output, ModelError>;
fn require_grad(&mut self, grad_enabled: bool) -> Result<(), ModelError>;
fn to_device(&mut self, device: &Device) -> Result<(), ModelError>;
fn to_dtype(&mut self, dtype: &DType) -> Result<(), ModelError>;
fn parameters(&self) -> Result<Vec<Tensor>, ModelError>;
fn named_parameters(&self) -> Result<HashMap<String, Tensor>, ModelError>;
// Provided methods
fn save(&self, file_path: &str) -> Result<(), ModelError> { ... }
fn load(
&mut self,
file_path: &str,
device: &Device,
) -> Result<(), ModelError> { ... }
}Required Associated Types§
Required Methods§
Sourcefn require_grad(&mut self, grad_enabled: bool) -> Result<(), ModelError>
fn require_grad(&mut self, grad_enabled: bool) -> Result<(), ModelError>
Sourcefn parameters(&self) -> Result<Vec<Tensor>, ModelError>
fn parameters(&self) -> Result<Vec<Tensor>, ModelError>
Get the parameters of the model.
§Returns
Ok(Vec<Tensor>)- The parameters of the model.Err(ModelError)- The error when getting the parameters of the model.
Sourcefn named_parameters(&self) -> Result<HashMap<String, Tensor>, ModelError>
fn named_parameters(&self) -> Result<HashMap<String, Tensor>, ModelError>
Get the named parameters of the model.
§Returns
Ok(HashMap<String, Tensor>)- The named parameters of the model.Err(ModelError)- The error when getting the named parameters of the model.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".