Skip to main content

LittleBitLinear

Struct LittleBitLinear 

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

Sub-1-bit factorized linear layer matching upstream quantization.modules.LittleBitLinear.

Implementations§

Source§

impl LittleBitLinear

Source

pub fn from_dense_weight( weight: &Tensor, bias: Option<&Tensor>, config: &LittleBitConfig, ratio_factor: f64, train_mode: TrainMode, seed: u64, ) -> Result<Self>

Decompose a dense weight (out_features, in_features) and optional bias (out_features,) into a LittleBitLinear module via low-rank SVD (and Joint-ITQ when configured).

§Errors

Returns an error on invalid config, non-2D weight, shape mismatch, or SVD failure.

Source

pub fn empty( shape: LayerShape, config: &LittleBitConfig, ratio_factor: f64, train_mode: TrainMode, dtype: DType, device: &Device, ) -> Result<Self>

Allocate zero-initialized factor tensors without performing SVD (for checkpoint loading).

§Errors

Returns an error if config validation or tensor allocation fails.

Source

pub fn from_state_dict( prefix: &str, tensors: &HashMap<String, Tensor>, shape: LayerShape, config: &LittleBitConfig, ratio_factor: f64, weight_state: WeightState, dtype: DType, device: &Device, ) -> Result<Self>

Reconstruct a LittleBitLinear layer from an unpacked state dictionary.

§Errors

Returns LittleBitError::MissingTensor or shape mismatch errors if any factor tensor is absent or malformed.

Source

pub fn forward(&self, x: &Tensor) -> Result<Tensor>

Forward pass accepting any leading shape [..., in_features] and returning [..., out_features].

§Errors

Returns an error if input trailing dimension differs from in_features or tensor ops fail.

Source

pub fn pack_state_dict(&self, prefix: &str) -> Result<HashMap<String, Tensor>>

Binarize and pack U, V (and U_R, V_R when dual) into upstream safetensors keys.

§Errors

Returns an error if binarization or packing fails.

Source

pub fn to_packed(&self) -> Result<PackedLittleBitLinear>

Convert this layer into a memory-compact 1-bit PackedLittleBitLinear runtime module.

§Errors

Returns an error if binarization or host packing fails.

Source

pub fn in_features(&self) -> usize

Input feature dimension.

Source

pub fn out_features(&self) -> usize

Output feature dimension.

Source

pub fn budget(&self) -> &BitBudget

Resolved bit budget and latent rank geometry.

Source

pub fn split_dim(&self) -> usize

Selected latent rank split_dim.

Source

pub fn is_binarized(&self) -> bool

Whether weights are already pre-binarized (_binarized inference mode).

Source

pub fn binarize_in_place(&mut self) -> Result<()>

Switch module to pre-binarized inference mode, converting U and V in place to {-1, +1}.

§Errors

Returns an error if binarization fails.

Source

pub fn trainable_vars(&self) -> Vec<Var>

Collect all trainable [Var] parameters inside this layer.

Source

pub fn freeze(&mut self)

Freeze all trainable parameters in this layer.

Source

pub fn warm_start_from_binarized(&mut self, latent_mag: f64) -> Result<()>

Promote a finished/pre-binarized layer back into trainable latent QAT factors by scaling binary signs U/V (and residual U_R/V_R) by latent_mag (--warm_mag), promoting scales and bias to trainable Vars, and disabling binarized mode.

Matches littlebit-bench/patches/volta-fp16.patch::warm_start.

§Errors

Returns LittleBitError::InvalidConfig when latent_mag is not finite and positive, or Candle tensor/variable errors if scaling or allocation fails.

Source

pub fn param_count(&self) -> usize

Total scalar parameter elements stored in this layer.

Source

pub fn main_branch(&self) -> &FactorBranch

Borrow the main latent branch.

Source

pub fn residual_branch(&self) -> Option<&FactorBranch>

Borrow the optional residual latent branch.

Source

pub fn bias(&self) -> Option<&Param>

Borrow the optional bias parameter.

Source

pub fn extra_repr(&self) -> String

Format module summary string matching upstream LittleBitLinear.extra_repr().

Trait Implementations§

Source§

impl Clone for LittleBitLinear

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LittleBitLinear

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LittleBitLinear

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

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

§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

impl<T> ToCompactString for T
where T: Display,

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V