(weight_for_adapter, module_name)
| 239 | from peft.tuners.tuners_utils import BaseTunerLayer |
| 240 | |
| 241 | def get_module_weight(weight_for_adapter, module_name): |
| 242 | if not isinstance(weight_for_adapter, dict): |
| 243 | # If weight_for_adapter is a single number, always return it. |
| 244 | return weight_for_adapter |
| 245 | |
| 246 | for layer_name, weight_ in weight_for_adapter.items(): |
| 247 | if layer_name in module_name: |
| 248 | return weight_ |
| 249 | |
| 250 | parts = module_name.split(".") |
| 251 | # e.g. key = "down_blocks.1.attentions.0" |
| 252 | key = f"{parts[0]}.{parts[1]}.attentions.{parts[3]}" |
| 253 | block_weight = weight_for_adapter.get(key, 1.0) |
| 254 | |
| 255 | return block_weight |
| 256 | |
| 257 | # iterate over each adapter, make it active and set the corresponding scaling weight |
| 258 | for adapter_name, weight in zip(adapter_names, weights): |
no outgoing calls
no test coverage detected