MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / _find_source_key_from_diff

Function _find_source_key_from_diff

tools/extract/lora_merger.py:350–380  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

348
349 return merged_weights
350
351
352def _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
374def _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

Callers 1

merge_lora_weightsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected