← 开源
zhuyu-cs

MeanFlow

Pytorch implementation of MeanFlow on ImageNet and CIFAR10

ModelsVision modelsPython
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
517
Star
38
Fork
+0
本周
3
贡献者
创建于 2025-05-23 · 更新于 2026-09-29 · 今日第 17938 名
主要开发者
zhuyu-csottoginfree001style

zhuyu-cs/MeanFlow 排名第 17,938,有 517 个星标。

同类别比较

zhuyu-cs/MeanFlow 排名第 17,938,此处有 8 个同类条目;MAGICS-LAB/DNABERT_2 排名第 17,942。

同类别比较
名称排名指标
NVlabs/DiffiT17,868
语言:
Python
星标数:
519
分叉数:
21
简介:
[ECCV 2024] Official Repository for DiffiT: Diffusion Vision Transformers for Image Generation
SCIR-TG/FengZhengLLM17,893
语言:
Python
星标数:
518
分叉数:
1
r9y9/gantts17,903
语言:
Jupyter Notebook
星标数:
518
分叉数:
116
简介:
PyTorch implementation of GAN-based text-to-speech synthesis and voice conversion (VC)
acids-ircam/ddsp_pytorch17,922
语言:
C
星标数:
517
分叉数:
62
简介:
Implementation of Differentiable Digital Signal Processing (DDSP) in Pytorch
MAGICS-LAB/DNABERT_217,942
语言:
Shell
星标数:
516
分叉数:
103
简介:
[ICLR 2024] DNABERT-2: Efficient Foundation Model and Benchmark for Multi-Species Genome
KangLiao929/Puffin17,962
语言:
Python
星标数:
515
分叉数:
23
简介:
Puffin Series: Towards Unified Multimodal 3D World Models
Atten4Vis/LW-DETR17,980
语言:
Python
星标数:
514
分叉数:
47
简介:
This repository is an official implementation of the paper "LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection".
baidu/ERNIE-Image17,994
语言:
Python
星标数:
514
分叉数:
37
简介:
ERNIE-Image is an open text-to-image generation model developed by the ERNIE-Image team at Baidu. It is built on a single-stream Diffusion Transformer (DiT), with only 8B DiT parameters, it reaches state-of-the-art performance among open-weight text-to-image models.
关键参数与规格
关键参数与规格
参数值
语言Python
类别Models
子类别Vision models
关键词Computer vision, Image production, Model architecture
星标数517
分叉数38
贡献者3
创建日期2025-05-23
更新日期2026-09-29
1 天星标数0
7 天星标数0
排名17,938
上次排名17,713
排名变化-225
7 天星标排名16,380
上次 7 天星标排名16,390
7 天星标排名变化10
总星标排名18,883
上次总星标排名18,860
总星标排名变化-23
README 摘录

MeanFlow: Pytorch Implementation This repository contains a minimalist PyTorch implementation of MeanFlow, a novel single-step flow matching model for high-quality image generation. 43, Table 2| **Note**: **All the weights trained on ImageNet256 are availavle at here**. 93, 240 epoch, Table 2| |SiT-XL/2(w cfg) + pretrained weights (1400 epoch)|15. 20, 1000 epoch, Table 2| **Tips**: Direct fine-tuning using MeanFlow with classifier-free guidance (CFG) exhibits training instability. To address this issue, we adopt a staged

training strategy: initially fine-tuning with MeanFlow without CFG for 20 epochs, followed by continued fine-tuning with CFG-enabled MeanFlow. 0 during inference, as the CFG guidance has been incorporated into the model during training and is no longer controllable at sampling time. We currently use sd-vae-ft-ema, which is not the suggested tokenizer in original paper (sd-vae-ft-mse). **Maybe replacing with would yield better results**. Installation Usage ImageNet 256 **Preparing Data** This implementation requires

