ruwwww commited on
Commit
42f4abe
·
verified ·
1 Parent(s): 1205244

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +98 -0
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ pipeline_tag: unconditional-image-generation
4
+ tags:
5
+ - diffusion
6
+ - rectified-flow
7
+ - patch-diffusion
8
+ - anime
9
+ ---
10
+ # Waifu Diffusion
11
+
12
+ A 130M-parameter diffusion model trained on 10,000 anime faces (90% monochrome) using **rectified flow**, **patch diffusion**, and **CIELAB color space decoupling**.
13
+
14
+ ## Model Details
15
+
16
+ - **Architecture**: Diffusion Transformer (DiT-B) with Vision RoPE
17
+ - **Parameters**: 130M
18
+ - **Training Data**: 10k anime faces (80×80), 90% corrupted to grayscale
19
+ - **Training Steps**: 1280 epochs × batch 256
20
+ - **Sampling**: 50-step Euler integration
21
+
22
+ ### Versions
23
+
24
+ | Model | Details |
25
+ |-------|---------|
26
+ | `waifu_diffusion_1280_bs256.safetensors` | Full training (1280 epochs, bs=256) |
27
+ | `waifu_diffusion_128_bs32.safetensors` | Shallow trained version (128 epochs, bs=32) |
28
+
29
+ ## Quick Start
30
+
31
+ ```python
32
+ import torch
33
+ from safetensors.torch import load_file
34
+ from skimage import color
35
+ import numpy as np
36
+
37
+ # Load model
38
+ model = JiT(
39
+ input_size=80,
40
+ patch_size=4,
41
+ in_channels=3,
42
+ hidden_size=768,
43
+ depth=12,
44
+ num_heads=12,
45
+ num_classes=1
46
+ )
47
+ state_dict = load_file("waifu_diffusion_1280_bs256.safetensors")
48
+ model.load_state_dict(state_dict)
49
+ model.eval()
50
+
51
+ # Generate
52
+ device = "cuda"
53
+ model.to(device)
54
+
55
+ with torch.no_grad():
56
+ xt = torch.randn((1, 3, 80, 80), device=device)
57
+ y = torch.zeros(1, dtype=torch.long, device=device)
58
+
59
+ for step in range(50):
60
+ t = torch.tensor(step / 50, device=device)
61
+ pred_x1 = model(xt, t, y, top_idx=0, left_idx=0)
62
+ v = (pred_x1 - xt) / max(1.0 - step / 50, 1e-2)
63
+ xt = xt + v / 50
64
+
65
+ # Convert CIELAB → RGB
66
+ lab = torch.clamp(pred_x1[0], -1, 1).cpu().numpy()
67
+ L = (lab[0] + 1) * 50
68
+ a = lab[1] * 128
69
+ b = lab[2] * 128
70
+ rgb = color.lab2rgb(np.stack([L, a, b], axis=-1))
71
+ ```
72
+
73
+ ## Key Techniques
74
+
75
+ - **Rectified Flow**: Straight-line paths from noise to data (50 steps vs. 1000s for DDPM)
76
+ - **CIELAB Decoupling**: Separate luminance from color; mask gradients on monochrome → learn structure from all 10k, color from 1k
77
+ - **Patch Diffusion**: Random 40×80 px crops act as data augmentation; effectively 10k → ~50k samples
78
+ - **Vision RoPE**: 2D rotary embeddings for spatial consistency across patches
79
+
80
+ ## Links
81
+
82
+ - **GitHub**: https://github.com/ruwwww/waifu_diffusion
83
+ - **Blog Post**: [Training a Waifu Diffusion Model](https://ruwwww.github.io/al-folio/blog/2026/waifu-diffusion/)
84
+
85
+ ## Citation
86
+
87
+ ```bibtex
88
+ @misc{waifu_diffusion_2026,
89
+ author = {Abdurrahman Izzuddin Al Faruq},
90
+ title = {Training a Waifu Diffusion Model with Patch Diffusion and Rectified Flow},
91
+ year = {2026},
92
+ url = {https://github.com/ruwwww/waifu_diffusion}
93
+ }
94
+ ```
95
+
96
+ ## License
97
+
98
+ MIT