(
prefix,
root_module: torch.nn.Module,
target_replace_modules,
target_replace_names=[],
target_exclude_names=[],
)
| 401 | if lora_name not in lora_names: |
| 402 | lora_names.append(lora_name) |
| 403 | continue |
| 404 | |
| 405 | if name: |
| 406 | lora_name = prefix + "." + name |
| 407 | else: |
| 408 | lora_name = prefix |
| 409 | |
| 410 | if f"{self.LORA_PREFIX}_." in lora_name: |
| 411 | lora_name = lora_name.replace( |
| 412 | f"{self.LORA_PREFIX}_.", |
| 413 | f"{self.LORA_PREFIX}.", |
| 414 | ) |
| 415 | |
| 416 | lora_name = lora_name.replace(".", "_") |
| 417 | if lora_name in loras: |
| 418 | continue |
| 419 | |
| 420 | lora = create_single_module(lora_name, module, algo, **configs) |
| 421 | if lora is not None: |
| 422 | loras[lora_name] = lora |
| 423 | lora_names.append(lora_name) |
| 424 | return [loras[lora_name] for lora_name in lora_names], lora_names, loras |
| 425 | |
| 426 | # create module instances |
| 427 | def create_modules( |
| 428 | prefix, |
| 429 | root_module: torch.nn.Module, |
| 430 | target_replace_modules, |
| 431 | target_replace_names=[], |
| 432 | target_exclude_names=[], |
| 433 | ) -> tuple: |
| 434 | logger.info("Create LyCORIS Module") |
| 435 | loras = [] |
| 436 | lora_map = {} |
| 437 | next_config = {} |
| 438 | # Track which targets were matched |
| 439 | matched_modules = set() |
| 440 | matched_names = set() |
| 441 | for name, module in root_module.named_modules(): |
| 442 | if self.is_excluded(name, target_exclude_names): |
| 443 | continue |
| 444 | |
| 445 | module_name = module.__class__.__name__ |
| 446 | if module_name in target_replace_modules and not any( |
| 447 | self.match_fn(t, name) for t in target_replace_names |
| 448 | ): |
| 449 | matched_modules.add(module_name) |
| 450 | if module_name in self.MODULE_ALGO_MAP: |
| 451 | next_config = self.MODULE_ALGO_MAP[module_name] |
| 452 | algo = next_config.get("algo", network_module) |
| 453 | else: |
| 454 | algo = network_module |
| 455 | |
| 456 | lora_lst, _, _lora_map = create_modules_( |
| 457 | f"{prefix}_{name}", |
| 458 | module, |
| 459 | algo, |
| 460 | lora_map, |
nothing calls this directly
no test coverage detected