Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples Codebook Utilization does not generalize #109

Open
AmitMY opened this issue Feb 25, 2024 · 0 comments
Open

Examples Codebook Utilization does not generalize #109

AmitMY opened this issue Feb 25, 2024 · 0 comments

Comments

@AmitMY
Copy link

AmitMY commented Feb 25, 2024

In the examples, you report f"active %: {indices.unique().numel() / num_codes * 100:.3f}", for example:
https://github.com/lucidrains/vector-quantize-pytorch/blob/master/examples/autoencoder_fsq.py#L76

But this does not generalize when the num_codebooks parameters is set to 2 or more.
I think if the utilization of codebook 1 is 97% and codebook 2 is 93%, this should report (97+93)/2 = 95%, for example

Possible, ugly solution (for a single item, not a batch)

    def get_codebook_util(self, indices: Tensor):
        codebooks = [indices[:, :, i] for i in range(self.model.num_codebooks)]
        uniques = [codebook.unique().numel() for codebook in codebooks]
        mean_unique = torch.tensor(uniques, dtype=torch.float).mean()
        return mean_unique / num_codes * 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant