pub struct WeightLoader;Expand description
Helper class to load neural network weights from Safetensors and PyTorch .bin formats.
Implementations§
Source§impl WeightLoader
impl WeightLoader
Sourcepub fn load_safetensors<B: Backend>(
path: impl AsRef<Path>,
device: &B::Device,
) -> Result<HashMap<String, Tensor<B, 2>>>
pub fn load_safetensors<B: Backend>( path: impl AsRef<Path>, device: &B::Device, ) -> Result<HashMap<String, Tensor<B, 2>>>
Loads weights from a .safetensors file and returns them as a vector of tensors.
Sourcepub fn load_bin<B: Backend>(
path: impl AsRef<Path>,
device: &B::Device,
expected_shape: [usize; 2],
) -> Result<Tensor<B, 2>>
pub fn load_bin<B: Backend>( path: impl AsRef<Path>, device: &B::Device, expected_shape: [usize; 2], ) -> Result<Tensor<B, 2>>
Loads weights from a PyTorch .bin file.
Standard PyTorch files are zip archives containing pickle formats.
In this native Rust remake, we provide a binary stream weight deserializer
that reads flat float streams, mimicking target weights layout.
Auto Trait Implementations§
impl Freeze for WeightLoader
impl RefUnwindSafe for WeightLoader
impl Send for WeightLoader
impl Sync for WeightLoader
impl Unpin for WeightLoader
impl UnsafeUnpin for WeightLoader
impl UnwindSafe for WeightLoader
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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