[2026년 여름 세미나] Flow matching과 그것의 응용

2026년 여름을 맞이하여 세미나를 준비한다. flow matching에 대해 다룰려고 한다.

flow matching은 생성모델에 쓰인다.

ordinary differential equation (ODE)를 활용한 생성모델 기법이고 2023년에 발표된 논문 [1] 이 제일 유명하다.

이 세미나는 flow matching을 이해하고 flow matching의 응용까지 보기 위해 준비한 세미나이다.

flow matching의 응용으로 음성분야에서 음성향상에 쓰인 논문 FlowSE [2]가 있다.

응용은 나중에 살펴보도록 하고 flow matching을 이해해보도록 하자.

 

Flow와 vector field

flow matching이라는 말을 들으면 어떤 느낌인가?

flow 맞춤? flow를 알아맞춘다는 것이고 그러면 flow가 뭔지 부터 알아야겠다.

flow를 정의하기전에 vector field라는 것을 알아야 되는데 vector field부터 알아보도록 하자.

Vector field

vector field는 기호로 v라고 쓸것이고 간단히 말해서 vector field는 함수다.

v: \mathbb{R}^d \to \mathbb{R}^d \tag{VF}

각각의 x \in \mathbb{R}^d 마다 어떠한 vector v(x) 를 할당한 꼴이다.

왜 굳이 x v(x) 를 할당했을까?

v(x) 는 위치나 state x 에 있던 뭔가를 변하게 하는 힘이다.

v(x) 만큼의 크기와 방향으로 x 가 변한다는 것을 표현 한다.

vector field를 상태를 변하게 하는 힘이라 했다.

그런데 시간에 따라 상태가 변한다 치면 vector field가 항상 일정할까? 아니다. 그래서 나온 개념이 time depencent vector field

Time-dependent vector field

time-dependent vector field에 대해 알아보자.

t \in [0,T] 라 하자. time-dependent vector field란?

vector field v_t : \mathbb{R}^d \to \mathbb{R}^d t 에 의존하는 벡터필드다.

v_t : \mathbb{R}^d \to \mathbb{R}^d \tag{TVF}

x \in \mathbb{R}^d 라 하면 v_t(x) time t 에서 x 에 작용하는 힘이다.

vector field v_t 가 어떤 공간이나 위치에 작용함으로써 그 공간이 변함을 표현하는 것이다.

 

Flow에 대하여

이제 flow에 대하여 알아보자.

만약에 초기에 state가 x 라고 합시다.

그러면 힘 혹은 외부 변환 요인인 vector field v_t 가 작용함으로써 x 는 시간이 지남에 따라 변할것이다.

이 시간이 지남에 따라 변하는 것을 표현하는 것이 flow 이다.

이 flow는 ODE를 이용해 정의되고 기호로는 \phi_t: \mathbb{R}^d \to \mathbb{R}^d 라고 쓴다.

\frac{d}{dt} \phi_t(x) = v_t(\phi_t(x)), \phi_0(x)=x, t \in [0,T] \tag{Flow}

위와 같이 미분방정식을 쓰면 이해가 안될수도 있어서 아래와 같이 다시 써보자.

\phi_t(x) = x + \int_0^t v_\tau(\phi_\tau(x))d\tau \tag{Flow}

건조하게는 \phi_t(x) 는 초기에 x 이던것이 t 시점에서 어떤지를 보는것이다.

x 는 vector field v_t 의 영향이 누적되어 변화될것인데 누적된 time-dependent vector field는 flow식에서 \int_0^t v_\tau(\phi_\tau(x))d\tau 이렇게 나타낸다.

flow 는 t=0 에서 \phi_0(x) =x 상태가 있는데 변화의 근원, 힘의 근원이 vector field들 v_t 가 작용할 때 x 가 어떻게 변했는지를 보여준다.

\phi_t(x) : \text{ } x \text{가 time-dependent vector field의 영향을 받아 변하는데 t이후에 변화된 상태}

방금 위에서 한말을 수식적으로 멋지게 표현한것이 아래와 같다.

