class
MeanFlowForImageGeneration
extends
ImageGenerationModelMeanFlowForImageGeneration(config: MeanFlowConfig)MeanFlow's objective and its one-step sampler.
Parameters
configMeanFlowConfigThe variant to build.
Attributes
mean_flowMeanFlowModelThe average-velocity network.
Notes
Reference: Geng, Deng, Bai, Kolter, and He, "Mean Flows for One-step Generative Modeling", arXiv:2505.13447, 2025. Training is Algorithm 1, sampling is Algorithm 2 and Eq. 12.
Examples
>>> import lucid
>>> from lucid.models.generative.mean_flow import (
... MeanFlowConfig, MeanFlowForImageGeneration)
>>> config = MeanFlowConfig(sample_size=8, patch_size=2, hidden_size=32,
... depth=2, num_heads=4, num_classes=10)
>>> model = MeanFlowForImageGeneration(config).eval()
>>> model.generate(2).samples.shape
(2, 4, 8, 8)Used by 2
Constructors
1Instance methods
2forward(images: Tensor, labels: Tensor | None = None)One training step of the MeanFlow objective.
Parameters
Returns
MeanFlowOutputThe weighted loss, the prediction and the target.
Notes
The Jacobian-vector product is taken along — the tangent that the chain rule gives for once and are substituted. Any other tangent trains a different quantity: the paper's destructive ablation reports FID 61.06 for this one and 137–329 for the alternatives.
generate(n_samples: int = 1, labels: Tensor | None = None, steps: int = 1, noise: Tensor | None = None, device: str | None = None)Sample by walking the average velocity backwards from noise.
Parameters
n_samplesint= 1How many to draw.
(n_samples,) class indices. None samples the
unconditional field.stepsint= 1Network evaluations. One is the point of the method:
covers the whole path. More
subdivide and apply Eq. 12 on each piece, which
the paper notes is straightforward and reports at two.
Starting point . Drawn when absent.
devicestr or None= NoneWhere to draw. Defaults to the model's own device.
Returns
GenerationOutputsamples of shape (n_samples, out_channels, H, W).
Raises
ValueErrorIf
steps is not positive.Examples
>>> import lucid
>>> from lucid.models.generative.mean_flow import (
... MeanFlowConfig, MeanFlowForImageGeneration)
>>> config = MeanFlowConfig(sample_size=8, patch_size=2,
... hidden_size=32, depth=2, num_heads=4,
... num_classes=10)
>>> model = MeanFlowForImageGeneration(config).eval()
>>> model.generate(2).samples.shape
(2, 4, 8, 8)