Transfusion<T>

Models & Types · AiDotNet.VisionLanguage.Unified

Transfusion: combined autoregressive and diffusion loss in single transformer.

Inheritance: NeuralNetworkBase<T> → VisionLanguageModelBase<T> → Transfusion<T>

Implements: IUnifiedVisionModel<T>

For Beginners

Transfusion is a unified model that combines autoregressive text generation with diffusion-based image generation. Default values follow the original paper settings.

How It Works

Transfusion (Meta, 2024) combines autoregressive next-token prediction and continuous diffusion loss within a single multi-modal transformer. Text tokens use cross-entropy loss while image patches use diffusion denoising loss, allowing the model to both generate text autoregressively and produce high-quality images through diffusion within a unified architecture.

References:

  • Paper: “Transfusion: Predict the Next Token and Diffuse Images with One Multi-Modal Model” (Meta, 2024)

Example

// Create a Transfusion model combining autoregressive and diffusion objectives
// in a single transformer for unified text and image generation
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.TwoDimensional,
    taskType: NeuralNetworkTaskType.ImageClassification,
    inputHeight: 224, inputWidth: 224, inputDepth: 3, outputSize: 512);
            
// ONNX inference mode with pre-trained model
var model = new Transfusion<double>(architecture, "transfusion.onnx");
            
// Training mode with native layers
var trainModel = new Transfusion<double>(architecture, new TransfusionOptions());

Constructors

Constructor Summary
Transfusion(NeuralNetworkArchitecture<T> architecture, TransfusionOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
Transfusion(NeuralNetworkArchitecture<T> architecture, string modelPath, TransfusionOptions options)

Properties

Property Summary
bool SupportsGeneration { get; }
int DecoderEmbeddingDim { get; }
int EmbeddingDimension { get; }
int MaxGenerationLength { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
Tensor<T> EncodeImage(Tensor<T> image)
Tensor<T> GenerateFromImage(Tensor<T> image, string prompt) Generates text from image using Transfusion’s mixed-modal transformer.
Tensor<T> GenerateImage(string textDescription) Generates an image from text with the model the objective trains (Zhou et al.