r/MachineLearning
•
u/IvanMikhnenkov
•
Sep 11 '26
•
1
Project Training a 210M text-to-image DiT from scratch on one GPU: what I measured [P]
I trained a 210M-parameter text-to-image diffusion transformer from scratch (3.5 days, one RTX PRO 6000, 4.2M images at 256²) mainly to understand the recipe end to end. Three measurements came out of it that I have not seen stated plainly elsewhere, so I'm posting those rather than the samples.
1. Learned null attention slots become the sink. Following the register-token idea, the model has 16 register tokens in the image stream plus 2 learned key/value slots appended to every cross-attention. At mid-noise in a middle block, those 2 slots receive ~90% of the cross-attention mass; the EOS token, which is the usual sink in cross-attention models, drops to ~4%; content words keep a few percent each, sharply on their objects. Register vectors grow to 4–13× the norm of image tokens by the middle blocks.
2. The flow-matching loss is a health signal, not a quality signal. It moved 0.805 → 0.754 over the whole run while held-out FID went 33.7 → 27.0, FD-DINOv2 570 → 218 and detector-based object accuracy 65% → 90%. Most of the loss at high noise is the irreducible variance of the velocity target; training and held-out loss stayed equal to the third decimal for 24 epochs.
3. The training-time timestep shift is worth more than doubling the steps. On 2,456 held-out prompts with the final weights: 20 steps with shift 2.8 → FID 27.0; 50 steps → 26.6; 8 steps → 28.4; 20 steps with no shift → 27.3 and FD-DINOv2 218 → 228. Shift 2.8 comes from the SD3/RAE rule √(32·32·32/4096) for the 32-channel FLUX.2 latent.
Setup, briefly: cross-attention DiT (896 × 16 blocks), 2D RoPE, QK-norm, SwiGLU, adaLN-single; rectified flow with logit-normal timesteps and the shift above; cosine velocity and dispersive auxiliary losses; five aspect-ratio buckets of ~256 tokens from step one; flan-t5-base frozen, long/short caption per image sampled 50/40/10 (empty). Data: Pexels 2.8M (60%), a quality-filtered 1.2M slice of FLUX-Reason-6M (25%), COCO with GPT-4V captions (15%). batch 256, 400k steps, EMA 0.9999, linear LR decay over the last quarter, torch.compile (2.4× over eager).
Everything, with the sources for each decision: https://github.com/ivanmikhnenkov/tinydit
Write-up: https://huggingface.co/blog/ivanmikhnenkov/tinydit-text-to-image-from-scratch-one-gpu
Weights: https://huggingface.co/ivanmikhnenkov/tinydit-256
Demo: https://huggingface.co/spaces/ivanmikhnenkov/tinydit
For the next phase (Flow-GRPO on this base), which reward would you start with: PickScore/HPSv2, a detector-based object reward, or something verifiable like counting?


15
u/ahf95 Sep 11 '26
Wow, your write-up was awesome! Thank you for that. Legit, the stuff about timestep choices and latent dims are directly relevant to my research. I hope to see more posts like this in the future :)
8
u/Saetlan Sep 11 '26
Kind of things I'd like to do but never motivated enough when working alone 😅 Thanks for the write-up! I'm currently gathering all tricks and tips I find in every paper/blogs I see so I can know what are all options for each part of the process.
The goal would be to have chapters for each "concepts" (positional encoding, attention, ...) which would describe pro/cons. For example Attention
I'm wondering how you organize your knowledge? There is so much being released nowadays I wanted to work on a knowledge base to organize all concepts and would summarize them for me to be able to quickly understand them when I need them. Because I don't find the time to dive in all papers.
3
u/IvanMikhnenkov Sep 11 '26
If you found the HF article useful, an upvote there would be much appreciated: https://huggingface.co/blog/ivanmikhnenkov/tinydit-text-to-image-from-scratch-one-gpu
2
u/FractalNerve Sep 11 '26
congrats, this is too good for reddit! Thanks for the release and writeup
What other communities exist for scientists? On X/Bsky there's too many bots and similar silence and concentration of eyes on very few profiles. Amplified Gauss Curve
2
u/pm_me_your_pay_slips ML Engineer Sep 14 '26 edited Sep 14 '26
One useful trick is that after training for a while, you can improve the model by changing some hyper parameters: dropping the learning rate, shifting the logsnr schedule, tweaking the training dataset mixture. Having varied held out evaluation sets (for short/medium/long text accuracy, tiny text accuracy, human anatomy, anime style, posters, common sense, physics) can help a lot in debugging.
Edit: another thing you can do is to fine tune on a high quality and high resolution subset to make the model better at finer details. You may not need much training to make you 256p model be able to generate 1024p images. The 256p pretraining regime would mostly be to make the model have better and more extensive world knowledge.
1
u/Fit_Maintenance_2455 Sep 12 '26
added here: https://github.com/andysingal/CV_public/tree/main/DiT