code: def grad_total_variation(
      self, weight=1e-7, inputs=None, bound=1, B=1000000
  ):
      # inputs: [..., input_dim], float in [-b, b], location to calculate TV loss.
  
      D = self.input_dim
      C = self.embeddings.shape[1]  # embedding dim for each level
      L = self.offsets.shape[0] - 1  # level
      S = np.log2(
          self.per_level_scale
      )  # resolution multiplier at each level, apply log2 for later CUDA exp2f
      H = self.base_resolution  # base resolution
  
      if inputs is None:
          # randomized in [0, 1]
          inputs = torch.rand(
              B, self.input_dim, device=self.embeddings.device
          )
      else:
          inputs = (inputs + bound) / (2 * bound)  # map to [0, 1]
          inputs = inputs.view(-1, self.input_dim)
          B = inputs.shape[0]
  
      if self.embeddings.grad is None:
          raise ValueError(
              "grad is None, should be called after loss.backward() and before optimizer.step()!"
          )
  
      _backend.grad_total_variation(
          inputs,
          self.embeddings,
          self.embeddings.grad,
          self.offsets,
          weight,
          B,
          D,
          C,
          L,
          S,
          H,
          self.gridtype_id,
          self.align_corners,
      )
  
file_path: NeMo/nemo/collections/multimodal/modules/nerf/utils/torch_ngp/gridencoder.py
imports: import math
  import _gridencoder
  import numpy
  import torch
  import torch.nn
  from torch.autograd import Function
  from torch.cuda.amp import custom_bwd, custom_fwd
label_desc: Use image node_id 5 for calling the GridEncoder obj's underlying member method code with example usage: obj.grad_total_variation(weight, inputs, bound, B) without return types