ImageNet ILSVRC2012 (1000 classes). The preprocessing converts images to VAE-encoded latents in LMDB format. Expected directory structure: **Step 1:** Convert ImageNet to LMDB format using : **Step 2:** Encode images to VAE latents: **Training** We provide training configurations for different model scales (B, L, XL) based on the hyperparameters from the original paper:: Each configuration is optimized for different model sizes according to the original paper's settings. **Finetuning with pretrained flow matching model** For finetuning explorations, please use the branch

. **Sampling and Evaluation** For large-scale sampling and quantitative evaluation (FID, IS), we provide a distributed evaluation framework: This evaluation performs distributed sampling across 8 GPUs to generate 50,000 high-quality samples for robust FID computation. The framework validates MeanFlow's single-step generation capability (num-steps=1) and computes FID scores against pre-computed ImageNet statistics. CIFAR10 **Requirements** NVIDIA A100/H100 80GB GPU recommended for optimal performance *Note: The UNet architecture needs higher memory consumption compared to Diffusion Transformer

(DiT) models* **Training** 1. Switch to the CIFAR-10 experimental branch: 2. Memory-Efficient Training (Lower GPU Memory) 3. 35| Acknowledgements This implementation builds upon: SiT (model architecture) REPA (training pipeline) MAR (data preprocessing) Official MeanFlow Repos See also: Official MeanFlow JAX repo with ImageNet experiments. Official MeanFlow PyTorch repo with CIFAR10 experiments. Citation If you find this implementation useful in your research, please cite the original work and this repo: License MIT License

常见问题

记录了多少星标和分叉?

zhuyu-cs/MeanFlow 有 517 个星标和 38 个分叉。

仓库排名是多少?

zhuyu-cs/MeanFlow 排名第 17,938。

记录的语言和类别是什么?

zhuyu-cs/MeanFlow 有 517 个星标,语言为 Python,类别为 Models。

哪个仓库排名最接近?

zhuyu-cs/MeanFlow 与 MAGICS-LAB/DNABERT_2 比较,后者排名第 17,942,有 516 个星标。

README

MeanFlow: Pytorch Implementation

This repository contains a minimalist PyTorch implementation of MeanFlow, a novel single-step flow matching model for high-quality image generation.

Reproduced ImageNet Results

Model Epoch FID(NFE=1), our results FID(NFE=1), results in paper
SiT-B/4(wo cfg) 80 58.74 61.06, Table 1f
SiT-B/4 80 15.43 15.53, Table 1f
SiT-B/2 240 6.06 6.17, Table 2
SiT-L/2 240 3.94(140/240) 3.84, Table 2
SiT-XL/2 240 3.39(200/240) 3.43, Table 2

Note: All the weights trained on ImageNet256 are availavle at here.

DO NOT overlook the pretrained flow matching model:Fine-tuning Pretrained Flow Matching Models with MeanFlow

Model FID(NFE=1), our results FID(NFE=2), our results FID(NFE=2), results in paper
SiT-XL/2(w cfg) + pretrained weights (1400 epoch) 4.52 2.81 (1400+20+40) 2.93, 240 epoch, Table 2
SiT-XL/2(w cfg) + pretrained weights (1400 epoch) 15.50 2.55 (1400+20+110) 2.20, 1000 epoch, Table 2

Tips: Direct fine-tuning using MeanFlow with classifier-free guidance (CFG) exhibits training instability. To address this issue, we adopt a staged training strategy: initially fine-tuning with MeanFlow without CFG for 20 epochs, followed by continued fine-tuning with CFG-enabled MeanFlow.

Notes:

  1. When evaluating models trained with CFG , the --cfg-scale parameter must be set to 1.0 during inference, as the CFG guidance has been incorporated into the model during training and is no longer controllable at sampling time.
  2. We currently use sd-vae-ft-ema, which is not the suggested tokenizer in original paper (sd-vae-ft-mse). Maybe replacing with sd-vae-ft-mse would yield better results.

Installation

# Clone this repository
git clone https://github.com/zhuyu-cs/MeanFlow.git
cd MeanFlow

# Install dependencies
pip install -r requirements.txt

Usage

ImageNet 256

Preparing Data

