User Story
As a machine learning engineer, I want to leverage a wider variety of diffusion schedulers and advanced diffusion models (like Latent Diffusion) within the AiDotNet library, so that I can experiment with cutting-edge techniques for generative AI and improve the quality and speed of image generation.
Architectural Foundation (Assumed from #261 & #263)
This plan assumes the foundational interfaces and models from Part 1 exist, specifically: IDiffusionModel<T>, IStepScheduler<T>, DDPMModel<T>, and DDIMScheduler<T>.
Phase 1: Advanced Scheduler Implementation
Goal: Implement a suite of popular and powerful diffusion schedulers.
AC 1.1: PNDMScheduler<T> (3 points)
AC 1.2: DPMSolverMultistepScheduler<T> (5 points)
AC 1.3: Additional Schedulers (3 points each)
Phase 2: U-Net and VAE Implementation
Goal: Build the core neural network architectures required for latent diffusion.
AC 2.1: U-Net Sub-Components (8 points)
Requirement: Create the generic building blocks of the U-Net.
AC 2.2: U-Net Model (8 points)
Requirement: Assemble the U-Net from its building blocks.
AC 2.3: VAE Model (8 points)
Requirement: Build the Variational Autoencoder to move between pixel and latent space.
Phase 3: Latent Diffusion Pipeline
Goal: Combine all the components into a functioning latent diffusion model.
AC 3.1: LatentDiffusionModel<T> (5 points)
Requirement: Create the final pipeline class that orchestrates the full generative process.
Definition of Done
⚠️ CRITICAL ARCHITECTURAL REQUIREMENTS
Before implementing this user story, you MUST review:
Mandatory Implementation Checklist
1. INumericOperations Usage (CRITICAL)
2. Inheritance Pattern (REQUIRED)
3. PredictionModelBuilder Integration (REQUIRED)
4. Beginner-Friendly Defaults (REQUIRED)
5. Property Initialization (CRITICAL)
6. Class Organization (REQUIRED)
7. Documentation (REQUIRED)
8. Testing (REQUIRED)
⚠️ Failure to follow these requirements will result in repeated implementation mistakes and PR rejections.
See full details: .github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md
User Story
Architectural Foundation (Assumed from #261 & #263)
This plan assumes the foundational interfaces and models from Part 1 exist, specifically:
IDiffusionModel<T>,IStepScheduler<T>,DDPMModel<T>, andDDIMScheduler<T>.Phase 1: Advanced Scheduler Implementation
Goal: Implement a suite of popular and powerful diffusion schedulers.
AC 1.1:
PNDMScheduler<T>(3 points)src/Diffusion/Schedulers/PNDMScheduler.cs.PNDMScheduler<T>to conform to theIStepScheduler<T>interface.Stepmethod must correctly implement the Pseudo Numerical Methods for Diffusion Models algorithm, which involves using the outputs from the previous 4 steps to calculate the next one.AC 1.2:
DPMSolverMultistepScheduler<T>(5 points)src/Diffusion/Schedulers/DPMSolverMultistepScheduler.cs.DPMSolverMultistepScheduler<T>to conform toIStepScheduler<T>.Stepmethod must implement the DPM-Solver++ algorithm, including the data-dependent correction term.AC 1.3: Additional Schedulers (3 points each)
LMSDiscreteScheduler<T>: Implement the Linear Multi-Step scheduler.HeunDiscreteScheduler<T>: Implement the Heun's method second-order ODE solver.EulerDiscreteScheduler<T>: Implement the simple first-order Euler method.EulerAncestralDiscreteScheduler<T>: Implement the Euler method with added noise at each step.IStepScheduler<T>, and have corresponding unit tests.Phase 2: U-Net and VAE Implementation
Goal: Build the core neural network architectures required for latent diffusion.
AC 2.1: U-Net Sub-Components (8 points)
Requirement: Create the generic building blocks of the U-Net.
src/NeuralNetworks/Architectures/UNet/ResNetBlock<T>:ResNetBlock.cs.Convolutionlayers, twoGroupNormalizationlayers, and aSiLUactivation. It must handle a skip connection.AttentionBlock<T>:AttentionBlock.cs.Linearlayers for Query, Key, and Value projections, followed by aSoftmaxand matrix multiplications.DownsampleBlock<T>&UpsampleBlock<T>:DownsampleBlockwill be aConvolutionlayer withstride > 1.UpsampleBlockwill be aTransposedConvolutionlayer.AC 2.2: U-Net Model (8 points)
Requirement: Assemble the U-Net from its building blocks.
UNet.csin the same folder.UNet<T>class will not be a traditional model but an architecture definition.Forward(Tensor<T> input, Tensor<T> timestepEmbedding)method:AC 2.3: VAE Model (8 points)
Requirement: Build the Variational Autoencoder to move between pixel and latent space.
src/NeuralNetworks/Architectures/VAE/VAEEncoder<T>:VAEEncoder.cs. Implement a series ofConvolutionlayers that progressively reduce the spatial dimensions of an inputTensor<T>.VAEDecoder<T>:VAEDecoder.cs. Implement a series ofTransposedConvolutionlayers that upsample a latentTensor<T>back to image dimensions.VAE<T>:VAE.cs. It will contain an instance of the encoder and decoder.Encode(Tensor<T> image)method that returns a latent tensor.Decode(Tensor<T> latent)method that returns an image tensor.Phase 3: Latent Diffusion Pipeline
Goal: Combine all the components into a functioning latent diffusion model.
AC 3.1:
LatentDiffusionModel<T>(5 points)Requirement: Create the final pipeline class that orchestrates the full generative process.
src/Models/Generative/Diffusion/LatentDiffusionModel.cs.LatentDiffusionModel<T>must implementIDiffusionModel<T>.UNet<T>, aVAE<T>, and anIStepScheduler<T>.Generatemethod:t=0tonum_inference_steps.UNet'sForwardmethod to predict the noise for the current latent tensor.Stepmethod, passing in the U-Net's output and the current latent tensor, to get the denoised latent tensor for the next step.VAE'sDecodemethod on the final latent tensor.Definition of Done
LatentDiffusionModelis covered by an integration test that ensures all three main components (U-Net, VAE, Scheduler) are called in the correct order.Before implementing this user story, you MUST review:
.github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md.github/PROJECT_RULES.mdMandatory Implementation Checklist
1. INumericOperations Usage (CRITICAL)
protected static readonly INumericOperations<T> NumOps = MathHelper.GetNumericOperations<T>();in base classdouble,float, or specific numeric types - use genericTdefault(T)- useNumOps.ZeroinsteadNumOps.Zero,NumOps.One,NumOps.FromDouble()for valuesNumOps.Add(),NumOps.Multiply(), etc. for arithmeticNumOps.LessThan(),NumOps.GreaterThan(), etc. for comparisons2. Inheritance Pattern (REQUIRED)
I{FeatureName}.csinsrc/Interfaces/(root level, NOT subfolders){FeatureName}Base.csinsrc/{FeatureArea}/inheriting from interface3. PredictionModelBuilder Integration (REQUIRED)
private I{FeatureName}<T>? _{featureName};toPredictionModelBuilder.csBuild()with default:var {featureName} = _{featureName} ?? new Default{FeatureName}<T>();4. Beginner-Friendly Defaults (REQUIRED)
ArgumentExceptionfor invalid values5. Property Initialization (CRITICAL)
default!operator= string.Empty;= new List<T>();or= new Vector<T>(0);NumOps.Zero6. Class Organization (REQUIRED)
src/Interfaces/(root level)src/Regularization/→namespace AiDotNet.Regularization)7. Documentation (REQUIRED)
<b>For Beginners:</b>sections with analogies and examples<param>,<returns>,<exception>tags8. Testing (REQUIRED)
See full details:
.github/USER_STORY_ARCHITECTURAL_REQUIREMENTS.md