code: def test_grid_sample(executor_kind):
      def verify_grid_sample(
          data_shape,
          grid_shape,
          method="bilinear",
          padding_mode="zeros",
          align_corners=True,
      ):
          dtype = "float32"
          data = relay.var(
              "data", relay.ty.TensorType(data_shape, dtype)
          )
          grid = relay.var(
              "grid", relay.ty.TensorType(grid_shape, dtype)
          )
  
          if len(data_shape) == 4:
              layout = "NCHW"
              batch, channel, _, _ = data_shape
              _, _, out_height, out_width = grid_shape
              tensor_type = relay.TensorType(
                  (batch, channel, out_height, out_width), dtype
              )
          else:  # len(data_shape) == 5:
              layout = "NCDHW"
              batch, channel, _, _, _ = data_shape
              _, _, out_depth, out_height, out_width = grid_shape
              tensor_type = relay.TensorType(
                  (batch, channel, out_depth, out_height, out_width),
                  dtype,
              )
  
          y = relay.image.grid_sample(
              data,
              grid,
              method=method,
              layout=layout,
              padding_mode=padding_mode,
              align_corners=align_corners,
          )
          yy = run_infer_type(y)
          assert yy.checked_type == tensor_type
          func = relay.Function([data, grid], y)
  
          data_np = np.random.uniform(size=data_shape).astype(dtype)
          grid_np = np.random.uniform(
              size=grid_shape, low=-1.5, high=1.5
          ).astype(dtype)
          ref_res = tvm.topi.testing.grid_sample_python(
              data_np,
              grid_np,
              method,
              layout,
              padding_mode,
              align_corners,
          )
  
          for target, dev in tvm.testing.enabled_targets():
              op_res = relay.create_executor(
                  executor_kind, device=dev, target=target
              ).evaluate(func)(data_np, grid_np)
              tvm.testing.assert_allclose(
                  op_res.numpy(), ref_res, rtol=1e-5, atol=1e-5
              )
  
      methods = ["nearest", "bilinear", "bicubic"]
      padding_modes = ["zeros", "border", "reflection"]
      align_corners = [True, False]
  
      data_2D_shape = (4, 4, 8, 8)
      grid_2D_shape = (4, 2, 16, 16)
      # choosing smaller sizes to be testable on weaker GPUs
      data_3D_shape = (4, 4, 4, 4, 4)
      grid_3D_shape = (4, 3, 8, 8, 8)
  
      for _method in methods:
          for _padding in padding_modes:
              for _align in align_corners:
                  verify_grid_sample(
                      data_2D_shape,
                      grid_2D_shape,
                      _method,
                      _padding,
                      _align,
                  )
  
                  # 3D "bicubic"(tricubic) is not supported in pytorch
                  if _method != "bicubic":
                      verify_grid_sample(
                          data_3D_shape,
                          grid_3D_shape,
                          _method,
                          _padding,
                          _align,
                      )
  
imports: import math
  import platform
  import sys
  import numpy
  import pytest
  import tvm
  import tvm.testing
  import tvm.topi.testing
  from tvm import relay, te
  from tvm.relay.testing import run_infer_type
label_desc: Use image node_id 17 for calling a global function with example usage: test_grid_sample(executor_kind) without return types