pub trait ModuleAdapter: Send + Sync {
// Required methods
fn adapt(&self, snapshot: &TensorSnapshot) -> TensorSnapshot;
fn clone_box(&self) -> Box<dyn ModuleAdapter>;
// Provided methods
fn get_alternative_param_name(
&self,
_param_name: &str,
_container_type: &str,
) -> Option<String> { ... }
fn chain<A>(self, next: A) -> ChainAdapter
where Self: Sized + 'static,
A: ModuleAdapter + 'static { ... }
}Expand description
Trait for adapting tensor snapshots between different module formats
Required Methods§
Sourcefn adapt(&self, snapshot: &TensorSnapshot) -> TensorSnapshot
fn adapt(&self, snapshot: &TensorSnapshot) -> TensorSnapshot
Adapt a tensor snapshot based on its container type and parameter name
Sourcefn clone_box(&self) -> Box<dyn ModuleAdapter>
fn clone_box(&self) -> Box<dyn ModuleAdapter>
Clone the adapter into a boxed trait object
Provided Methods§
Sourcefn get_alternative_param_name(
&self,
_param_name: &str,
_container_type: &str,
) -> Option<String>
fn get_alternative_param_name( &self, _param_name: &str, _container_type: &str, ) -> Option<String>
Get alternative parameter name to try during matching
When looking for a parameter in a module, this method provides an alternative name to try if the direct name doesn’t match. This enables matching parameters with different naming conventions (e.g., PyTorch’s “weight” vs Burn’s “gamma”).
§Arguments
param_name- The parameter name we’re looking forcontainer_type- The type of container module (e.g., “BatchNorm”)
§Returns
Alternative parameter name to try, or None if no alternative exists
Sourcefn chain<A>(self, next: A) -> ChainAdapterwhere
Self: Sized + 'static,
A: ModuleAdapter + 'static,
fn chain<A>(self, next: A) -> ChainAdapterwhere
Self: Sized + 'static,
A: ModuleAdapter + 'static,
Chain adapters together, applying self first and then next.
This is useful when multiple transformations are required when importing model weights (e.g. PyTorch -> Burn layout conversion, then dtype casting, then custom remapping).
The semantics follow a simple pipeline:
adapt:next.adapt(&self.adapt(snapshot))get_alternative_param_name: tryselffirst; if it returns an alternative name, trynextwith that name, otherwise return the first alternative name.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".