Model merge
PEFT provides several internal utilities for merging LoRA adapters with the TIES and DARE methods.
peft.utils.merge_utils.prune
< source >( tensor: Tensor density: float method: Literal rescale: bool = False ) → torch.Tensor
Parameters
- tensor (
torch.Tensor
) —The tensor to prune. - density (
float
) —The fraction of values to preserve. Should be in [0,1]. - method (
str
) —The method to use to prune. Should be one of [“magnitude”, “random”]. - rescale (
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
.
peft.utils.merge_utils.calculate_majority_sign_mask
< source >( tensor: Tensor method: Literal = 'total' ) → torch.Tensor
Get the mask of the majority sign across the task tensors. Task tensors are stacked on dimension 0.
peft.utils.merge_utils.disjoint_merge
< source >( task_tensors: Tensor majority_sign_mask: Tensor ) → torch.Tensor
Merge the task tensors using disjoint merge.
peft.utils.merge_utils.task_arithmetic
< source >( task_tensors: List weights: Tensor ) → torch.Tensor
Merge the task tensors using task arithmetic
.
peft.utils.merge_utils.ties
< source >( task_tensors: List weights: Tensor density: float majority_sign_method: Literal = 'total' ) → torch.Tensor
Merge the task tensors using ties
.
peft.utils.merge_utils.dare_linear
< source >( task_tensors: List weights: Tensor density: float ) → torch.Tensor
Merge the task tensors using dare linear
.
peft.utils.merge_utils.dare_ties
< source >( task_tensors: List weights: Tensor density: float majority_sign_method: Literal = 'total' ) → torch.Tensor
Merge the task tensors using dare ties
.