(ctx, grad_output)
| 25 | |
| 26 | @staticmethod |
| 27 | def backward(ctx, grad_output): |
| 28 | zq, zi, prob = ctx.saved_tensors |
| 29 | grad_array = -grad_output * (torch.log(prob) + 1) / zi.numel() / ctx.K |
| 30 | reord_grad = grad_array[zi.flatten()].reshape(zi.shape) |
| 31 | grad_input = reord_grad.unsqueeze(-1) * zq |
| 32 | return grad_input, None, None, None, None |
| 33 | |
| 34 | |
| 35 | def codebook_entropy(zq, basis, K, eps=1e-4): |
no outgoing calls
no test coverage detected