code: def forward(self, img):
      img = self.norm(img)
      logits = self.encoder(img).permute(
          (0, 2, 3, 1) if len(img.shape) == 4 else (0, 2, 1)
      )
      sampled, codes, commitment_loss = self.codebook(logits)
      sampled = sampled.permute(
          (0, 3, 1, 2) if len(img.shape) == 4 else (0, 2, 1)
      )
  
      if self.training:
          out = sampled
          for d in self.decoder:
              out = d(out)
          self.log_codes(codes)
      else:
          # This is non-differentiable, but gives a better idea of how the network is actually performing.
          out, _ = self.decode(codes)
  
      # reconstruction loss
      recon_loss = self.loss_fn(img, out, reduction="none")
  
      return recon_loss, commitment_loss, out
  
imports: import functools
  from math import sqrt
  import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
  import torchaudio
  from einops import rearrange
label_desc: Use image node_id 7 for calling the DiscreteVAE obj's underlying member method code with example usage: obj.forward(img) and returns: recon_loss,  commitment_loss,  out