PEFT provides several internal utilities for merging LoRA adapters with the TIES and DARE methods.
( tensor: Tensor density: float method: typing.Literal['magnitude', 'random'] rescale: bool = False ) → torch.Tensor
Parameters
torch.Tensor
) —The tensor to prune. float
) —The fraction of values to preserve. Should be in [0,1]. str
) —The method to use to prune. Should be one of [“magnitude”, “random”]. bool
) —Whether to rescale the result to preserve the expected value of the original tensor. Returns
torch.Tensor
The pruned tensor.
Prune the values of task tensors based on the method
.
( tensor: Tensor method: typing.Literal['total', 'frequency'] = 'total' ) → torch.Tensor
Get the mask of the majority sign across the task tensors. Task tensors are stacked on dimension 0.
( task_tensors: Tensor majority_sign_mask: Tensor ) → torch.Tensor
Merge the task tensors using disjoint merge.
( task_tensors: typing.List[torch.Tensor] weights: Tensor ) → torch.Tensor
Merge the task tensors using task arithmetic
.
( task_tensors: typing.List[torch.Tensor] weights: Tensor density: float majority_sign_method: typing.Literal['total', 'frequency'] = 'total' ) → torch.Tensor
Parameters
List[torch.Tensor]
) —The task tensors to merge. torch.Tensor
) —The weights of the task tensors. float
) —The fraction of values to preserve. Should be in [0,1]. str
) —
The method to use to get the majority sign mask. Should be one of [“total”, “frequency”]. Returns
torch.Tensor
The merged tensor.
Merge the task tensors using ties
.
( task_tensors: typing.List[torch.Tensor] weights: Tensor density: float ) → torch.Tensor
Merge the task tensors using dare linear
.
( task_tensors: typing.List[torch.Tensor] weights: Tensor density: float majority_sign_method: typing.Literal['total', 'frequency'] = 'total' ) → torch.Tensor
Parameters
List[torch.Tensor]
) —The task tensors to merge. torch.Tensor
) —The weights of the task tensors. float
) —The fraction of values to preserve. Should be in [0,1]. str
) —
The method to use to get the majority sign mask. Should be one of [“total”, “frequency”]. Returns
torch.Tensor
The merged tensor.
Merge the task tensors using dare ties
.