\frac{d}{dt} \phi_t(x) = v_t(\phi_t(x)), \phi_0(x)=x, t \in [0,T] \tag{Flow} \phi_t(x) = x + \int_0^t v_\tau(\phi_\tau(x))d\tau \tag{Flow}

 

Flow matching가지고 뭐할건데? 데이터 분포를 맞추자!

 

flow \phi_t(x) 는 initial state \phi_0(x)=x 가 time-dependent vector field v_t 의 영향을 받아 시간이 지남에 따라 어떻게 변하는지를 나타내는 것이라고 하였다.

\frac{d}{dt}\phi_t(x)=v_t(\phi_t(x)),\qquad \phi_0(x)=x,\qquad t\in[0,T]

flow matching에서는 이 flow를 가지고 무엇을 하려고 하는 것일까?

데이터 분포 pdf인 $p_{data}$ 여기서 부터 생성을 하고 싶으니까 하는 것이지!

\phi_t(x) 의 pdf 를 p_t 라고하자.

p_0 는 초기값이 \phi_0(x)=x 가질 수 있는 분포다.

생성을 위하여 많은 경우 가우시안 분포 (gaussian distribution)의 pdf p_{\text{simple}} = N(x; \mu_0, \sigma_0^2 I) 를 생각한다.

Flow matching의 목적은 p_0 = p_{simple} 일 때 p_T = p_{data} 가 되도록 하는 flow \phi_t(x) 혹은 vectorfield v_t 를 찾는것이다.

만약에 p_0 = p_{simple}, p_T = p_{data} 가 되도록 하는 flow와 vector field 를 아래와 같이 찾았으면

\frac{d}{dt} \phi_t(x) = v_t(\phi_t(x)), 0\leq t \leq T, \phi_0(x)=x

x p_0 에서 샘플이 있고 \phi_T(x) 를 구하면 데이터가 샘플이 하나 만들어진다.

data sample을 생성할만한 v_t 를 찾는 방법에 대해서는 나중에 논의하고 p_t 가 어떻게 움직이는지를 보도록 하자.

 

Continuity equation p_t 의 관계

\frac{d}{dt}\phi_t(x)=v_t(\phi_t(x)),\qquad \phi_0(x)=x,\qquad t\in[0,T]

위의 식에서 \phi_t(x) 의 pdf를 p_t 라고 표시하자. 이제 p_t 르 ㄹ어떻게 구할 수 있나 보겠다.

z=\phi_t(x)

라고 하자.

 

dz=\left|\nabla_x\phi_t(x)\right|dx

여기서 \nabla_x\phi_t(x) \phi_t x 에 대해 미분한 Jacobian matrix이고, \left|\nabla_x\phi_t(x)\right| 는 jacobian matrix의 determinant의 절대값이다.

\left|\nabla_x\phi_t(x)\right| x 주변에 직육면체를 잡았을때 부피가 있고 \phi_t(x) 로 옮겼을때 도형이 생길때 부피가 있는데 그것의 비라고 보면된다.

여튼

dz=\left|\nabla_x\phi_t(x)\right|dx

이 식을 이용하면 아래가 성립한다.

p_t(\phi_t(x))=p_0(x)\left|\nabla_x\phi_t(x)\right|^{-1}

다르게 쓰면

p_t(z)=p_0(\phi_t^{-1}(z))\left|\nabla_z \phi_t^{-1}(z)\right|

이것이 change of variables formula다.

이제 하나의 값 z 에 대하여 p_t(z) 의 변화를 보자.

아무 함수나 하나 잡자.

f:\mathbb{R}^d\to\mathbb{R}

\mathbb{E}_{z\sim p_t}[f(z)]=\mathbb{E}_{x\sim p_0}[f(\phi_t(x))]

이다.

\int f(z)p_t(z)dz=\int f(\phi_t(x))p_0(x)dx

편의상 양변을 시간에 대해 미분하면,

\int f(z)\frac{\partial}{\partial t}p_t(z)dz=\int\frac{\partial}{\partial t}f(\phi_t(x))p_0(x)dx

이다.

\frac{\partial}{\partial t}f(\phi_t(x))=\sum_i\frac{\partial f}{\partial\phi_{t,i}(x)}\frac{d\phi_{t,i}(x)}{dt}=\nabla_{\phi_t(x)}f(\phi_t(x))^\top v_t(\phi_t(x))

그러므로,

\int\frac{\partial}{\partial t}f(\phi_t(x))p_0(x)dx=\int\nabla_{\phi_t(x)}f(\phi_t(x))^\top v_t(\phi_t(x))p_0(x)dx

이다.

z=\phi_t(x),\qquad dz=\left|\nabla_x\phi_t(x)\right|dx

로 치환하면,

\int\nabla_{\phi_t(x)}f(\phi_t(x))^\top v_t(\phi_t(x))p_0(x)dx=\int\nabla_zf(z)^\top v_t(z)p_0(\phi_t^{-1}(z))\left|\nabla_z\phi_t^{-1}(z)\right|dz

=\mathbb{E}_{z\sim p_t}\left[\nabla_zf(z)^\top V_t(z)\right]

=\int p_t(z)\nabla_zf(z)^\top v_t(z)dz

이다.

\nabla_z\cdot\left(f(z)v_t(z)p_t(z)\right)=\nabla_zf(z)^\top v_t(z)p_t(z)+f(z)\nabla_z\cdot\left(v_t(z)p_t(z)\right)

이므로,

\int\nabla_zf(z)^\top v_t(z)p_t(z)dz=\int\nabla_z\cdot\left(f(z)v_t(z)p_t(z)\right)dz-\int f(z)\nabla_z\cdot\left(v_t(z)p_t(z)\right)dz

이다.

Divergence theorem에 의하여

\int_{\mathbb{R}^d}\nabla_z\cdot\left(f(z)v_t(z)p_t(z)\right)dz=\int_{\partial\mathbb{R}^d}\left(f(z)v_t(z)p_t(z)\right)^\top n(z)dS(z)=0

이므로

\int\nabla_zf(z)^\top v_t(z)p_t(z)dz=-\int f(z)\nabla_z\cdot\left(v_t(z)p_t(z)\right)dz

이다.

따라서,

\int f(z)\frac{\partial}{\partial t}p_t(z)dz=-\int f(z)\nabla_z\cdot\left(v_t(z)p_t(z)\right)dz

이다.

f 가 임의의 함수이므로,

\frac{\partial}{\partial t}p_t(z)=\nabla_z\cdot\left(v_t(z)p_t(z)\right)

이다.

이것을 z 가 고정일 때 P_t(z) 에 대한 결과와 실제로 \phi_t(x) 경로를 따라 움직이는 p_t(\phi_t(x)) 를 비교해보자.

\phi_t(x) 경로를 따라 움직이는 p_t(\phi_t(x)) 의 식을 instantaneous change of variable (ICOV)라고 부른다.

ICOV란? 실제 움직이는 경로 \phi_t(x) 에 대한 p_t 값, 부피값 변화

\frac{d}{dt}p_t(\phi_t(x))=\lim_{h\to0}\frac{p_{t+h}(\phi_{t+h}(x))-p_t(\phi_t(x))}{h}

이다.

\nabla_{\phi_t(x)}\cdot\left(v_t(\phi_t(x))p_t(\phi_t(x))\right)=\nabla_{\phi_t(x)}p_t(\phi_t(x))^\top v_t(\phi_t(x))+p_t(\phi_t(x))\nabla_{\phi_t(x)}\cdot v_t(\phi_t(x))

이다.

\frac{d}{dt}p_t(\phi_t(x))=\frac{\partial}{\partial t}p_t(\phi_t(x))\frac{dt}{dt}+\nabla_{\phi_t(x)}p_t(\phi_t(x))^\top\frac{d\phi_t(x)}{dt}

이다.

continuity equation에서,

\frac{\partial}{\partial t}p_t(\phi_t(x))+\nabla_{\phi_t(x)}p_t(\phi_t(x))^\top\frac{d\phi_t(x)}{dt}=-p_t(\phi_t(x))\nabla_{\phi_t(x)}\cdot v_t(\phi_t(x))

