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

zero for second residual grad #33

Closed
aijianiula0601 opened this issue Nov 23, 2022 · 1 comment
Closed

zero for second residual grad #33

aijianiula0601 opened this issue Nov 23, 2022 · 1 comment

Comments

@aijianiula0601
Copy link

aijianiula0601 commented Nov 23, 2022

Thanks for you jobs. When we checked the code, we found that there was no gradient for residual layer after second layer, please confirm it.

we change the code to : residual = residual - quantized ---> residual = residual - quantized.detach()

image

Here's the verification we did

    if __name__ == "__main__":
          quantizer = ResidualVQ(
              num_quantizers=4, dim=256, codebook_size=16,
              kmeans_init=True, kmeans_iters=10, threshold_ema_dead_code=2, channel_last=False,
          )
  
          for i in range(4):
              input = torch.rand((2, 256, 30), requires_grad=True)
              quantized, indices, losses = quantizer(input)
              print(quantized.shape, indices.shape, losses.shape)
  
              losses[0, i].backward()
              print(input.grad)
lucidrains added a commit that referenced this issue Nov 23, 2022
@lucidrains
Copy link
Owner

@aijianiula0601 i do believe you are correct! thank you for spotting this! 🙏

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

2 participants