I am trying to train a diffusion model (from scratch in pytorch). UNet used is not anything too fancy, takes in images and time step as input for about 512 time steps. I am using learnable embeddings for 512 time steps. This works just fine for mnist but when moving to another dataset (my dataset is of motorbikes) it produces nothing meaningful even after 20k steps (batchsize 32). This is what i get after 20k steps on it.
Some experiments i tried somewhat contradict each other and i cant think of why this is happening.
Experiment:
- overfit a small batch of my dataset. Result: model produces something intangible like the above picture
- Have a dataset of about 10k images. Produces something like a bike if you really look for it. Trained this for ~28k steps (batchsize 32).
- model works fine for mnist and cifar (even after running it for a short while).
- Noticed there was noisy data which has nothing to do with bikes, so i manually got rid of them hoping my model would perform better. (reduced my dataset of 10k images to ~6.5k clean, quality images). Result: No changes, produces intangible images (just like first one) after training for ~55k steps (batchsize 32). This surprises me because i was expecting it to atleast be like the images produced from the noisy dataset.
I have not changed model hyperparameters when performing these experiments:
- lr = 4e-4 with Adam
- batch_size = 32 (for bikes)
- Normalised images from [-1,1]
- img_size = (3, 128, 128) # c, h, w
- timesteps = 512
- betas scheduler from 10e-4 to 0.02 (just like in the original paper)
- using a cosine scheduler (this works a bit better than using a linear one)
I tried using self attention but that performs worse (not sure if its "worse" because it produces noise even after 12.5k steps on mnist (batchsize of 64).
I could not find a practical guide on training diffusion models, however from the information i gathered, the takeaway is that you have to train these forever and wont really work well if you run it for few hours on a mediocre gpu. I see that some of the sota diffusion models were trained on a few thousand days worth of gpu compute. Is my assumption correct ?
I am still not clear on why overfitting on a batch does not work here or why the clean dataset does not produce anything tangible. How do i know if my model is ever learning ? when do i know i should stop ?