Replies: 5 comments
-
Hi @jacobgorm , _dims = tuple(range(per_sample_probs.dim() - 2))
avg_prob = per_samples_probs.mean(dim=_dims) This snippet should do the trick, even if it is not beautiful :) |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! However, I am also having trouble converting the distance calculation etc. Is it equivalent to this formula:
Used in older versions of this repo? |
Beta Was this translation helpful? Give feedback.
-
If you are talking about this line for the computation of the loss, Regardless, I think the formula you wrote looks good, except it should be the transpose of the codebook here. Play with toy examples of different shapes, and you will find if it works or not! |
Beta Was this translation helpful? Give feedback.
-
Here is how far I got:
notice that I had to use F.relu() to prevent occasional negative entropy loss values, not sure if that is a sign that something is not right. |
Beta Was this translation helpful? Give feedback.
-
This looks good! The non positivity of the loss is not an issue, it is expected for the loss to sometimes be negative, due to the difference between two terms. |
Beta Was this translation helpful? Give feedback.
-
hi,
I am trying to use LFQ for an existing codebase that has traditionally not used Einops for anything. I am using the Lucidrains LFQ code as a starting point, but am starting from scratch because find that it has too many knobs that makes the code too hard to reason about. Also, I frankly don't understand Einops well enough to get the Entropy loss working in my implementation, and I don't like adding too many external dependencies outside of pytorch, or use copy-pasted code that I don't completely understand or will be able to read half a year from now, so I was wondering if anyone would be able to help me write a super-simple LFQ without any Einops.
I've noticed that pytorch already has the Categorical distribution https://pytorch.org/docs/stable/distributions.html that appears to allow me to calculate the entropy, and the mean should be easy, so I am just looking for code that will get a typical image tensor (b,c,h,w) into the right shape for reproducing the entropy loss as per the Magvit-2 paper.
Here is the code that I currently have:
Any help would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions