code: def pad(
      img: Tensor,
      padding: Union[int, List[int]],
      fill: Optional[Union[int, float]] = 0,
      padding_mode: str = "constant",
  ) -> Tensor:
      _assert_image_tensor(img)
  
      if fill is None:
          fill = 0
  
      if not isinstance(padding, (int, tuple, list)):
          raise TypeError("Got inappropriate padding arg")
      if not isinstance(fill, (int, float)):
          raise TypeError("Got inappropriate fill arg")
      if not isinstance(padding_mode, str):
          raise TypeError("Got inappropriate padding_mode arg")
  
      if isinstance(padding, tuple):
          padding = list(padding)
  
      if isinstance(padding, list):
          # TODO: Jit is failing on loading this op when scripted and saved
          # https://github.com/pytorch/pytorch/issues/81100
          if len(padding) not in [1, 2, 4]:
              raise ValueError(
                  f"Padding must be an int or a 1, 2, or 4 element tuple, not a {len(padding)} element tuple"
              )
  
      if padding_mode not in [
          "constant",
          "edge",
          "reflect",
          "symmetric",
      ]:
          raise ValueError(
              "Padding mode should be either constant, edge, reflect or symmetric"
          )
  
      p = _parse_pad_padding(padding)
  
      if padding_mode == "edge":
          # remap padding_mode str
          padding_mode = "replicate"
      elif padding_mode == "symmetric":
          # route to another implementation
          return _pad_symmetric(img, p)
  
      need_squeeze = False
      if img.ndim < 4:
          img = img.unsqueeze(dim=0)
          need_squeeze = True
  
      out_dtype = img.dtype
      need_cast = False
      if (padding_mode != "constant") and img.dtype not in (
          torch.float32,
          torch.float64,
      ):
          # Here we temporarily cast input tensor to float
          # until pytorch issue is resolved :
          # https://github.com/pytorch/pytorch/issues/40763
          need_cast = True
          img = img.to(torch.float32)
  
      if padding_mode in ("reflect", "replicate"):
          img = torch_pad(img, p, mode=padding_mode)
      else:
          img = torch_pad(img, p, mode=padding_mode, value=float(fill))
  
      if need_squeeze:
          img = img.squeeze(dim=0)
  
      if need_cast:
          img = img.to(out_dtype)
  
      return img
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn.functional import conv2d, grid_sample, interpolate, pad
label_desc: Use image node_id 23 for calling a global function with example usage: pad(img, padding, fill, padding_mode) and returns: img, _pad_symmetric