Find corresponding source weight key for diff key Args: diff_key: Diff key (e.g., "diffusion_model.input_blocks.0.diff") source_weights: Source model weights Returns: Corresponding source key or None
(diff_key: str, source_weights: Dict[str, torch.Tensor])
| 348 | |
| 349 | return merged_weights |
| 350 | |
| 351 | |
| 352 | def _find_source_key(lora_base_key: str, source_weights: dict[str, torch.Tensor]) -> str | None: |
| 353 | """ |
| 354 | Find corresponding source weight key for LoRA base key |
| 355 | |
| 356 | Args: |
| 357 | lora_base_key: LoRA base key (e.g., "diffusion_model.input_blocks.0.0.weight") |
| 358 | source_weights: Source model weights |
| 359 | |
| 360 | Returns: |
| 361 | Corresponding source key or None |
| 362 | """ |
| 363 | candidates = [lora_base_key] |
| 364 | for prefix in ("diffusion_model.", "transformer."): |
| 365 | if lora_base_key.startswith(prefix): |
| 366 | candidates.append(lora_base_key[len(prefix) :]) |
| 367 | for candidate in candidates: |
| 368 | for key in (candidate + ".weight", candidate): |
| 369 | if key in source_weights: |
| 370 | return key |
| 371 | return None |
| 372 | |
| 373 | |
| 374 | def _find_source_key_from_diff(diff_key: str, source_weights: dict[str, torch.Tensor]) -> str | None: |
| 375 | """ |
| 376 | Find corresponding source weight key for diff key |
| 377 | |
| 378 | Args: |
| 379 | diff_key: Diff key (e.g., "diffusion_model.input_blocks.0.diff") |
| 380 | source_weights: Source model weights |
| 381 | |
| 382 | Returns: |
| 383 | Corresponding source key or None |
no outgoing calls
no test coverage detected