Skip to content

PLAYERUNKNOWN-Productions/rectified-flow-matching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rectified Flow Matching (RFM) tutorial

This repository contains a Jupyter notebook implementing and explaining the Rectified Flow Matching algorithm for generating samples from a target distribution. The tutorial demonstrates the transformation from a simple Gaussian distribution to a complex star-shaped distribution.

Overview

Rectified Flow Matching (RFM) is a powerful technique for learning transformations between probability distributions. It builds on the idea of learning an explicit velocity field that transports samples from source to target distributions along smooth paths, as introduced in Flow Straight and Fast.

Recent developments such as Flow Matching in Latent Space and Conditional Generation and Downstream Tasks explore how these methods can be extended to more complex generative tasks. This tutorial focuses on the core concepts of RFM and the ReFlow technique.

This tutorial provides:

  • Detailed implementation of RFM in PyTorch
  • Visual demonstrations of the transformation process
  • Implementation of the ReFlow training technique for faster sampling

For a simplified explanation of RFM concepts and real-world applications in generative AI, see SIMPLE.md.

Key components

This tutorial demonstrates the core components of RFM and ReFlow. The goal is to show how to learn a velocity field that transports samples between distributions, and how to efficiently perform sampling using both time-dependent and time-independent approaches.

The following components are covered in the notebook:

  1. Distribution transformation

    • Transform samples from a standard Gaussian to a star-shaped mixture of Gaussians
    • Visualize the transformation process step by step
  2. Model architecture

    • Neural network implementation of the velocity field
    • Sinusoidal position embeddings for time encoding
    • Batch normalization and residual connections
  3. Training methods

    • Standard RFM training
    • ReFlow training for single-step generation
    • Visualization of both approaches

Usage

  1. Open the explain_reflow.ipynb notebook in Jupyter
  2. Run all cells sequentially
  3. Observe the transformation process through generated visualizations

References

License

Apache 2.0

About

A Jupyter notebook tutorial for Rectified Flow Matching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published