pub struct Weights { /* private fields */ }Expand description
Named weights, such as the parameters of a Flax model with names like
params/Dense_0/kernel (the keys of the parameter tree joined by /).
§Examples
use ruxla_ir::HostArray;
use ruxla_nn::Weights;
let mut w = Weights::default();
w.insert("params/Dense_0/bias", HostArray::from_vec(vec![0.5f32, -1.0], [2]));
let bias = w.array::<f32>("params/Dense_0/bias", &[2]).unwrap();
assert_eq!(bias.to_vec(), [0.5, -1.0]);Implementations§
Source§impl Weights
impl Weights
Sourcepub fn from_safetensors(bytes: &[u8]) -> Result<Self, WeightsError>
pub fn from_safetensors(bytes: &[u8]) -> Result<Self, WeightsError>
Reads a safetensors file (little-endian, as written by
safetensors.numpy.save_file or safetensors.flax.save_file).
§Errors
Returns an error if the data is not valid safetensors or has an element type that ruxla does not have.
Sourcepub fn from_flax_msgpack(bytes: &[u8]) -> Result<Self, WeightsError>
pub fn from_flax_msgpack(bytes: &[u8]) -> Result<Self, WeightsError>
Reads weights serialized by Flax (flax.serialization.to_bytes of a
parameter tree): nested maps whose leaves are arrays.
§Errors
Returns an error if the data is not valid MessagePack, is not a tree of maps and arrays, or has an element type that ruxla does not have.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Weights
impl RefUnwindSafe for Weights
impl Send for Weights
impl Sync for Weights
impl Unpin for Weights
impl UnsafeUnpin for Weights
impl UnwindSafe for Weights
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