A C-based implementation of a Stable Diffusion model, inspired by llm.c.
diffusion.c is a project to implement a Stable Diffusion model entirely in C/CUDA. Our goal is to create a lightweight, efficient, and highly controllable version of Stable Diffusion, for training and inference, which can run without the overhead of large machine learning frameworks.
- Define Tensor structure
- Implement basic Tensor operations (creation, destruction, indexing)
- Define UNetConfig and UNet2DConditionModel structures
- Implement creation and destruction functions
- Implement conv2d function
- Implement normalization layers (GroupNorm and LayerNorm)
- Implement activation function (SiLU)
- Implement tensor_concat function (current implementation not working)
- Implement attention mechanism
- Implement down blocks
- Implement up blocks
- Implement mid block
- Connect all components (conv2d, normalization, attention, etc.)
- Implement time embedding
- Implement cross-attention with condition
- Implement gradient calculation for all operations
- Implement optimizer (e.g., AdamW)
- Implement forward diffusion (noise addition)
- Implement reverse diffusion (denoising)
- Implement basic tests for tensor operations
- Implement tests for normalization and activation functions
- Implement tests for UNet blocks
- Fix and complete test for tensor_concat
- Implement test for attention mechanism
- Implement integration tests for full model
- Implement comparison with PyTorch reference implementation
$ cd src/
$ make
$ ./unet_test
This is AnswerAI hack by Nate Cooper, Alexis Gallagher, with special moral support provided Sanyam Bhutani!