pub struct ModuleBase {
pub parameters: HashMap<String, Parameter>,
/* private fields */
}Expand description
Base module implementation helper
Fields§
§parameters: HashMap<String, Parameter>Implementations§
Source§impl ModuleBase
impl ModuleBase
pub fn new() -> Self
Sourcepub fn set_training(&mut self, training: bool)
pub fn set_training(&mut self, training: bool)
Set training mode
Sourcepub fn apply_to_parameters<F>(&mut self, f: F) -> Result<()>
pub fn apply_to_parameters<F>(&mut self, f: F) -> Result<()>
Apply function to all parameters in this module
Sourcepub fn apply_to_modules<F>(&mut self, f: F) -> Result<()>
pub fn apply_to_modules<F>(&mut self, f: F) -> Result<()>
Apply function to all modules recursively
Sourcepub fn named_children(&self) -> Vec<(String, &dyn Module)>
pub fn named_children(&self) -> Vec<(String, &dyn Module)>
Get named children modules
Sourcepub fn named_parameters(&self) -> HashMap<String, Parameter>
pub fn named_parameters(&self) -> HashMap<String, Parameter>
Get named parameters
Sourcepub fn to_device(&mut self, device: DeviceType) -> Result<()>
pub fn to_device(&mut self, device: DeviceType) -> Result<()>
Move to device
Sourcepub fn register_parameter(&mut self, name: String, param: Parameter)
pub fn register_parameter(&mut self, name: String, param: Parameter)
Register a parameter
Sourcepub fn register_buffer(&mut self, name: String, tensor: Tensor)
pub fn register_buffer(&mut self, name: String, tensor: Tensor)
Register a buffer
Sourcepub fn register_module(&mut self, name: String, module: Box<dyn Module>)
pub fn register_module(&mut self, name: String, module: Box<dyn Module>)
Register a submodule
Sourcepub fn all_parameter_tensors(&self) -> Vec<Arc<RwLock<Tensor>>>
pub fn all_parameter_tensors(&self) -> Vec<Arc<RwLock<Tensor>>>
Get all parameters including submodules (legacy method)
Sourcepub fn get_all_named_parameters(&self) -> HashMap<String, Parameter>
pub fn get_all_named_parameters(&self) -> HashMap<String, Parameter>
Get all parameters with module hierarchical names
Sourcepub fn all_named_parameters(&self) -> HashMap<String, Arc<RwLock<Tensor>>>
pub fn all_named_parameters(&self) -> HashMap<String, Arc<RwLock<Tensor>>>
Get all named parameters including submodules
Sourcepub fn register_hook(
&mut self,
hook_type: HookType,
callback: HookCallback,
) -> HookHandle
pub fn register_hook( &mut self, hook_type: HookType, callback: HookCallback, ) -> HookHandle
Register a hook for this module
Sourcepub fn remove_hook(&mut self, hook_type: HookType, handle: HookHandle) -> bool
pub fn remove_hook(&mut self, hook_type: HookType, handle: HookHandle) -> bool
Remove a hook by handle
Sourcepub fn execute_hooks(
&self,
hook_type: HookType,
module: &dyn Module,
input: &Tensor,
output: Option<&Tensor>,
) -> Result<()>
pub fn execute_hooks( &self, hook_type: HookType, module: &dyn Module, input: &Tensor, output: Option<&Tensor>, ) -> Result<()>
Execute hooks of a specific type
Sourcepub fn hook_count(&self, hook_type: HookType) -> usize
pub fn hook_count(&self, hook_type: HookType) -> usize
Get hook count for a specific type
Sourcepub fn clear_hooks(&mut self, hook_type: HookType)
pub fn clear_hooks(&mut self, hook_type: HookType)
Clear all hooks of a specific type
Sourcepub fn clear_all_hooks(&mut self)
pub fn clear_all_hooks(&mut self)
Clear all hooks
Trait Implementations§
Source§impl Debug for ModuleBase
impl Debug for ModuleBase
Auto Trait Implementations§
impl Freeze for ModuleBase
impl !RefUnwindSafe for ModuleBase
impl Send for ModuleBase
impl Sync for ModuleBase
impl Unpin for ModuleBase
impl UnsafeUnpin for ModuleBase
impl !UnwindSafe for ModuleBase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more