INNER CODE UNIT · Python
indices
lucidrains/vector-quantize-pytorch · vector_quantize_pytorch/binary_mapper.py:157
indices = (self.power_two * sampled_bits).sum(dim = -1)
one_hot = F.one_hot(indices, self.num_codes).float()
# maybe calculate aux loss
aux_kl_loss = self.zero
if calc_aux_loss:
aux_kl_loss = self.calc_aux_loss(orig_logits, reduce_aux_kl_loss = reduce_aux_kl_loss)
# maybe straight through
if straight_through:
# get the soft G for the gradients and do a straight through
soft_G = (
einsum(F.logsigmoid(logits), self.codes.float(), '... bits, codes bits -> ... codes') +