calculated by:   Copied >>> import torch.nn.functional as F

>>> noise_pred = model(noisy_image, timesteps).sample
>>> loss = F.mse_loss(noise_pred, noise)  Train the model By now, you have most of the pieces to start training the model and all that’s left is putting everything together. First, you’ll need an optimizer and a learning rate scheduler:   Copied >>> from diffusers.optimization import get_cosine_schedule_with_warmup

>>> optimizer =