이고 p_t 로 나누면

\frac{1}{p_t(\phi_t(x))}\frac{\partial}{\partial t}p_t(\phi_t(x))+\frac{1}{p_t(\phi_t(x))}\nabla_{\phi_t(x)}p_t(\phi_t(x))^\top v_t(\phi_t(x))=-\nabla_{\phi_t(x)}\cdot v_t(\phi_t(x))

이다.

\frac{d}{dt}\log p_t(\phi_t(x))=-\nabla_{\phi_t(x)}\cdot v_t(\phi_t(x))

이다.

p_t(\phi_t(x))=p_0(x)\left|\nabla_x\phi_t(x)\right|^{-1}

이므로,

\frac{d}{dt}\log\left|\nabla_x\phi_t(x)\right|=\nabla_{\phi_t(x)}\cdot v_t(\phi_t(x))

이다.

혹은,

\frac{d}{dt}\log p_t(\phi_t(x))=-\operatorname{tr}\left(\nabla_{\phi_t(x)}v_t(\phi_t(x))\right)

\frac{d}{dt}\log\left|\nabla_x\phi_t(x)\right|=\operatorname{tr}\left(\nabla_{\phi_t(x)}v_t(\phi_t(x))\right)

위의 두식을 ICOV라고 보면 되겠다!!

Flow matching 용어정리 generate, generated

아래와 같은 ode가 있다고 하자.

\frac{d}{dt} \phi_t(x) = v_t (\phi_t(x)), \phi_0(x)=x , 0\leq t \leq T

\phi_t(x) 의 pdf를 p_t 라 하자.

이러면 vectorfield (v_t)_{0\leq t \leq T} (p_t)_{0 \leq t \leq T} 를 generate 한다고 말하거나

(p_t)_{0\leq t \leq T} is generated by (v_t)_{0 \leq t \leq T} 라고 말한다.

Flow matching의 목적

p_{simple} 를 gaussian distribution의 pdf (예를들어 N(\mu_0, \sigma_0^2I) 라 하자. 그리고 p_{data} 를 우리가 알고자 하는 분포라고 하자. flow matching의 목적은

p_0 = p_{data}, p_T = p_{simple} (p_t)_{0 \leq t \leq T} 를 생성하는 vector field (v_t)_{0 \leq t \leq T} 를 찾는것이다.

 

Flow matching loss (FM loss)

다시 ode를 생각하자.

\frac{d}{dt} \phi_t(x) =v_t(\phi_t(x)) , \phi_0(x)=x, 0\leq t \leq T

p_t \phi_t(x) 의 pdf라고 하자. 만약에 p_0 = p_{simpel} , p_T = p_{data} (p_t)_{0\leq t \leq T}를 생성하는 (v_t)_{0 \leq t \leq T} 라 하자. 그러면 아래와 같은 loss를 사용할 수도 있다, ( v_\theta 는 neural network)

L_{FM} (\theta) = E_{t \sim U[0,T]} E_{x_t \sim p_t(x_t)} \lVert v_t(x_t)-v_\theta (t,x_t) \rVert^2

또는 아래와 같이 쓸 수 있다.

L_{FM} (\theta) = E_{t \sim U[0,T]} E_{x \sim p_0(x)} \lVert v_t(\phi_t(x))-v_\theta (t,\phi_t(x)) \rVert^2

위의 두식에서 U[0,T] 는 0과 T사이의 uniform distribution이다. 위의 loss L_{FM} 를 flow matching loss라 부른다. flow matching loss 를 쓰고 싶지만 실제로 v_t, p_t 를 알기 어려워서 flow matching loss를 사용하지 못한다.

[1] Lipman, Y., Chen, R. T. Q., Ben-Hamu, H., Nickel, M., & Le, M. (2023). Flow Matching for Generative Modeling. International Conference on Learning Representations (ICLR).

[2] Lee, S., Cheong, S., Han, S., & Shin, J. W. (2025). FlowSE: Flow Matching-based Speech Enhancement. In ICASSP 2025 – 2025 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP),

Leave a Comment