Updates paths inside attentions to the new naming scheme (local renaming)
(old_list, n_shave_prefix_segments=0)
| 591 | |
| 592 | |
| 593 | def renew_vae_attention_paths(old_list, n_shave_prefix_segments=0): |
| 594 | """ |
| 595 | Updates paths inside attentions to the new naming scheme (local renaming) |
| 596 | """ |
| 597 | mapping = [] |
| 598 | for old_item in old_list: |
| 599 | new_item = old_item |
| 600 | |
| 601 | new_item = new_item.replace("norm.weight", "group_norm.weight") |
| 602 | new_item = new_item.replace("norm.bias", "group_norm.bias") |
| 603 | |
| 604 | new_item = new_item.replace("q.weight", "to_q.weight") |
| 605 | new_item = new_item.replace("q.bias", "to_q.bias") |
| 606 | |
| 607 | new_item = new_item.replace("k.weight", "to_k.weight") |
| 608 | new_item = new_item.replace("k.bias", "to_k.bias") |
| 609 | |
| 610 | new_item = new_item.replace("v.weight", "to_v.weight") |
| 611 | new_item = new_item.replace("v.bias", "to_v.bias") |
| 612 | |
| 613 | new_item = new_item.replace("proj_out.weight", "to_out.0.weight") |
| 614 | new_item = new_item.replace("proj_out.bias", "to_out.0.bias") |
| 615 | |
| 616 | new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments) |
| 617 | |
| 618 | mapping.append({"old": old_item, "new": new_item}) |
| 619 | |
| 620 | return mapping |
| 621 | |
| 622 | |
| 623 | def convert_ldm_vae_checkpoint(checkpoint, config): |
no test coverage detected