merge_utils
mindnlp.peft.utils.merge_utils
¶
merge utils
mindnlp.peft.utils.merge_utils.calculate_majority_sign_mask(tensor, method='total')
¶
Get the mask of the majority sign across the task tensors. Task tensors are stacked on dimension 0.
PARAMETER | DESCRIPTION |
---|---|
tensor |
The tensor to get the mask from.
TYPE:
|
method |
The method to use to get the mask. Should be one of ["total", "frequency"].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
mindnlp.peft.utils.merge_utils.dare_linear(task_tensors, weights, density)
¶
Merge the task tensors using dare linear
.
PARAMETER | DESCRIPTION |
---|---|
task_tensors(`List[mindspore.Tensor]`) |
The task tensors to merge.
|
weights |
The weights of the task tensors.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
mindnlp.peft.utils.merge_utils.dare_ties(task_tensors, weights, density, majority_sign_method='total')
¶
Merge the task tensors using dare ties
.
PARAMETER | DESCRIPTION |
---|---|
task_tensors(`List[mindspore.Tensor]`) |
The task tensors to merge.
|
weights |
The weights of the task tensors.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
majority_sign_method |
The method to use to get the majority sign mask. Should be one of ["total", "frequency"].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
mindnlp.peft.utils.merge_utils.disjoint_merge(task_tensors, majority_sign_mask)
¶
Merge the task tensors using disjoint merge.
PARAMETER | DESCRIPTION |
---|---|
task_tensors |
The task tensors to merge.
TYPE:
|
majority_sign_mask |
The mask of the majority sign across the task tensors.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
mindnlp.peft.utils.merge_utils.magnitude_based_pruning(tensor, density)
¶
Prune the smallest values of the task tensors and retain the top-k values based on the specified fraction
density
.
PARAMETER | DESCRIPTION |
---|---|
tensor |
The tensor to prune.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
mindnlp.peft.utils.merge_utils.magnitude_prune(task_tensors, weights, density)
¶
Merge the task tensors using task arithmetic
.
PARAMETER | DESCRIPTION |
---|---|
task_tensors(`List[mindspore.Tensor]`) |
The task tensors to merge.
|
weights |
The weights of the task tensors.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
mindnlp.peft.utils.merge_utils.prune(tensor, density, method, rescale=False)
¶
Prune the values of task tensors based on the method
.
PARAMETER | DESCRIPTION |
---|---|
tensor |
The tensor to prune.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
method |
The method to use to prune. Should be one of ["magnitude", "random"].
TYPE:
|
rescale |
Whether to rescale the result to preserve the expected value of the original tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
mindnlp.peft.utils.merge_utils.random_pruning(tensor, density, rescale)
¶
Prune random values based on the specified fraction density
.
PARAMETER | DESCRIPTION |
---|---|
tensor |
The tensor to prune.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
rescale |
Whether to rescale the result to preserve the expected value of the original tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
mindnlp.peft.utils.merge_utils.reshape_weight_task_tensors(task_tensors, weights)
¶
Reshapes weights
to match the shape of task_tensors
by unsqeezing in the remaining dimenions.
PARAMETER | DESCRIPTION |
---|---|
task_tensors |
The tensors that will be used to reshape
TYPE:
|
weights |
The tensor to be reshaped.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/peft/utils/merge_utils.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
mindnlp.peft.utils.merge_utils.task_arithmetic(task_tensors, weights)
¶
Merge the task tensors using task arithmetic
.
PARAMETER | DESCRIPTION |
---|---|
task_tensors(`List[mindspore.Tensor]`) |
The task tensors to merge.
|
weights |
The weights of the task tensors.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
mindnlp.peft.utils.merge_utils.ties(task_tensors, weights, density, majority_sign_method='total')
¶
Merge the task tensors using ties
.
PARAMETER | DESCRIPTION |
---|---|
task_tensors(`List[mindspore.Tensor]`) |
The task tensors to merge.
|
weights |
The weights of the task tensors.
TYPE:
|
density |
The fraction of values to preserve. Should be in [0,1].
TYPE:
|
majority_sign_method |
The method to use to get the majority sign mask. Should be one of ["total", "frequency"].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindnlp/peft/utils/merge_utils.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|