This implementation requires ImageNet ILSVRC2012 (1000 classes). The preprocessing converts images to VAE-encoded latents in LMDB format.

Expected directory structure:

ImageNet/
└── train/
    ├── n01440764/
    │   ├── n01440764_10026.JPEG
    │   └── ...
    ├── n01443537/
    └── ... (1000 class folders)

Step 1: Convert ImageNet to LMDB format using preprocess_imagenet/image2lmdb.py:

# Edit the paths in image2lmdb.py, then run:
cd ./preprocess_imagenet
python image2lmdb.py

Step 2: Encode images to VAE latents:

cd ./preprocess_imagenet
torchrun --nproc_per_node=8 --nnodes=1 --node_rank=0 \
    main_cache.py \
    --source_lmdb /path/to/imagenet_train.lmdb \
    --target_lmdb /path/to/train_vae_latents_lmdb \
    --img_size 256 \
    --batch_size 1024 \
    --lmdb_size_gb 400

Training

We provide training configurations for different model scales (B, L, XL) based on the hyperparameters from the original paper::


accelerate launch --multi_gpu \
    train.py \
    --exp-name "meanflow_b_4" \
    --output-dir "work_dir" \
    --data-dir "/data/train_vae_latents_lmdb" \
    --model "SiT-B/4" \
    --resolution 256 \
    --batch-size 256 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 80\
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -0.4 \
    --time-sigma 1.0 \
    --ratio-r-not-equal-t 0.25 \
    --adaptive-p 1.0 \
    --cfg-omega 3.0 \ #1.0 for no cfg
    --cfg-kappa 0.\
    --cfg-min-t 0.0\
    --cfg-max-t 1.0

accelerate launch --multi_gpu \
    train.py \
    --exp-name "meanflow_b_2" \
    --output-dir "exp" \
    --data-dir "/data/train_vae_latents_lmdb" \
    --model "SiT-B/2" \
    --resolution 256 \
    --batch-size 256 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 240\
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -0.4 \
    --time-sigma 1.0 \
    --ratio-r-not-equal-t 0.25 \
    --adaptive-p 1.0 \
    --cfg-omega 1.0 \
    --cfg-kappa 0.5\
    --cfg-min-t 0.0\
    --cfg-max-t 1.0

accelerate launch --multi_gpu \
    train.py \
    --exp-name "meanflow_l_2" \
    --output-dir "exp" \
    --data-dir "/data/train_vae_latents_lmdb" \
    --model "SiT-L/2" \
    --resolution 256 \
    --batch-size 256 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 240\
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -0.4 \
    --time-sigma 1.0 \
    --ratio-r-not-equal-t 0.25 \
    --adaptive-p 1.0 \
    --cfg-omega 0.2 \
    --cfg-kappa 0.92\
    --cfg-min-t 0.0\
    --cfg-max-t 0.8

accelerate launch --multi_gpu \
    train.py \
    --exp-name "meanflow_xl_2" \
    --output-dir "exp" \
    --data-dir "/data/train_vae_latents_lmdb" \
    --model "SiT-XL/2" \
    --resolution 256 \
    --batch-size 256 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 240\
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -0.4 \
    --time-sigma 1.0 \
    --ratio-r-not-equal-t 0.25 \
    --adaptive-p 1.0 \
    --cfg-omega 0.2 \
    --cfg-kappa 0.92\
    --cfg-min-t 0.0\
    --cfg-max-t 0.75

accelerate launch --multi_gpu \
    train.py \
    --exp-name "meanflow_xl_2_plus" \
    --output-dir "exp" \
    --data-dir "/data/train_vae_latents_lmdb" \
    --model "SiT-XL/2" \
    --resolution 256 \
    --batch-size 256 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 1000\
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -0.4 \
    --time-sigma 1.0 \
    --ratio-r-not-equal-t 0.25 \
    --adaptive-p 1.0 \
    --cfg-omega 1.0 \
    --cfg-kappa 0.5\
    --cfg-min-t 0.3\
    --cfg-max-t 0.8

Each configuration is optimized for different model sizes according to the original paper's settings.

