code: def verify_torch_dlpack():
      a = np.random.randn(1337)
      tvm_a = tvm.nd.array(a)
      np.testing.assert_equal(
          tvm.nd.from_dlpack(tvm_a.to_dlpack()).numpy(), a
      )
  
      try:
          import torch
          import torch.utils.dlpack
  
          x = torch.rand(56, 56)
          tvm_x = tvm.nd.from_dlpack(torch.utils.dlpack.to_dlpack(x))
          np.testing.assert_equal(x.numpy(), tvm_x.numpy())
          y = tvm.nd.from_dlpack(tvm_x)
          np.testing.assert_equal(y.numpy(), tvm_x.numpy())
          np.testing.assert_equal(
              torch.utils.dlpack.from_dlpack(y.to_dlpack()).numpy(),
              tvm_x.numpy(),
          )
  
          n = tvm.runtime.convert(137)
          xx = torch.rand(137, 137)
          yy = torch.rand(137, 137)
          zz2 = torch.empty(137, 137)
          zz = xx.mm(yy)
          XX = te.placeholder((n, n), name="X")
          YY = te.placeholder((n, n), name="Y")
  
          k = te.reduce_axis((0, n), name="k")
          ZZ = te.compute(
              (n, n), lambda i, j: te.sum(XX[i, k] * YY[k, j], axis=k)
          )
          s = te.create_schedule(ZZ.op)
          # No need to speficy target_host if it's llvm
          # Otherwise you will need to specify the target and target_host
          f = tvm.build(s, [XX, YY, ZZ], name="f")
  
          f_pytorch = to_pytorch_func(f)
          zz2 = torch.empty(137, 137)
          f_pytorch(xx, yy, zz2)
          tvm.testing.assert_allclose(
              zz.numpy(), zz2.numpy(), rtol=1e-4, atol=1e-4
          )
  
      except ImportError:
          pass
  
imports: import tvm
  import tvm.testing
  from tvm import te
  import numpy
  from tvm.contrib.dlpack import to_pytorch_func
label_desc: Use image node_id 1 for calling a global function with example usage: verify_torch_dlpack() without return types