pub struct LittleBitLinear { /* private fields */ }Expand description
Sub-1-bit factorized linear layer matching upstream quantization.modules.LittleBitLinear.
Implementations§
Source§impl LittleBitLinear
impl LittleBitLinear
Sourcepub fn from_dense_weight(
weight: &Tensor,
bias: Option<&Tensor>,
config: &LittleBitConfig,
ratio_factor: f64,
train_mode: TrainMode,
seed: u64,
) -> Result<Self>
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.
Sourcepub fn empty(
shape: LayerShape,
config: &LittleBitConfig,
ratio_factor: f64,
train_mode: TrainMode,
dtype: DType,
device: &Device,
) -> Result<Self>
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.
Sourcepub 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>
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.
Sourcepub fn forward(&self, x: &Tensor) -> Result<Tensor>
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.
Sourcepub fn pack_state_dict(&self, prefix: &str) -> Result<HashMap<String, Tensor>>
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.
Sourcepub fn to_packed(&self) -> Result<PackedLittleBitLinear>
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.
Sourcepub fn in_features(&self) -> usize
pub fn in_features(&self) -> usize
Input feature dimension.
Sourcepub fn out_features(&self) -> usize
pub fn out_features(&self) -> usize
Output feature dimension.
Sourcepub fn is_binarized(&self) -> bool
pub fn is_binarized(&self) -> bool
Whether weights are already pre-binarized (_binarized inference mode).
Sourcepub fn binarize_in_place(&mut self) -> Result<()>
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.
Sourcepub fn trainable_vars(&self) -> Vec<Var>
pub fn trainable_vars(&self) -> Vec<Var>
Collect all trainable [Var] parameters inside this layer.
Sourcepub fn warm_start_from_binarized(&mut self, latent_mag: f64) -> Result<()>
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.
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Total scalar parameter elements stored in this layer.
Sourcepub fn main_branch(&self) -> &FactorBranch
pub fn main_branch(&self) -> &FactorBranch
Borrow the main latent branch.
Sourcepub fn residual_branch(&self) -> Option<&FactorBranch>
pub fn residual_branch(&self) -> Option<&FactorBranch>
Borrow the optional residual latent branch.
Sourcepub fn extra_repr(&self) -> String
pub fn extra_repr(&self) -> String
Format module summary string matching upstream LittleBitLinear.extra_repr().
Trait Implementations§
Source§impl Clone for LittleBitLinear
impl Clone for LittleBitLinear
Source§impl Debug for LittleBitLinear
impl Debug for LittleBitLinear
Auto Trait Implementations§
impl !RefUnwindSafe for LittleBitLinear
impl !UnwindSafe for LittleBitLinear
impl Freeze for LittleBitLinear
impl Send for LittleBitLinear
impl Sync for LittleBitLinear
impl Unpin for LittleBitLinear
impl UnsafeUnpin for LittleBitLinear
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T, U> Imply<T> for U
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§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more