Finetuning with pretrained flow matching model

For finetuning explorations, please use the finetune_fm branch.

git checkout finetune_fm

Sampling and Evaluation

For large-scale sampling and quantitative evaluation (FID, IS), we provide a distributed evaluation framework:

torchrun --nproc_per_node=8 --nnodes=1 evaluate.py \
    --ckpt "/path/to/the/weights" \
    --model "SiT-L/2" \
    --resolution 256 \
    --cfg-scale 1.0 \
    --per-proc-batch-size 128 \
    --num-fid-samples 50000 \
    --sample-dir "./fid_dir" \
    --compute-metrics \
    --num-steps 1\
    --fid-statistics-file "./fid_stats/adm_in256_stats.npz"

This evaluation performs distributed sampling across 8 GPUs to generate 50,000 high-quality samples for robust FID computation. The framework validates MeanFlow's single-step generation capability (num-steps=1) and computes FID scores against pre-computed ImageNet statistics.

CIFAR10

Requirements

  • NVIDIA A100/H100 80GB GPU recommended for optimal performance

Note: The UNet architecture needs higher memory consumption compared to Diffusion Transformer (DiT) models

Training

  1. Switch to the CIFAR-10 experimental branch:
git checkout cifar10
  1. Standard Training (High Memory)
accelerate launch --num_processes=8 \
    train.py \
    --exp-name "cifar_unet" \
    --output-dir "work_dir" \
    --data-dir "/data/dataset/train_sdvae_latents_lmdb" \
    --resolution 32 \
    --batch-size 1024 \
    --allow-tf32 \
    --mixed-precision "bf16" \
    --epochs 19200\ # about 800k iters.
    --path-type "linear" \
    --weighting "adaptive" \
    --time-sampler "logit_normal" \
    --time-mu -2.0 \
    --time-sigma 2.0 \
    --ratio-r-not-equal-t 0.75 \
    --adaptive-p 0.75
  1. Memory-Efficient Training (Lower GPU Memory)
accelerate launch --num_processes=8 \
      train.py \
      --exp-name "cifar_unet" \
      --output-dir "work_dir" \
      --data-dir "/data/dataset/train_sdvae_latents_lmdb" \
      --resolution 32 \
      --batch-size 512 \
      --gradient-accumulation-steps 2 \
      --allow-tf32 \
      --mixed-precision "bf16" \
      --epochs 19200\ 
      --path-type "linear" \
      --weighting "adaptive" \
      --time-sampler "logit_normal" \
      --time-mu -2.0 \
      --time-sigma 2.0 \
      --ratio-r-not-equal-t 0.75 \
      --adaptive-p 0.75
  1. Evaluation
torchrun --nproc_per_node=8 evaluate.py \
    --ckpt "./work_dir/cifar_unet/checkpoints/0200000.pt" \
    --per-proc-batch-size 128 \
    --num-fid-samples 50000 \
    --sample-dir "./fid_dir" \
    --compute-metrics \
    --num-steps 1\
    --fid-ref "train"

Results

Iters FID(NFE=1)
50k 210.36
100k 6.35

Acknowledgements

This implementation builds upon:

  • SiT (model architecture)
  • REPA (training pipeline)
  • MAR (data preprocessing)

Official MeanFlow Repos

See also:

Citation

If you find this implementation useful in your research, please cite the original work and this repo:

@article{geng2025mean,
  title={Mean Flows for One-step Generative Modeling},
  author={Geng, Zhengyang and Deng, Mingyang and Bai, Xingjian and Kolter, J Zico and He, Kaiming},
  journal={arXiv preprint arXiv:2505.13447},
  year={2025}
}

@misc{meanflow_pytorch,
  title={MeanFlow: PyTorch Implementation},
  author={Zhu, Yu},
  year={2025},
  howpublished={\url{https://github.com/zhuyu-cs/MeanFlow}},
  note={PyTorch implementation of Mean Flows for One-step Generative Modeling}
}

License

MIT License

排名相邻
同类项目