Bellaard

Flow Matching

By: Gijs Bellaard

A few days ago I was reading a blog post on flow matching and diffusion models. After reading it, I felt inspired to finally make my own toy flow matching implementation. I started in one dimension for simplicity. The code can be found in this Python notebook. I considered the following two 1D distributions.

Two 1D Distributions

On the left we have a standard normal distribution with unit variance, and on the right a mixture of three scaled and translated normal distributions. After training a simple multi-layer perceptron to "match the flow" between the two distributions, we can visualize the resulting vector field.

Learned Vector Field

We can also visualize how increasing the amount of sampling steps increases the quality of the samples. From the left to the right we have 1, 2, 4, 8, and 16 sampling steps.

Sampling

Once I got the 1D flow matching working, I went to two dimensions. The code can be found in this Python notebook. I considered the following two 2D distributions.

Two 2D Distributions

We can visualize the resulting flow as an animation this time, which I found to be extremely pleasing to watch.