diff --git a/_images/LCM-LoRA_1.png b/_images/LCM-LoRA_1.png
new file mode 100644
index 00000000..bbd95b31
Binary files /dev/null and b/_images/LCM-LoRA_1.png differ
diff --git a/_images/LCM-LoRA_10.png b/_images/LCM-LoRA_10.png
new file mode 100644
index 00000000..3b977323
Binary files /dev/null and b/_images/LCM-LoRA_10.png differ
diff --git a/_images/LCM-LoRA_2.png b/_images/LCM-LoRA_2.png
new file mode 100644
index 00000000..03906bed
Binary files /dev/null and b/_images/LCM-LoRA_2.png differ
diff --git a/_images/LCM-LoRA_3.png b/_images/LCM-LoRA_3.png
new file mode 100644
index 00000000..4f45aee2
Binary files /dev/null and b/_images/LCM-LoRA_3.png differ
diff --git a/_images/LCM-LoRA_4.png b/_images/LCM-LoRA_4.png
new file mode 100644
index 00000000..4cd4a381
Binary files /dev/null and b/_images/LCM-LoRA_4.png differ
diff --git a/_images/LCM-LoRA_5.png b/_images/LCM-LoRA_5.png
new file mode 100644
index 00000000..b7950b4f
Binary files /dev/null and b/_images/LCM-LoRA_5.png differ
diff --git a/_images/LCM-LoRA_6.png b/_images/LCM-LoRA_6.png
new file mode 100644
index 00000000..4be1afb5
Binary files /dev/null and b/_images/LCM-LoRA_6.png differ
diff --git a/_images/LCM-LoRA_7.png b/_images/LCM-LoRA_7.png
new file mode 100644
index 00000000..ee98e947
Binary files /dev/null and b/_images/LCM-LoRA_7.png differ
diff --git a/_images/LCM-LoRA_8.png b/_images/LCM-LoRA_8.png
new file mode 100644
index 00000000..138bb6fb
Binary files /dev/null and b/_images/LCM-LoRA_8.png differ
diff --git a/_images/LCM-LoRA_9.png b/_images/LCM-LoRA_9.png
new file mode 100644
index 00000000..ea37f4c2
Binary files /dev/null and b/_images/LCM-LoRA_9.png differ
diff --git a/_sources/docs/review/LCM-LoRA.md b/_sources/docs/review/LCM-LoRA.md
index fd125e73..ef1f6dff 100644
--- a/_sources/docs/review/LCM-LoRA.md
+++ b/_sources/docs/review/LCM-LoRA.md
@@ -46,8 +46,12 @@ Distillation 방법론 또한 Distillation 시 Computation적으로 Overhead가
CMs은 sampling step을 획기적으로 줄이면서도 Quality를 유지할 수 있는 방법론이다.
+:::{figure-md}
+Consistency Models
+:::
+
CMs의 핵심은 PF-ODE의 궤적의 points가 solution에 mapping 되는 function $(f: (x_t,t) \mapsto x_\epsilon)$을 추정하는 것이다.
쉽게 말해 어떤 step의 noise image 던지 $x_0$ (정확히는 $x_\epsilon$)의 결과가 나오는 function을 추정한다. 또한 각 timestep에 관한function의 결과값은 self-consistency를 만족해야 한다.
@@ -79,8 +83,12 @@ $\Phi$는 numerical PF-ODE를 의미한다. (보통 DDIM을 사용하는 것 같
### Latent Consistency Models
+:::{figure-md}
+Latent Diffusion Models
+:::
+
LCMs은 CMs에 condition을 추가해주고 $F_\theta(x,t)$를 $\epsilon-Prediction$의 수식으로 치환한다. ($\mu$나 $v$ prediction을 사용해도 됨.) 추가로 LDMs 기반이기 때문에 latent $z$에 대한 수식으로 변경해준다.
$$f_\theta(z,c,t)=c_{skip}(t)z+c_{out}(t)\bigg(\frac{z-\sigma(t)\hat{\epsilon}_\theta(z,c,t)}{\alpha(t)}\bigg). (\epsilon-Prediction)$$
@@ -115,11 +123,19 @@ $$\underset{\Phi}{max}\sum_{(x,y)\in Z}\sum^{|y|}_{t=1}\log{(P_{\Phi_0+\Delta\Ph
즉 기존의 잘 학습된 weight는 그대로 두고 low rank로 decomposition 된 weight만 optimization 하는 방법론을 Low Rank Adaptation(LoRA)라고 한다.
+:::{figure-md}
+Low Rank Adaptation
+:::
+
위의 그림과 같이 원본 모델 weight는 freeze, LoRA는 rank를 r로 낮추어 finetuning한다. 이때 LoRA의 A는 random Gauissian으로, B는 zero로 weight initializing 한다.
-
+:::{figure-md}
+
+
+Low Rank Adaptation matrix
+:::
위 그림처럼 기존에는 d x d의 매우 큰 weight를 finetuning 해야 했지만, LoRA는 r만큼 압축된 weight matrix만 finetuning 하면 되기 때문에 훨씬 효율적이고 때에 따라 Fully fine-tuning 하는 방법들보다 더 좋은 성능을 보여주기도 한다. (그림은 [이곳](https://ffighting.net/deep-learning-paper-review/language-model/lora/)을 참고하였습니다.)
@@ -129,8 +145,12 @@ $$\underset{\Phi}{max}\sum_{(x,y)\in Z}\sum^{|y|}_{t=1}\log{(P_{\Phi_0+\Delta\Ph
task Arithmetic은 특정 task에서 학습된 Model의 가중치를 task vector라 보고 각 task vector를 조합하여 새로운 task vector를 생성하는 방법론이다.
+:::{figure-md}
+Task Arithmetic
+:::
+
pre-trained parameter를 $\theta_{pre}$, fine-tuning parameter를 $\theta_{ft}$라고 할때 task vector $\tau$는 $\theta_{ft}-\theta_{pre}$로 정의할 수 있다.
이를 다양하게 조합하고 특히 d)처럼 task 간 analogy를 고려하여 연산하는 경우 새로운 task에 대한 성능을 높일 수 있다.
@@ -140,8 +160,12 @@ pre-trained parameter를 $\theta_{pre}$, fine-tuning parameter를 $\theta_{ft}$
LCMs의 Latent Consistency Distillation에 대한 pseudo code는 다음과 같다:
+:::{figure-md}
+Latent Consistency Distillation
+:::
+
논문의 저자는 LCMs의 Distillation은 LDMs에 관한 일종의 fine-tuning으로 보고 LoRA를 적용하는 방법을 제안하였다.
pre-trained 된 weight matrix $W_0$에 대하여 기울기 업데이트는 $W_0+\Delta W=W_0+BA, W_0\in \mathbb{R}^{d\times k}, B\in \mathbb{R}^{d\times r}, A\in \mathbb{R}^{r\times k}$ 로 표현할 수 있으며 rank $r \leq \min{(d,k)}$ 로 작은 값을 갖는다. $W_0$의 weight는 고정되며 input $x$ 에 대한 forward pass는 다음과 같다:
@@ -149,18 +173,30 @@ $$h=W_0x+\Delta Wx=W_0x+BAx. \tag{1}$$
위와같이 LCMs에 LoRA를 적용할 경우 학습 parameter를 크게 줄일 수 있어 효율적이다.
+:::{figure-md}
+compare trainable parameter
+:::
+
따라서 LCM-loRA는 기존 LCMs 보다 더 큰 모델의 훈련과 실사용이 가능하다. LCMs의 경우 SD-V1.5나 SD-V2.1의 base Stable Diffusion을 사용했지만, LCM-LoRA는 SDXL과 SSD-1B(Segmind)을 확장하여 사용하였다. large Model에서도 LCD을 적용했을 때 잘 적응하는 모습을 볼 수 있었다.
-
+:::{figure-md}
+
+
+1024 x 1024 resolution image results with CFG scale w=7.5
+:::
## 3.2 LCM-LoRA as Universal Acceleration Module
LCM-LoRA는 sampling step을 줄이는 distillation에 LoRA를 적용하였다. LoRA는 이외에도 custionized datasets에 대해 fine-tuning할 때 주로 쓰이는데 이같은 style에 대한 LoRA와 LCM-LoRA가 추가 학습없이 바로 합쳐져 사용할 수 있음을 발견했다. 저자는 이 발견이 task arithmetic에 대한 관점으로 해석할 수 있다고 주장하였다.
+:::{figure-md}
+Style LoRA with LCM-LoRA
+:::
+
LCM-LoRA의 fine-tuned parameter를 $\tau_{LCM}$이라 할 때, $\tau_{LCM}$은 acceleration vector라 할수 있다. 그리고 custom dataset에서 학습한 LoRA의 fine-tuned parameter를 $\tau'$이라 할 때, $\tau'$은 style vector라 할 수 있다. LCMs를 통해 custom dataset에 대한 image를 생성할 때, 파라미터는 다음과 같이 조합된다:
$$\theta'_{LCM}=\theta_{pre}+\tau'_{LCM} \tag{2}$$
@@ -168,7 +204,11 @@ $$\tau'_{LCM}=\lambda_1\tau'+\lambda_2\tau_{LCM} \tag{3}$$
파라미터는 단순한 선형 결합을 통해 이루어지며 $\lambda_1$과 $\lambda_2$는 하이퍼파라미터다. 추가적인 학습없이 다음과 같은 결과를 얻을 수 있었다:
-
+:::{figure-md}
+
+
+fine-tuning with LCM-LoRA
+:::
# 4. Conclusion
diff --git a/docs/experiments/js_exp.html b/docs/experiments/js_exp.html
index f01e1e58..b488642b 100644
--- a/docs/experiments/js_exp.html
+++ b/docs/experiments/js_exp.html
@@ -542,7 +542,7 @@
DreamBooth 를 실험하면서 대표적으로 instance prompt, guidance scale, negative prompt, 그리고 마지막으로 prior preservation loss 를 반영하는 정도를 조절하는 prior_loss_weight 를 바꿔가면서 학습해보았습니다. 사전학습된 text-to-image 모델로 처음에는 hakurei/waifu-diffusion 모델을 시도해봤지만 결과가 만족스럽지 못해 runwayml/stable-diffusion-v1-5 모델로 fine-tuning 작업을 진행했습니다.
Inference step 을 늘려가면서 추론된 인물 이미지의 퀄리티가 상승하는 부분도 확인할 수 있었습니다. 또한, guidance scale 에 대한 실험도 진행했는데 guidance scale 이 작을수록 prompt 와 무관한 random 한 이미지들을 생성하게 됩니다. 최종적으로 num_inference steps 와 guidance scale 의 값은 각각 100 과 7.5 로 설정하였습니다.
마지막으로 하단의 좌측과 우측 사진은 각각 “A photo of sks girl” 그리고 “A photo of a girl in the style of sks” 이라는 prompt 로 DreamBooth 모델을 각각 학습한 후, 나비를 생성하라는 동일한 prompt 로 추론해본 결과입니다. sks 가 수식하는 명사가 girl 이 아닌 style 이도록 prompt 를 수정함으로써, butterfly 사진을 생성할때 조금이나마 더 프리드로우 웹툰의 그림체를 반영할 수 있었던 부분도 확인할 수 있었습니다.
3D Gaussian은 포인트(mean) μ를 중심으로 하고, 3D 공분산 행렬 Σ로 정의한다. 렌더링을 위해 3D Gaussian을 2D로 project해야 하며, 이는 viewing transformation W에 따라 카메라 좌표계에서의 공분산 행렬 Σ’로 나타낼 수 있다. 최적화를 위해, Σ는 positive semi-definite 행렬이어야 하며, 이 때문에 최적화가 어렵다고 한다.
Fig. 569 scaler를 0으로 하면 domain adapter에 의한 효과를 제거한 것과 같다. 위의 그림은 모델이 생성한 animation clip의 첫번째 프레임이다.#
+
Fig. 579 scaler를 0으로 하면 domain adapter에 의한 효과를 제거한 것과 같다. 위의 그림은 모델이 생성한 animation clip의 첫번째 프레임이다.#
domain adapter에 의한 효과를 제거했을때 전체적인 이미지 퀄리티가 높아 보이는데, 이는 domain adapter가 video dataset의 특성이라고 할 수 있는 watermark나 모션 블러 등을 학습했기 때문이다. 즉, domain adapter가 전체 학습과정에 도움이 되었음을 보여준다.
visual content와 motion prior의 개별 학습을 통해 AnimateDiff가 existing content를 조절할 수 있도록 했다. 이 특성을 확인하기 위해 AnimateDiff를 ControlNet과 결합하여 영상 생성시 depth를 통해 조절할 수 있도록 했다.