A from-scratch implementation of a Flux.1 Pro–style text-to-image generation system built on Diffusion Transformers (DiT) with Flow Matching.
Text Prompt ──► CLIP + T5-XXL Encoders ──► Cross-Attention
│
Noise z_t ──► DiT Blocks (24 layers) ────────┤──► Predicted v(z_t, t)
│
Timestep t ──► Sinusoidal + Adaln ────────────┘
│
▼
VAE Decoder ──► RGB Image (512–1024px)
| Feature | Status |
|---|---|
| Diffusion Transformer (DiT) core | ✅ |
| Flow Matching (ODE-based) | ✅ |
| CLIP + T5-XXL text encoding | ✅ |
| VAE latent compression | ✅ |
| Multi-resolution (512–1024+) | ✅ |
| Classifier-Free Guidance | ✅ |
| Negative prompts | ✅ |
| DDIM / Euler / Euler-A samplers | ✅ |
| Seed reproducibility | ✅ |
| Mixed-precision training | ✅ |
| Gradient checkpointing | ✅ |
| LoRA fine-tuning | ✅ |
| ControlNet conditioning | ✅ |
| Watermarking | ✅ |
| NSFW safety filter | ✅ |
| Gradio UI | ✅ |
| FastAPI endpoint | ✅ |
# Install dependencies
pip install -r requirements.txt
# Generate an image (after training or loading weights)
python generate.py --prompt "a majestic dragon flying over mountains at sunset" \
--steps 28 --guidance 7.5 --seed 42
# Launch Gradio UI
python serve.py --ui gradio --port 7860
# Launch FastAPI
python serve.py --ui api --port 8000
# Start training
python train.py --config config/train_default.yaml
flux-from-scratch/
├── config/ # Model & training configurations
├── models/ # Core neural network modules
│ ├── dit.py # Diffusion Transformer
│ ├── vae.py # Variational Autoencoder
│ ├── text_encoder.py # CLIP + T5-XXL encoders
│ ├── flow_matching.py # Flow Matching scheduler
│ ├── lora.py # LoRA adapters
│ └── controlnet.py # ControlNet conditioning
├── training/ # Training pipeline
│ ├── trainer.py # Main training loop
│ ├── dataset.py # Data loading (LAION-5B)
│ └── losses.py # Loss functions
├── inference/ # Inference pipeline
│ ├── pipeline.py # End-to-end generation
│ ├── samplers.py # ODE/SDE samplers
│ └── safety.py # NSFW + watermarking
├── ui/ # Serving interfaces
│ ├── gradio_app.py # Gradio UI
│ └── api.py # FastAPI REST API
├── utils/ # Shared utilities
├── train.py # Training entry point
├── generate.py # CLI generation
└── serve.py # Server entry point
| Task | Minimum | Recommended |
|---|---|---|
| Inference | 1× RTX 3090 (24 GB) | 1× A100 (80 GB) |
| Training | 8× A100 (80 GB) | 64× H100 (80 GB) |
| Fine-tuning (LoRA) | 1× A100 (40 GB) | 1× A100 (80 GB) |
Apache 2.0
1 commits
Python
63.6%
CSS
12.3%
HTML
12.3%
JavaScript
11.7%
A from-scratch implementation of a Flux.1 Pro–style text-to-image generation system built on Diffusion Transformers (DiT) with Flow Matching.
Text Prompt ──► CLIP + T5-XXL Encoders ──► Cross-Attention
│
Noise z_t ──► DiT Blocks (24 layers) ────────┤──► Predicted v(z_t, t)
│
Timestep t ──► Sinusoidal + Adaln ────────────┘
│
▼
VAE Decoder ──► RGB Image (512–1024px)
| Feature | Status |
|---|---|
| Diffusion Transformer (DiT) core | ✅ |
| Flow Matching (ODE-based) | ✅ |
| CLIP + T5-XXL text encoding | ✅ |
| VAE latent compression | ✅ |
| Multi-resolution (512–1024+) | ✅ |
| Classifier-Free Guidance | ✅ |
| Negative prompts | ✅ |
| DDIM / Euler / Euler-A samplers | ✅ |
| Seed reproducibility | ✅ |
| Mixed-precision training | ✅ |
| Gradient checkpointing | ✅ |
| LoRA fine-tuning | ✅ |
| ControlNet conditioning | ✅ |
| Watermarking | ✅ |
| NSFW safety filter | ✅ |
| Gradio UI | ✅ |
| FastAPI endpoint | ✅ |
# Install dependencies
pip install -r requirements.txt
# Generate an image (after training or loading weights)
python generate.py --prompt "a majestic dragon flying over mountains at sunset" \
--steps 28 --guidance 7.5 --seed 42
# Launch Gradio UI
python serve.py --ui gradio --port 7860
# Launch FastAPI
python serve.py --ui api --port 8000
# Start training
python train.py --config config/train_default.yaml
flux-from-scratch/
├── config/ # Model & training configurations
├── models/ # Core neural network modules
│ ├── dit.py # Diffusion Transformer
│ ├── vae.py # Variational Autoencoder
│ ├── text_encoder.py # CLIP + T5-XXL encoders
│ ├── flow_matching.py # Flow Matching scheduler
│ ├── lora.py # LoRA adapters
│ └── controlnet.py # ControlNet conditioning
├── training/ # Training pipeline
│ ├── trainer.py # Main training loop
│ ├── dataset.py # Data loading (LAION-5B)
│ └── losses.py # Loss functions
├── inference/ # Inference pipeline
│ ├── pipeline.py # End-to-end generation
│ ├── samplers.py # ODE/SDE samplers
│ └── safety.py # NSFW + watermarking
├── ui/ # Serving interfaces
│ ├── gradio_app.py # Gradio UI
│ └── api.py # FastAPI REST API
├── utils/ # Shared utilities
├── train.py # Training entry point
├── generate.py # CLI generation
└── serve.py # Server entry point
| Task | Minimum | Recommended |
|---|---|---|
| Inference | 1× RTX 3090 (24 GB) | 1× A100 (80 GB) |
| Training | 8× A100 (80 GB) | 64× H100 (80 GB) |
| Fine-tuning (LoRA) | 1× A100 (40 GB) | 1× A100 (80 GB) |
Apache 2.0
1 commits
Python
63.6%
CSS
12.3%
HTML
12.3%
JavaScript
11.7%