Extract diff-style LoRA weights (direct addition, not matrix multiplication). Args: lora_weights: The LoRA state dictionary Returns: Dictionary mapping model keys to diff information
(self, lora_weights: Dict)
| 305 | return lora_pairs |
| 306 | |
| 307 | def extract_lora_diffs(self, lora_weights: Dict) -> Dict[str, Dict]: |
| 308 | """ |
| 309 | Extract diff-style LoRA weights (direct addition, not matrix multiplication). |
| 310 | |
| 311 | Args: |
| 312 | lora_weights: The LoRA state dictionary |
| 313 | |
| 314 | Returns: |
| 315 | Dictionary mapping model keys to diff information |
| 316 | """ |
| 317 | lora_diffs = {} |
| 318 | |
| 319 | # Define diff patterns: (suffix_to_check, suffix_to_remove, suffix_to_add) |
| 320 | diff_patterns = [ |
| 321 | (".diff", ".diff", ".weight"), |
| 322 | (".diff_b", ".diff_b", ".bias"), |
| 323 | (".diff_m", ".diff_m", ".modulation"), |
| 324 | ] |
| 325 | |
| 326 | for key in lora_weights.keys(): |
| 327 | for check_suffix, remove_suffix, add_suffix in diff_patterns: |
| 328 | if key.endswith(check_suffix): |
| 329 | base_key = key[: -len(remove_suffix)] |
| 330 | model_key = self._get_model_key(key, base_key, remove_suffix, add_suffix) |
| 331 | |
| 332 | if model_key: |
| 333 | lora_diffs[model_key] = { |
| 334 | "diff_key": key, |
| 335 | "type": check_suffix, |
| 336 | } |
| 337 | break |
| 338 | |
| 339 | return lora_diffs |
| 340 | |
| 341 | def apply_lora( |
| 342 | self, |
no test coverage detected