pub struct ModuleReshaper<B: Backend, M: Module<B>> { /* private fields */ }Expand description
A ParamReshaper backed by a cloned template module.
Construction clones the supplied module once and counts its float leaves.
Each unflatten call clones that template and
maps the flat buffer into the clone’s leaves; each
flatten call visits a module’s leaves and
concatenates them.
§Single-source width convention
A reshaper is the genome-width source of truth. Build one reshaper for
the width, then hand reshaper.clone() (this type is Clone) to the
fitness adapter — the strategy and its evaluator then agree on
num_params by construction. Prefer this over
building two ModuleReshaper::new(template.clone()) instances whose widths
match only by convention: a silent divergence surfaces late as the
documented width-mismatch panic in
unflatten / evaluate_batch. Where a
WeightOnly wrapper already
owns a reshaper, clone its via strategy.reshaper().clone().
§Example
See the module_eval_fn tests for a runnable
end-to-end example of flatten/unflatten in the weight-only pipeline.
Implementations§
Source§impl<B: Backend, M: Module<B>> ModuleReshaper<B, M>
impl<B: Backend, M: Module<B>> ModuleReshaper<B, M>
Sourcepub fn new(template: M) -> Self
pub fn new(template: M) -> Self
Build a reshaper from a template module.
The template is cloned and retained; its float-leaf count is computed
once and cached as num_params.
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Number of float parameters (flat-vector length).
Inherent mirror of ParamReshaper::num_params so callers can read the
width without the M: Sync bound the trait requires.
Trait Implementations§
Source§impl<B, M> ParamReshaper<B> for ModuleReshaper<B, M>
impl<B, M> ParamReshaper<B> for ModuleReshaper<B, M>
Auto Trait Implementations§
impl<B, M> Freeze for ModuleReshaper<B, M>where
M: Freeze,
impl<B, M> RefUnwindSafe for ModuleReshaper<B, M>where
M: RefUnwindSafe,
impl<B, M> Send for ModuleReshaper<B, M>
impl<B, M> Sync for ModuleReshaper<B, M>where
M: Sync,
impl<B, M> Unpin for ModuleReshaper<B, M>where
M: Unpin,
impl<B, M> UnsafeUnpin for ModuleReshaper<B, M>where
M: UnsafeUnpin,
impl<B, M> UnwindSafe for ModuleReshaper<B, M>where
M: 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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
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>
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