pub struct PerLayerQuant {
pub trits: Vec<Trit>,
pub scale: f32,
pub shape: Vec<usize>,
pub name: String,
pub sparsity: f64,
}Expand description
The result of quantizing one weight tensor.
Fields§
§trits: Vec<Trit>Ternary weights in row-major order.
scale: f32Per-layer scale factor α = mean(|W|). Multiply by this to approximate the original magnitudes.
shape: Vec<usize>Shape: [rows, cols] for 2D tensors; arbitrary for higher ranks.
name: StringHuman-readable layer name (e.g. “model.layers.0.self_attn.q_proj.weight”).
sparsity: f64Fraction of trits that are Tend (zero) — 0.0 … 1.0.
Implementations§
Source§impl PerLayerQuant
impl PerLayerQuant
Sourcepub fn quantize(
weights: &[f32],
name: impl Into<String>,
shape: Vec<usize>,
) -> Self
pub fn quantize( weights: &[f32], name: impl Into<String>, shape: Vec<usize>, ) -> Self
Quantize weights (flat, row-major) to balanced ternary.
name — layer identifier for diagnostics.
shape — logical shape of the tensor (product must equal weights.len()).
Sourcepub fn reconstruct(&self) -> Vec<f32>
pub fn reconstruct(&self) -> Vec<f32>
Approximate reconstruction: W_approx = α × W_t (as f32). Useful for measuring quantization error.
Trait Implementations§
Source§impl Clone for PerLayerQuant
impl Clone for PerLayerQuant
Source§fn clone(&self) -> PerLayerQuant
fn clone(&self) -> PerLayerQuant
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PerLayerQuant
impl RefUnwindSafe for PerLayerQuant
impl Send for PerLayerQuant
impl Sync for PerLayerQuant
impl Unpin for PerLayerQuant
impl UnsafeUnpin for PerLayerQuant
impl UnwindSafe for PerLayerQuant
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
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>
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