code: def code_to_run(self, input_args):
      input_dims = input_args.get("dims", (2, 3, 8))
      device = (
          torch.device("cuda")
          if (
              input_args.get("device") == "cuda"
              and torch.cuda.is_available()
          )
          else torch.device("cpu:0")
      )
  
      base = torch.ones(*input_dims).to(device)
      gt = torch.tensor(input_args["gt"], requires_grad=False).to(
          device
      )
      g_type = input_args["type"]
      lr = input_args.get("lr", 0.1)
      init_sigma = input_args.get("init", 1.0)
  
      # static filter to generate a target
      spatial_dims = len(base.shape) - 2
      filtering = GaussianFilter(
          spatial_dims=spatial_dims,
          sigma=gt,
          approx=g_type,
          requires_grad=False,
      )
      filtering.to(device)
      target = filtering(base)
      self.assertFalse(filtering.sigma[0].requires_grad)
  
      # build trainable
      init_sigma = torch.tensor(init_sigma).to(device)
      trainable = GaussianFilter(
          spatial_dims=spatial_dims,
          sigma=init_sigma,
          approx=g_type,
          requires_grad=True,
      )
      trainable.to(device)
      self.assertTrue(trainable.sigma[0].requires_grad)
  
      # train
      optimizer = torch.optim.Adam(trainable.parameters(), lr=lr)
      for s in range(1000):
          optimizer.zero_grad()
          pred = trainable(base)
          loss = torch.pow(pred - target, 2).mean()
          loss.backward()
          if (s + 1) % 50 == 0:
              var = list(trainable.parameters())[0]
              print(f"step {s} loss {loss}")
              print(var, var.grad)
          if loss.item() < 1e-7:
              break
          optimizer.step()
      # check the result
      print(s, gt)
      for idx, s in enumerate(trainable.sigma):
          np.testing.assert_allclose(
              s.cpu().item(),
              gt.cpu() if len(gt.shape) == 0 else gt[idx].cpu().item(),
              rtol=1e-2,
          )
  
file_path: MONAI/tests/test_gaussian_filter.py
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from monai.networks.layers import GaussianFilter
  from tests.utils import skip_if_quick
label_desc: Use image node_id 1 for calling the TestGaussianFilterBackprop obj's underlying member method code with example usage: obj.code_to_run(input_args) without return types