pub struct PyTorchCompat {
pub weights: HashMap<String, TensorInfo>,
pub config: ModelConfig,
pub torch_version: String,
}Expand description
PyTorch-compatible weight export/import
Provides utilities to save and load tokenizer weights in a format compatible with PyTorch models using safetensors.
Fields§
§weights: HashMap<String, TensorInfo>Model weights as named tensors
config: ModelConfigModel configuration
torch_version: StringPyTorch version compatibility
Implementations§
Source§impl PyTorchCompat
impl PyTorchCompat
Sourcepub fn new(config: ModelConfig) -> Self
pub fn new(config: ModelConfig) -> Self
Create a new PyTorch compatibility wrapper
Sourcepub fn add_weight_1d(&mut self, name: impl Into<String>, array: &Array1<f32>)
pub fn add_weight_1d(&mut self, name: impl Into<String>, array: &Array1<f32>)
Add a 1D weight tensor (bias, etc.)
Sourcepub fn get_weight(&self, name: &str) -> TokenizerResult<Array2<f32>>
pub fn get_weight(&self, name: &str) -> TokenizerResult<Array2<f32>>
Get a weight tensor as Array2
Sourcepub fn get_weight_1d(&self, name: &str) -> TokenizerResult<Array1<f32>>
pub fn get_weight_1d(&self, name: &str) -> TokenizerResult<Array1<f32>>
Get a 1D weight tensor
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> TokenizerResult<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> TokenizerResult<()>
Save to safetensors format (PyTorch compatible)
Sourcepub fn load<P: AsRef<Path>>(path: P) -> TokenizerResult<Self>
pub fn load<P: AsRef<Path>>(path: P) -> TokenizerResult<Self>
Load from safetensors format
Sourcepub fn weight_names(&self) -> Vec<String>
pub fn weight_names(&self) -> Vec<String>
Export weight names for ONNX mapping
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get total number of parameters
Trait Implementations§
Source§impl Clone for PyTorchCompat
impl Clone for PyTorchCompat
Source§fn clone(&self) -> PyTorchCompat
fn clone(&self) -> PyTorchCompat
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 PyTorchCompat
impl Debug for PyTorchCompat
Source§impl<'de> Deserialize<'de> for PyTorchCompat
impl<'de> Deserialize<'de> for PyTorchCompat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PyTorchCompat
impl RefUnwindSafe for PyTorchCompat
impl Send for PyTorchCompat
impl Sync for PyTorchCompat
impl Unpin for PyTorchCompat
impl UnwindSafe for PyTorchCompat
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more