pub struct StateDictMapper { /* private fields */ }Implementations§
Source§impl StateDictMapper
impl StateDictMapper
Sourcepub fn rename(self, from: impl Into<String>, to: impl Into<String>) -> Self
pub fn rename(self, from: impl Into<String>, to: impl Into<String>) -> Self
Rename a single key
If the key doesn’t exist, this operation is a no-op.
Sourcepub fn rename_prefix(
self,
old_prefix: impl Into<String>,
new_prefix: impl Into<String>,
) -> Self
pub fn rename_prefix( self, old_prefix: impl Into<String>, new_prefix: impl Into<String>, ) -> Self
Rename all keys with a given prefix
Example: rename_prefix("old.", "new.") changes “old.weight” to “new.weight”
Sourcepub fn strip_prefix(self, prefix: impl Into<String>) -> Self
pub fn strip_prefix(self, prefix: impl Into<String>) -> Self
Strip a prefix from all keys
Example: strip_prefix("model.") changes “model.encoder.weight” to “encoder.weight”
Sourcepub fn add_prefix(self, prefix: impl Into<String>) -> Self
pub fn add_prefix(self, prefix: impl Into<String>) -> Self
Add a prefix to all keys
Example: add_prefix("encoder.") changes “weight” to “encoder.weight”
Sourcepub fn transpose(self, key: impl Into<String>) -> Self
pub fn transpose(self, key: impl Into<String>) -> Self
Transpose a specific 2D tensor (for Linear weight conversion)
PyTorch Linear layers store weights as [out_features, in_features],
while Volta stores them as [in_features, out_features].
This operation only affects 2D tensors. Non-2D tensors are left unchanged.
Sourcepub fn transpose_pattern(self, pattern: impl Into<String>) -> Self
pub fn transpose_pattern(self, pattern: impl Into<String>) -> Self
Transpose all tensors matching a pattern
Example: transpose_pattern("weight") transposes all keys containing “weight”
Sourcepub fn select_keys(self, keys: Vec<String>) -> Self
pub fn select_keys(self, keys: Vec<String>) -> Self
Select only specific keys (for partial loading)
All other keys are removed from the state dict.
Sourcepub fn exclude_keys(self, keys: Vec<String>) -> Self
pub fn exclude_keys(self, keys: Vec<String>) -> Self
Exclude specific keys
The specified keys are removed from the state dict.
Sourcepub fn transform<F>(self, f: F) -> Self
pub fn transform<F>(self, f: F) -> Self
Apply a custom transformation function
This allows arbitrary transformations beyond the built-in methods.