pub struct IncrementalModelLoader<S: WeightSource> { /* private fields */ }Expand description
Wraps a WeightSource and provides layer-by-layer streaming iteration.
On construction, all tensor names are scanned to extract unique "layers.N."
prefixes. The load_all_streaming method then
iterates over these prefixes in sorted order, loading one layer at a time
and invoking a user-supplied callback. Miscellaneous tensors (not matching
the layers.N. pattern) are presented last, grouped under "_misc.".
Implementations§
Source§impl<S: WeightSource> IncrementalModelLoader<S>
impl<S: WeightSource> IncrementalModelLoader<S>
Sourcepub fn new(source: S) -> Self
pub fn new(source: S) -> Self
Construct a new loader from a weight source.
Tensor names are scanned once to build the list of unique layer prefixes.
Sourcepub fn load_layer(
&mut self,
prefix: &str,
) -> ModelResult<HashMap<String, Vec<f32>>>
pub fn load_layer( &mut self, prefix: &str, ) -> ModelResult<HashMap<String, Vec<f32>>>
Load all tensors whose names start with prefix.
The special prefix "_misc." loads all tensors that do not match
the "layers.N." pattern.
Returns a HashMap<tensor_name, Vec<f32>> for the group.
Sourcepub fn load_all_streaming<F>(&mut self, callback: F) -> ModelResult<()>
pub fn load_all_streaming<F>(&mut self, callback: F) -> ModelResult<()>
Stream through all layers in order, invoking callback once per layer prefix.
The callback receives:
prefix: the layer prefix string (e.g."layers.0."or"_misc.")tensors: aHashMap<tensor_name, Vec<f32>>for that layer
If callback returns an Err, iteration stops immediately and the error
is propagated.
Sourcepub fn layer_prefixes(&self) -> &[String]
pub fn layer_prefixes(&self) -> &[String]
Return the list of unique layer prefixes discovered in the weight source.
The list is sorted lexicographically; the "_misc." bucket (if present)
always appears last.
Sourcepub fn into_source(self) -> S
pub fn into_source(self) -> S
Consume the loader and return ownership of the underlying weight source.
Auto Trait Implementations§
impl<S> Freeze for IncrementalModelLoader<S>where
S: Freeze,
impl<S> RefUnwindSafe for IncrementalModelLoader<S>where
S: RefUnwindSafe,
impl<S> Send for IncrementalModelLoader<S>
impl<S> Sync for IncrementalModelLoader<S>
impl<S> Unpin for IncrementalModelLoader<S>where
S: Unpin,
impl<S> UnsafeUnpin for IncrementalModelLoader<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for IncrementalModelLoader<S>where
S: UnwindSafe,
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
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>
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>
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