PyTorch implementation of MeanFlow & iMF (one-step generative modeling).
Python
1,204
81 commits
updated Jul 1, 2026
PyTorch implementation of Mean Flows for One-step Generative Modeling (MeanFlow) and Improved Mean Flows (iMF).
Note: Unofficial implementation, based on the papers above and the official JAX repo imeanflow.
Contributions and feedback are welcome! Feel free to open an issue or pull request.
2026.06.13
meanflow.mode: "meanflow" / "i-meanflow")u for MeanFlow, v for flow matchingcfg_scale; None to disable)no_grad for dudt only; separate grad-enabled forward pass for optimizationi-meanflow (meanflow.mode: "i-meanflow") is more stable and recommended for your projects. meanflow mode is kept for reference.
pip install torch accelerate torchvision einops tqdm diffusers
# single GPU
python train.py --config configs/mnist.py
# custom run name
python train.py --config configs/cifar10.py --run_suffix exp1
# multi-GPU
accelerate launch --num_processes 2 train.py --config configs/mnist.py
| Config | Dataset |
|---|---|
configs/mnist.py | MNIST |
configs/cifar10.py | CIFAR-10 |
configs/imagenet_latent.py | ImageNet (latent, VAE) |
Common config fields: n_steps, batch_size, grad_clip, mixed_precision, meanflow.mode, meanflow.cfg_scale.
Training logs are saved to logs/{run_name}/:
logs/{run_name}/
├── config.py
├── train.log # loss, FM/MF loss, MF_V_MSE, grad norm, LR
├── images/
└── ckpts/
MNIST — 10k steps, 1-step sample:

MNIST — 6k steps, 1-step CFG (w=2.0):

CIFAR-10 — 200k steps, 1-step CFG (w=2.0):

jvp is currently incompatible with PyTorch's native Flash Attention (scaled_dot_product_attention).
Solution in this repo:
no_grad (for dudt only) without Flash Attention.Other advanced solutions:
Building upon Just-a-DiT and EzAudio.
iMF support is based on the official JAX repo imeanflow. Thanks to the authors for releasing their code.
If you find this repo helpful, consider dropping a ⭐, it really helps!
If you find this repository useful in your research or projects, please consider citing the original MeanFlow papers as well as this implementation.
@article{geng2025meanflow,
title={Mean Flows for One-step Generative Modeling},
author={Geng, Zhengyang and Shechtman, Eli and Kolter, J. Zico and He, Kaiming},
journal={arXiv preprint arXiv:2505.13447},
year={2025}
}
@article{geng2025improved,
title={Improved Mean Flows: On the Challenges of Fastforward Generative Models},
author={Geng, Zhengyang and Lu, Yiyang and Wu, Zongze and Shechtman, Eli and Kolter, J. Zico and He, Kaiming},
journal={arXiv preprint arXiv:2512.02012},
year={2025}
}
@misc{meanflow_pytorch,
title={MeanFlow: Unofficial PyTorch Implementation},
author={haidog-yaqub},
year={2025},
howpublished={\url{https://github.com/haidog-yaqub/MeanFlow}},
}
154 followers · starred May 2025
Python
100.0%
PyTorch implementation of MeanFlow & iMF (one-step generative modeling).
Python
1,204
81 commits
updated Jul 1, 2026
PyTorch implementation of Mean Flows for One-step Generative Modeling (MeanFlow) and Improved Mean Flows (iMF).
Note: Unofficial implementation, based on the papers above and the official JAX repo imeanflow.
Contributions and feedback are welcome! Feel free to open an issue or pull request.
2026.06.13
meanflow.mode: "meanflow" / "i-meanflow")u for MeanFlow, v for flow matchingcfg_scale; None to disable)no_grad for dudt only; separate grad-enabled forward pass for optimizationi-meanflow (meanflow.mode: "i-meanflow") is more stable and recommended for your projects. meanflow mode is kept for reference.
pip install torch accelerate torchvision einops tqdm diffusers
# single GPU
python train.py --config configs/mnist.py
# custom run name
python train.py --config configs/cifar10.py --run_suffix exp1
# multi-GPU
accelerate launch --num_processes 2 train.py --config configs/mnist.py
| Config | Dataset |
|---|---|
configs/mnist.py | MNIST |
configs/cifar10.py | CIFAR-10 |
configs/imagenet_latent.py | ImageNet (latent, VAE) |
Common config fields: n_steps, batch_size, grad_clip, mixed_precision, meanflow.mode, meanflow.cfg_scale.
Training logs are saved to logs/{run_name}/:
logs/{run_name}/
├── config.py
├── train.log # loss, FM/MF loss, MF_V_MSE, grad norm, LR
├── images/
└── ckpts/
MNIST — 10k steps, 1-step sample:

MNIST — 6k steps, 1-step CFG (w=2.0):

CIFAR-10 — 200k steps, 1-step CFG (w=2.0):

jvp is currently incompatible with PyTorch's native Flash Attention (scaled_dot_product_attention).
Solution in this repo:
no_grad (for dudt only) without Flash Attention.Other advanced solutions:
Building upon Just-a-DiT and EzAudio.
iMF support is based on the official JAX repo imeanflow. Thanks to the authors for releasing their code.
If you find this repo helpful, consider dropping a ⭐, it really helps!
If you find this repository useful in your research or projects, please consider citing the original MeanFlow papers as well as this implementation.
@article{geng2025meanflow,
title={Mean Flows for One-step Generative Modeling},
author={Geng, Zhengyang and Shechtman, Eli and Kolter, J. Zico and He, Kaiming},
journal={arXiv preprint arXiv:2505.13447},
year={2025}
}
@article{geng2025improved,
title={Improved Mean Flows: On the Challenges of Fastforward Generative Models},
author={Geng, Zhengyang and Lu, Yiyang and Wu, Zongze and Shechtman, Eli and Kolter, J. Zico and He, Kaiming},
journal={arXiv preprint arXiv:2512.02012},
year={2025}
}
@misc{meanflow_pytorch,
title={MeanFlow: Unofficial PyTorch Implementation},
author={haidog-yaqub},
year={2025},
howpublished={\url{https://github.com/haidog-yaqub/MeanFlow}},
}
154 followers · starred May 2025
Python
100.0%