MAR + Softvqvae Implementation
Thansk for your great work! It would be very grateful if you could share the specific implementation code for achieving MAR using softvqvae. If you don't have the specific code at the moment, I am particularly interested in learning about the process of handling the latent features after vae.encde(imgs). The MAR defaulted implementation is : 【 with torch.no_grad(): if args.use_cached: moments = samples posterior = DiagonalGaussianDistribution(moments) else: posterior = vae.encode(samples)
# normalize the std of latent to be 1. Change it if you use a different tokenizer
x = posterior.sample().mul_(0.2325)
】
Your Softvqvae defaulted implementation is : 【 with torch.cuda.amp.autocast(dtype=ptdtype):
x = (x - vae_mean) / vae_std
】 Besides, I alse noticed the vae_mean and vae_std are not the same in different models, like ("vq_mean": 0.0009714666,"vq_std": 0.07259091) in softvq-l-64 but ( "vq_mean": -0.003192751,"vq_std": 0.07235257) in softvq-b-64。 Could you please inform the right implementation here?
This is a normalization technique to make sure that the latent vectors to the diffusion has 0 mean (not necessary) and 1 std (necessary) at their channel dimensions for diffusion models.
For MAR, it only normalized by std. the multiplier in your code snippet is equivalent to 1 / std. For SoftVQ and MAETok, we normalize by both mean and std.
The mean and std are usually pre-computed by running the encoder through partial training data or validation data.
Hope this helps. I will try to update the MAR training code soon.
This is a normalization technique to make sure that the latent vectors to the diffusion has 0 mean (not necessary) and 1 std (necessary) at their channel dimensions for diffusion models.
For MAR, it only normalized by std. the multiplier in your code snippet is equivalent to 1 / std. For SoftVQ and MAETok, we normalize by both mean and std.
The mean and std are usually pre-computed by running the encoder through partial training data or validation data.
Hope this helps. I will try to update the MAR training code soon.
Thank you for your reply.!Now I have resolved this problem!However, when I was reproducing the relevant experiments, I encountered a new problem. I fine-tuned a model with softvqvae-l and then trained the generator using the mar framework. When my model reached around 100 epochs, the loss suddenly became None. I checked the grad_norm and the data, and they seemed fine. You mentioned in the paper that this issue occurs when the loss is set too high, so your experiment used lr=2e-4, while I used lr=3.2e-4. The paper mentioned attempts to solve this problem. I wonder if you have any ideas on how to solve it now.
This is a normalization technique to make sure that the latent vectors to the diffusion has 0 mean (not necessary) and 1 std (necessary) at their channel dimensions for diffusion models. For MAR, it only normalized by std. the multiplier in your code snippet is equivalent to 1 / std. For SoftVQ and MAETok, we normalize by both mean and std. The mean and std are usually pre-computed by running the encoder through partial training data or validation data. Hope this helps. I will try to update the MAR training code soon.
Thank you for your reply.!Now I have resolved this problem!However, when I was reproducing the relevant experiments, I encountered a new problem. I fine-tuned a model with softvqvae-l and then trained the generator using the mar framework. When my model reached around 100 epochs, the loss suddenly became None. I checked the grad_norm and the data, and they seemed fine. You mentioned in the paper that this issue occurs when the loss is set too high, so your experiment used lr=2e-4, while I used lr=3.2e-4. The paper mentioned attempts to solve this problem. I wonder if you have any ideas on how to solve it now.
MAR does has the loss nan issue, I encountered it before too. One suggestions it to use bf16 instead of fp16 for mixed precision training. If bg16 still has the nan issue, you can try to decrease the batch size and learning rate.