pub trait ModuleVisitor<B: Backend> {
// Provided methods
fn visit_float<const D: usize>(&mut self, param: &Param<Tensor<B, D>>) { ... }
fn visit_int<const D: usize>(&mut self, param: &Param<Tensor<B, D, Int>>) { ... }
fn visit_bool<const D: usize>(&mut self, param: &Param<Tensor<B, D, Bool>>) { ... }
fn enter_module(&mut self, name: &str, container_type: &str) { ... }
fn exit_module(&mut self, name: &str, container_type: &str) { ... }
fn visit_float_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D>,
) { ... }
fn visit_int_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D, Int>,
) { ... }
fn visit_bool_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D, Bool>,
) { ... }
}Expand description
Module visitor trait for traversing and inspecting module parameters.
Provided Methods§
Sourcefn visit_float<const D: usize>(&mut self, param: &Param<Tensor<B, D>>)
fn visit_float<const D: usize>(&mut self, param: &Param<Tensor<B, D>>)
Sourcefn enter_module(&mut self, name: &str, container_type: &str)
fn enter_module(&mut self, name: &str, container_type: &str)
Called when entering a submodule.
§Parameters
name: The name of the submodule being enteredcontainer_type: The type of the container with format:- For user-defined structs: “Struct:TypeName” (e.g., “Struct:Linear”)
- For user-defined enums: “Enum:TypeName” (e.g., “Enum:MyEnum”)
- For Vec containers: “Vec” (name is the index)
- For Tuple containers: “Tuple” (name is the index)
- For Array containers: “Array” (name is the index)
Note: Option containers do not call enter_module/exit_module to preserve the field name in the path (e.g., “bias” instead of “bias.Some”)
Sourcefn exit_module(&mut self, name: &str, container_type: &str)
fn exit_module(&mut self, name: &str, container_type: &str)
Called when exiting a submodule.
§Parameters
name: The name of the submodule being exitedcontainer_type: The type of the container with format:- For user-defined structs: “Struct:TypeName” (e.g., “Struct:Linear”)
- For user-defined enums: “Enum:TypeName” (e.g., “Enum:MyEnum”)
- For Vec containers: “Vec” (name is the index)
- For Tuple containers: “Tuple” (name is the index)
- For Array containers: “Array” (name is the index)
Note: Option containers do not call enter_module/exit_module to preserve the field name in the path (e.g., “bias” instead of “bias.Some”)
Sourcefn visit_float_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D>,
)
fn visit_float_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D>, )
Visit a float tensor with its full module path.
§Parameters
path: The path components to the tensor as a slice (e.g., &[“encoder”, “layer1”, “weight”]). Each element represents a module name in the hierarchy, with the final element being the parameter name. This allows efficient reuse of the path stack.id: The unique identifier of the parametertensor: The float tensor to visit
Sourcefn visit_int_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D, Int>,
)
fn visit_int_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D, Int>, )
Visit an int tensor with its full module path.
§Parameters
path: The path components to the tensor as a slice (e.g., &[“encoder”, “layer1”, “weight”]). Each element represents a module name in the hierarchy, with the final element being the parameter name. This allows efficient reuse of the path stack.id: The unique identifier of the parametertensor: The integer tensor to visit
Sourcefn visit_bool_with_path<const D: usize>(
&mut self,
path: &[String],
id: ParamId,
tensor: &Tensor<B, D, Bool>,
)
fn visit_bool_with_path<const D: usize>( &mut self, path: &[String], id: ParamId, tensor: &Tensor<B, D, Bool>, )
Visit a bool tensor with its full module path.
§Parameters
path: The path components to the tensor as a slice (e.g., &[“encoder”, “layer1”, “weight”]). Each element represents a module name in the hierarchy, with the final element being the parameter name. This allows efficient reuse of the path stack.id: The unique identifier of the parametertensor: The boolean tensor to visit
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".