LoKr
mindnlp.peft.tuners.lokr.config
¶
lokr.
mindnlp.peft.tuners.lokr.config.LoKrConfig
dataclass
¶
Bases: PeftConfig
This is the configuration class to store the configuration of a [LoraModel
].
PARAMETER | DESCRIPTION |
---|---|
r |
lokr attention dimension.
TYPE:
|
target_cells |
The names of the cells to apply Lora to.
TYPE:
|
lora_alpha |
The alpha parameter for Lokr scaling.
TYPE:
|
rank_dropout |
The dropout probability for rank dimension during training.
TYPE:
|
cell_dropout |
The dropout probability for LoKR layers.
TYPE:
|
use_effective_conv2d |
Use parameter effective decomposition for Conv2d with ksize > 1 ("Proposition 3" from FedPara paper).
TYPE:
|
decompose_both |
Perform rank decomposition of left kronecker product matrix.
TYPE:
|
decompose_factor |
Kronecker product decomposition factor.
TYPE:
|
bias |
Bias type for Lora. Can be 'none', 'all' or 'lora_only'
TYPE:
|
cells_to_save |
List of cells apart from LoRA layers to be set as trainable and saved in the final checkpoint.
TYPE:
|
init_weights |
Whether to perform initialization of adapter weights. This defaults to
TYPE:
|
layers_to_transform |
The layer indexes to transform, if this argument is specified, it will apply the LoRA transformations on the layer indexes that are specified in this list. If a single integer is passed, it will apply the LoRA transformations on the layer at this index.
TYPE:
|
layers_pattern |
The layer pattern name, used only if
TYPE:
|
rank_pattern |
The mapping from layer names or regexp expression to ranks which are different from the default rank
specified by
TYPE:
|
alpha_pattern |
The mapping from layer names or regexp expression to alphas which are different from the default alpha
specified by
TYPE:
|
Source code in mindnlp/peft/tuners/lokr/config.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
mindnlp.peft.tuners.lokr.config.LoKrConfig.is_prompt_learning
property
¶
Utility method to check if the configuration is for prompt learning.
mindnlp.peft.tuners.lokr.config.LoKrConfig.__post_init__()
¶
Method to initialize the attributes of the LoKrConfig class after object creation.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the LoKrConfig class.
|
RETURNS | DESCRIPTION |
---|---|
None. This method performs attribute initialization within the class. |
Source code in mindnlp/peft/tuners/lokr/config.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
mindnlp.peft.tuners.lokr.model
¶
Lokr.
mindnlp.peft.tuners.lokr.model.LoKrModel
¶
Bases: BaseTuner
Creates Low-Rank Kronecker Product model from a pretrained model. The original method is partially described in https://arxiv.org/abs/2108.06098 and in https://arxiv.org/abs/2309.14859 Current implementation heavily borrows from https://github.com/KohakuBlueleaf/LyCORIS/blob/eb460098187f752a5d66406d3affade6f0a07ece/lycoris/cells/lokr.py
PARAMETER | DESCRIPTION |
---|---|
model |
The model to which the adapter tuner layers will be attached.
TYPE:
|
peft_config |
The configuration of the LoKr model.
TYPE:
|
adapter_name |
The name of the adapter, defaults to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoKrModel
|
The LoKr model.
TYPE:
|
Example
>>> from diffusers import StableDiffusionPipeline
>>> from peft import LoKrModel, LoKrConfig
>>> config_te = LoKrConfig(
... r=8,
... lora_alpha=32,
... target_cells=["k_proj", "q_proj", "v_proj", "out_proj", "fc1", "fc2"],
... rank_dropout=0.0,
... cell_dropout=0.0,
... init_weights=True,
... )
>>> config_unet = LoKrConfig(
... r=8,
... lora_alpha=32,
... target_cells=[
... "proj_in",
... "proj_out",
... "to_k",
... "to_q",
... "to_v",
... "to_out.0",
... "ff.net.0.proj",
... "ff.net.2",
... ],
... rank_dropout=0.0,
... cell_dropout=0.0,
... init_weights=True,
... use_effective_conv2d=True,
... )
>>> model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
>>> model.text_encoder = LoKrModel(model.text_encoder, config_te, "default")
>>> model.unet = LoKrModel(model.unet, config_unet, "default")
Attributes:
model ([
~nn.Module
])— The model to be adapted.peft_config ([
LoKrConfig
]): The configuration of the LoKr model.
Source code in mindnlp/peft/tuners/lokr/model.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
mindnlp.peft.tuners.lokr.model.LoKrModel.__getattr__(name)
¶
Forward missing attributes to the wrapped cell.
Source code in mindnlp/peft/tuners/lokr/model.py
200 201 202 203 204 205 |
|