pub struct HalfPrecisionAdapter { /* private fields */ }Expand description
Adapter for mixed-precision (F32/F16) model storage.
Auto-detects conversion direction from the snapshot’s dtype:
- F32 source -> cast to F16 (typical for saving)
- F16 source -> cast to F32 (typical for loading)
- Other dtypes -> passed through unchanged
The same instance works for both with_to_adapter (save) and with_from_adapter (load).
By default, converts weights in: Linear, Embedding, Conv*, LayerNorm, GroupNorm,
InstanceNorm, RmsNorm, PRelu. BatchNorm is excluded because running_var underflows in F16.
§Examples
Default usage (same adapter for save and load):
let adapter = HalfPrecisionAdapter::new();
// store.with_to_adapter(adapter.clone()); // F32 -> F16 on save
// store.with_from_adapter(adapter); // F16 -> F32 on loadExclude a module type:
let adapter = HalfPrecisionAdapter::new()
.without_module("LayerNorm");Add a custom module type:
let adapter = HalfPrecisionAdapter::new()
.with_module("CustomLayer");Implementations§
Source§impl HalfPrecisionAdapter
impl HalfPrecisionAdapter
Sourcepub fn with_module(self, module_type: impl Into<String>) -> Self
pub fn with_module(self, module_type: impl Into<String>) -> Self
Add a module type to convert. Accepts both short ("MyLayer") and
qualified ("Struct:MyLayer") forms.
Note: short names are mapped to "Struct:Name". If you have an Enum-based
module, use the qualified form "Enum:MyModule" explicitly.
Sourcepub fn without_module(self, module_type: impl Into<String>) -> Self
pub fn without_module(self, module_type: impl Into<String>) -> Self
Remove a module type from conversion. Accepts both short and qualified forms.
Trait Implementations§
Source§impl Clone for HalfPrecisionAdapter
impl Clone for HalfPrecisionAdapter
Source§fn clone(&self) -> HalfPrecisionAdapter
fn clone(&self) -> HalfPrecisionAdapter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more