MARModel<T>

Models & Types · AiDotNet.Diffusion.FastGeneration

Masked Autoregressive (MAR) model for image generation via masked token prediction.

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

For Beginners

MAR treats image generation like filling in a puzzle. It starts with all pieces hidden (masked) and progressively reveals them, predicting what each piece looks like based on the already-revealed pieces. This approach bridges autoregressive models (like GPT) and diffusion models.

How It Works

MAR generates images by progressively predicting masked tokens in a discrete latent space. Unlike standard diffusion which adds/removes continuous noise, MAR works with discrete tokens and uses a masking strategy that enables flexible generation ordering and variable-speed generation.

Reference: Li et al., “Autoregressive Image Generation without Vector Quantization”, NeurIPS 2024

Example

var options = new DiffusionModelOptions<float> { LatentChannels = 16, DefaultInferenceSteps = 12 };
var noise = Tensor<float>.CreateRandom(new[] { 1, 16, 32, 32 });
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 MARModel<float>(options: options))
    .Build(trainX, trainY);
var generated = result.Predict(noise);

Constructors

Constructor Summary
MARModel(NeuralNetworkArchitecture<T> architecture, DiffusionModelOptions<T> options, INoiseScheduler<T> scheduler, SiTPredictor<T> predictor, StandardVAE<T> vae, IConditioningModule<T> conditioner, int? seed)

Properties

Property Summary
IConditioningModule<T> Conditioner { get; }
INoisePredictor<T> NoisePredictor { get; }
IVAEModel<T> VAE { get; }
int LatentChannels { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()