PeRFlowModel<T>

Models & Types · AiDotNet.Diffusion.FastGeneration

PeRFlow (Piecewise Rectified Flow) model for few-step generation via flow straightening.

Inheritance: DiffusionModelBase<T> → LatentDiffusionModelBase<T> → PeRFlowModel<T>

For Beginners

Instead of trying to straighten the entire winding road from noise to image at once, PeRFlow divides it into segments and straightens each piece. This is easier and more effective — like fixing a winding highway by straightening each curve individually rather than rebuilding the whole road.

How It Works

PeRFlow divides the time interval [0,1] into K segments and straightens the flow within each segment independently. This piecewise approach is more effective than global straightening (Reflow) because each segment needs less straightening, achieving better quality at 4-8 steps.

Reference: Yan et al., “PeRFlow: Piecewise Rectified Flow as Universal Plug-and-Play Accelerator”, 2024

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 4, DefaultInferenceSteps = 4 };
var noise = Tensor<float>.CreateRandom(new[] { 1, 4, 64, 64 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new PeRFlowModel<float>(options: options))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
PeRFlowModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, UNetNoisePredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int numSegments, int? seed) Initializes a new PeRFlow model.

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }
int NumSegments { get; } Gets the number of piecewise segments.

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()