|
29 | 29 | import os |
30 | 30 |
|
31 | 31 | import torch |
| 32 | +import torch.nn.functional as F |
32 | 33 | from safetensors.torch import save_file |
33 | 34 |
|
34 | 35 | from .diffusers_converter import to_diffusers |
@@ -120,8 +121,14 @@ def compose_lora( |
120 | 121 | .replace(".add_q_proj.", ".add_v_proj.") |
121 | 122 | ] |
122 | 123 |
|
123 | | - assert q_a.shape[0] == k_a.shape[0] == v_a.shape[0] |
124 | | - assert q_b.shape[1] == k_b.shape[1] == v_b.shape[1] |
| 124 | + # Add paddings if their ranks are different |
| 125 | + max_rank = max(q_a.shape[0], k_a.shape[0], v_a.shape[0]) |
| 126 | + q_a = F.pad(q_a, (0, 0, 0, max_rank - q_a.shape[0])) |
| 127 | + k_a = F.pad(k_a, (0, 0, 0, max_rank - k_a.shape[0])) |
| 128 | + v_a = F.pad(v_a, (0, 0, 0, max_rank - v_a.shape[0])) |
| 129 | + q_b = F.pad(q_b, (0, max_rank - q_b.shape[1])) |
| 130 | + k_b = F.pad(k_b, (0, max_rank - k_b.shape[1])) |
| 131 | + v_b = F.pad(v_b, (0, max_rank - v_b.shape[1])) |
125 | 132 |
|
126 | 133 | if torch.isclose(q_a, k_a).all() and torch.isclose(q_a, v_a).all(): |
127 | 134 | lora_a = q_a |
|
0 commit comments