pub struct LoraAdapter {
pub a: Param<Tensor<2>>,
pub b: Param<Tensor<2>>,
pub scale: f64,
}Expand description
A LoRA (Low-Rank Adaptation) adapter attached to a frozen weight parameter.
When present on a Param<Tensor<2>>, the parameter materializes its effective value as
base + scale * (a @ b), where base is the frozen (and optionally quantized) weight and
a/b are the trainable low-rank factors. The frozen base is the stored value of the
parameter; the adapter factors are surfaced to the optimizer, autodiff and record systems as
regular parameters with their own ParamIds through the module
visitor/mapper traversal.
Fields§
§a: Param<Tensor<2>>Down-projection factor with shape [d_in, rank] (trainable).
b: Param<Tensor<2>>Up-projection factor with shape [rank, d_out] (trainable).
scale: f64Scaling factor applied to the low-rank product, typically alpha / rank.
Implementations§
Source§impl LoraAdapter
impl LoraAdapter
Sourcepub fn delta(&self) -> Tensor<2>
pub fn delta(&self) -> Tensor<2>
Compute the low-rank delta scale * (a @ b) with shape [d_in, d_out].
a and b are read through Param::val, so the delta always reflects the current
(optimizer-updated) factors and keeps them as autodiff leaves for backpropagation.
Trait Implementations§
Source§impl AutodiffModule for LoraAdapter
impl AutodiffModule for LoraAdapter
Source§impl Clone for LoraAdapter
impl Clone for LoraAdapter
Source§impl Debug for LoraAdapter
impl Debug for LoraAdapter
Source§impl Display for LoraAdapter
impl Display for LoraAdapter
Source§impl Module for LoraAdapter
impl Module for LoraAdapter
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
Source§fn collect_devices(&self, devices: Devices) -> Devices
fn collect_devices(&self, devices: Devices) -> Devices
Source§fn to_device(self, device: &Device) -> Self
fn to_device(self, device: &Device) -> Self
Source§fn fork(self, device: &Device) -> Self
fn fork(self, device: &Device) -> Self
Source§fn devices(&self) -> Devices
fn devices(&self) -> Devices
Source§fn freeze_group(self, group: ParamGroup) -> Self
fn freeze_group(self, group: ParamGroup) -> Self
require_grad to false for every parameter in the given group, leaving the rest
of the module untouched. Read moreSource§fn unfreeze_group(self, group: ParamGroup) -> Self
fn unfreeze_group(self, group: ParamGroup) -> Self
require_grad to true for every parameter in the given group, leaving the rest
of the module untouched. Read moreSource§fn train(self) -> Selfwhere
Self: AutodiffModule,
fn train(self) -> Selfwhere
Self: AutodiffModule,
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§fn quantize_weights_group(
self,
quantizer: &mut Quantizer,
group: ParamGroup,
) -> Self
fn quantize_weights_group( self, quantizer: &mut Quantizer, group: ParamGroup, ) -> Self
Source§fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
Reparameterizer. Read moreSource§fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
Source§fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
Source§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read moreSource§fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
Source§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read moreSource§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read moreSource§fn save_file<P: AsRef<Path>>(self, path: P) -> Result<(), RecordError>where
Self: Sized,
fn save_file<P: AsRef<Path>>(self, path: P) -> Result<(), RecordError>where
Self: Sized,
std only.Source§fn load_file<P: AsRef<Path>>(self, path: P) -> Selfwhere
Self: Sized,
fn load_file<P: AsRef<Path>>(self, path: P) -> Selfwhere
Self: Sized,
std only.Source§fn try_load_file<P: AsRef<Path>>(self, path: P) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_file<P: AsRef<Path>>(self, path: P) -> Result<Self, RecordError>where
Self: Sized,
std only.Source§impl ModuleDisplay for LoraAdapter
impl ModuleDisplay for LoraAdapter
Source§fn format(&self, passed_settings: DisplaySettings) -> String
fn format(&self, passed_settings: DisplaySettings) -> String
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Source§impl ModuleDisplayDefault for LoraAdapter
impl ModuleDisplayDefault for LoraAdapter
Source§impl Reparameterization for LoraAdapter
impl Reparameterization for LoraAdapter
Auto Trait Implementations§
impl !RefUnwindSafe for LoraAdapter
impl !UnwindSafe for LoraAdapter
impl Freeze for LoraAdapter
impl Send for LoraAdapter
impl Sync for LoraAdapter
impl Unpin for LoraAdapter
impl UnsafeUnpin for LoraAdapter
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,
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