class_docstr: Vector quantization using gumbel softmax. Copied from fairseq implementation.
  Arguments
  ---------
      input_dim: int
          Input dimension (channels).
      num_vars: int
          Number of quantized vectors per group.
      temp_tuple: float
          Temperature for training. this should be a tuple of 3 elements: (start, stop, decay factor).
      groups: int
          Number of groups for vector quantization.
      vq_dim: int
          Dimensionality of the resulting quantized vector.
  
  Example
  -------
  >>> quantiser = GumbelVectorQuantizer(128, 100, (2.0, 0.25, 0.999995,), 2, 50 )
  >>> inputs = torch.rand(10, 12, 128)
  >>> output = quantiser(inputs)
  >>> output["x"].shape
  torch.Size([10, 12, 50])
docstr: Forward the latent vector to obtain a quantised output 
docstr_tok: ["Forward","the","latent","vector","to","obtain","a","quantised","output"]
code: def forward(self, x):
      """Forward the latent vector to obtain a quantised output"""
  
      result = {
          "num_vars": self.num_vars * self.groups,
          "temp": self.curr_temp,
      }
  
      bsz, tsz, fsz = x.shape
      x = x.reshape(-1, fsz)
      x = self.weight_proj(x)
      x = x.view(bsz * tsz * self.groups, -1)
  
      _, k = x.max(-1)
      hard_x = (
          x.new_zeros(*x.shape)
          .scatter_(-1, k.view(-1, 1), 1.0)
          .view(bsz * tsz, self.groups, -1)
      )
      hard_probs = torch.mean(hard_x.float(), dim=0)
      result["code_perplexity"] = torch.exp(
          -torch.sum(hard_probs * torch.log(hard_probs + 1e-7), dim=-1)
      ).sum()
  
      avg_probs = torch.softmax(
          x.view(bsz * tsz, self.groups, -1).float(), dim=-1
      ).mean(dim=0)
      result["prob_perplex"] = torch.exp(
          -torch.sum(avg_probs * torch.log(avg_probs + 1e-7), dim=-1)
      ).sum()
  
      result["temp"] = self.curr_temp
  
      if self.training:
          x = F.gumbel_softmax(
              x.float(), tau=self.curr_temp, hard=True
          ).type_as(x)
      else:
          x = hard_x
  
      x = x.view(bsz * tsz, -1)
  
      vars = self.vars
      x = x.unsqueeze(-1) * vars
      x = x.view(bsz * tsz, self.groups, self.num_vars, -1)
      x = x.sum(-2)
      x = x.view(bsz, tsz, -1)
      result["x"] = x
      return result
  
imports: import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 3 for calling the GumbelVectorQuantizer obj's underlying member method code with example usage: obj.forward(x) and returns: result