Update README.md
Browse files
README.md
CHANGED
@@ -14,6 +14,11 @@ So, what if we could take an existing LoRA checkpoint with a high rank and reduc
|
|
14 |
- Reduce the memory requirements
|
15 |
- Enable use cases like `torch.compile()` (which require all the LoRAs to be of the same rank to avoid re-compilation)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
## Random projections
|
18 |
|
19 |
Basic idea:
|
@@ -34,6 +39,9 @@ Basic idea:
|
|
34 |
|
35 |
Tried on this LoRA: [https://huggingface.co/glif/how2draw](https://huggingface.co/glif/how2draw). Unless explicitly specified, a rank of 4 was used for all experiments. Here’s a side-by-side comparison of the original and the reduced LoRAs (on the same seed).
|
36 |
|
|
|
|
|
|
|
37 |
```python
|
38 |
from diffusers import DiffusionPipeline
|
39 |
import torch
|
@@ -54,23 +62,35 @@ images = pipe(
|
|
54 |
).images
|
55 |
```
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
### Notes
|
76 |
|
@@ -81,27 +101,27 @@ Code: [https://gist.github.com/sayakpaul/9bae12402eddd53a79ee1f64b659b07b#file-
|
|
81 |
|
82 |
### Results
|
83 |
|
84 |
-
![image.png](
|
85 |
|
86 |
-
![image.png](
|
87 |
|
88 |
-
![image.png](
|
89 |
|
90 |
-
![image.png](
|
91 |
|
92 |
### Randomized SVD
|
93 |
|
94 |
Full SVD can be time-consuming. Truncated SVD is useful very large sparse matrices. We can use randomized SVD for none-to-negligible loss in quality but significantly faster speed.
|
95 |
|
96 |
-
![image.png](
|
97 |
|
98 |
-
![image.png](
|
99 |
|
100 |
-
![image.png](
|
101 |
|
102 |
-
![image.png](
|
103 |
|
104 |
-
Code: [
|
105 |
|
106 |
### Tune the knobs in SVD
|
107 |
|
|
|
14 |
- Reduce the memory requirements
|
15 |
- Enable use cases like `torch.compile()` (which require all the LoRAs to be of the same rank to avoid re-compilation)
|
16 |
|
17 |
+
This project explores two options to reduce the original LoRA checkpoint into an even smaller one:
|
18 |
+
|
19 |
+
* Random projections
|
20 |
+
* SVD
|
21 |
+
|
22 |
## Random projections
|
23 |
|
24 |
Basic idea:
|
|
|
39 |
|
40 |
Tried on this LoRA: [https://huggingface.co/glif/how2draw](https://huggingface.co/glif/how2draw). Unless explicitly specified, a rank of 4 was used for all experiments. Here’s a side-by-side comparison of the original and the reduced LoRAs (on the same seed).
|
41 |
|
42 |
+
<details>
|
43 |
+
<summary>Inference code</summary>
|
44 |
+
|
45 |
```python
|
46 |
from diffusers import DiffusionPipeline
|
47 |
import torch
|
|
|
62 |
).images
|
63 |
```
|
64 |
|
65 |
+
</details>
|
66 |
+
|
67 |
+
<table>
|
68 |
+
<tbody>
|
69 |
+
<tr>
|
70 |
+
<td align="center"><img src="https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/collage_0.png" alt="Image 1"></td>
|
71 |
+
<td align="center">Yorkshire Terrier with smile, How2Draw</td>
|
72 |
+
</tr>
|
73 |
+
<tr>
|
74 |
+
<td align="center"><img src="https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/collage_1.png" alt="Image 2"></td>
|
75 |
+
<td align="center">a dolphin, How2Draw</td>
|
76 |
+
</tr>
|
77 |
+
<tr>
|
78 |
+
<td align="center"><img src="https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/collage_2.png" alt="Image 3"></td>
|
79 |
+
<td align="center">an owl, How3Draw</td>
|
80 |
+
</tr>
|
81 |
+
<tr>
|
82 |
+
<td align="center"><img src="https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/collage_3.png" alt="Image 4"></td>
|
83 |
+
<td align="center">
|
84 |
+
A silhouette of a girl performing a ballet pose, with elegant lines to suggest grace and movement.
|
85 |
+
The background can include simple outlines of ballet shoes and a music note.
|
86 |
+
The image should convey elegance and poise in a minimalistic style, How2Draw
|
87 |
+
</td>
|
88 |
+
</tr>
|
89 |
+
</tbody>
|
90 |
+
</table>
|
91 |
+
|
92 |
+
|
93 |
+
Code: [`low_rank_lora.py`](https://huggingface.co/sayakpaul/lower-rank-flux-lora/blob/main/low_rank_lora.py)
|
94 |
|
95 |
### Notes
|
96 |
|
|
|
101 |
|
102 |
### Results
|
103 |
|
104 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_svd_collage_0.png)
|
105 |
|
106 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_svd_collage_1.png)
|
107 |
|
108 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_svd_collage_2.png)
|
109 |
|
110 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_svd_collage_3.png)
|
111 |
|
112 |
### Randomized SVD
|
113 |
|
114 |
Full SVD can be time-consuming. Truncated SVD is useful very large sparse matrices. We can use randomized SVD for none-to-negligible loss in quality but significantly faster speed.
|
115 |
|
116 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_rand_svd_collage_0.png)
|
117 |
|
118 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_rand_svd_collage_1.png)
|
119 |
|
120 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_rand_svd_collage_2.png)
|
121 |
|
122 |
+
![image.png](https://huggingface.co/sayakpaul/lower-rank-flux-lora/resolve/main/images/How2Draw-V2_000002800_rand_svd_collage_3.png)
|
123 |
|
124 |
+
Code: [`svd_low_rank_lora.py`](https://huggingface.co/sayakpaul/lower-rank-flux-lora/blob/main/svd_low_rank_lora.py)
|
125 |
|
126 |
### Tune the knobs in SVD
|
127 |
|