Skip to main content

Reader

Struct Reader 

Source
pub struct Reader { /* private fields */ }
Expand description

Reader for loading burnpack containers.

Implementations§

Source§

impl Reader

Source

pub fn from_bytes(bytes: Bytes) -> Result<Self, Error>

Load a pack from an in-memory Bytes buffer.

Loading is lazy: only the header and metadata are parsed here. The buffer is kept as-is (no copy, no share) and is only turned into zero-copy Bytes::view windows when you consume the reader with into_tensors. For large models, prefer from_file, which keeps tensor data file-backed and lazy.

Source

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Load a pack from a file.

Only the header and metadata are read up front; the whole file is wrapped in a single lazy Bytes::from_file source, and each tensor’s data is a Bytes::view window into it, read from disk only when accessed. This integrates with the Burn ecosystem’s file allocation (pinned-memory staging) for fast file-to-GPU transfers.

If path has no extension and does not exist as given, the canonical crate::EXTENSION (.bpk) is appended.

Source

pub fn into_tensors(self) -> Result<Vec<Tensor>, Error>

Consume the reader, returning all tensors in sorted (alphabetical) name order.

Each tensor’s bytes are a zero-copy Bytes::view window into the source — no per-tensor copy. For an in-memory source the buffer is shared once here (a cheap Arc move, never a data copy) to make those views available; for a file source the windows are file-backed and read lazily on access. Consuming self lets us hand the source’s ownership to the views directly, so loading never reads or copies tensor data eagerly.

Source

pub fn metadata(&self) -> &BTreeMap<String, String>

The user-supplied key/value metadata stored alongside the tensors.

For per-tensor info (dtype/shape/param id), use into_tensors — for a file-backed reader that does not read any tensor data until a tensor’s bytes are accessed.

Source

pub fn scalars(&self) -> &BTreeMap<String, Scalar>

The typed scalars stored alongside the tensors.

Empty for files written before scalar support.

Source

pub fn tensor_names(&self) -> Vec<&str>

The names of all tensors in the pack, in sorted (alphabetical) order.

Source

pub fn tensor_data(&self, name: &str) -> Result<Vec<u8>, Error>

Read a single tensor’s raw little-endian bytes by name (always copies).

Returns Error::TensorNotFound if no tensor with that name exists.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.