pub struct KeyRemapper {
pub patterns: Vec<(Regex, String)>,
}Expand description
Key remapper for transforming tensor names.
This allows mapping tensor names from one naming convention to another, which is useful for loading models from different frameworks or versions.
§Examples
// Create a key remapper
let remapper = KeyRemapper::new()
.add_pattern(r"^pytorch\.(.*)", "burn.$1").expect("valid regex") // pytorch.layer -> burn.layer
.add_pattern(r"\.gamma$", ".weight").expect("valid regex"); // layer.gamma -> layer.weight
// Use remapper with stores
// store.remap(remapper)Fields§
§patterns: Vec<(Regex, String)>Pattern-based remapping rules (regex pattern, replacement string)
Implementations§
Source§impl KeyRemapper
impl KeyRemapper
Sourcepub fn add_pattern<S1, S2>(self, from: S1, to: S2) -> Result<Self, Error>
pub fn add_pattern<S1, S2>(self, from: S1, to: S2) -> Result<Self, Error>
Sourcepub fn from_compiled_patterns(patterns: Vec<(Regex, String)>) -> Self
pub fn from_compiled_patterns(patterns: Vec<(Regex, String)>) -> Self
Create from a list of compiled regex patterns
Sourcepub fn from_pattern_iter<I, S1, S2>(iter: I) -> Result<Self, Error>
pub fn from_pattern_iter<I, S1, S2>(iter: I) -> Result<Self, Error>
Sourcepub fn to_regex_pairs(&self) -> Vec<(Regex, String)>
pub fn to_regex_pairs(&self) -> Vec<(Regex, String)>
Convert to the format expected by remap_tensor_paths_with_patterns
Sourcepub fn remap(
&self,
tensors: Vec<TensorSnapshot>,
) -> (Vec<TensorSnapshot>, Vec<(String, String)>)
pub fn remap( &self, tensors: Vec<TensorSnapshot>, ) -> (Vec<TensorSnapshot>, Vec<(String, String)>)
Trait Implementations§
Source§impl Clone for KeyRemapper
impl Clone for KeyRemapper
Source§fn clone(&self) -> KeyRemapper
fn clone(&self) -> KeyRemapper
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KeyRemapper
impl Debug for KeyRemapper
Source§impl Default for KeyRemapper
impl Default for KeyRemapper
Source§fn default() -> KeyRemapper
fn default() -> KeyRemapper
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for KeyRemapper
impl RefUnwindSafe for KeyRemapper
impl Send for KeyRemapper
impl Sync for KeyRemapper
impl Unpin for KeyRemapper
impl UnwindSafe for KeyRemapper
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