code: def _np_pad(
      img: NdarrayTensor,
      pad_width: list[tuple[int, int]],
      mode: str,
      **kwargs,
  ) -> NdarrayTensor:
      if isinstance(img, torch.Tensor):
          if img.is_cuda:
              warnings.warn(
                  f"Padding: moving img {img.shape} from cuda to cpu for dtype={img.dtype} mode={mode}."
              )
          img_np = img.detach().cpu().numpy()
      else:
          img_np = img
      mode = convert_pad_mode(dst=img_np, mode=mode).value
      if mode == "constant" and "value" in kwargs:
          kwargs["constant_values"] = kwargs.pop("value")
      img_np = np.pad(img_np, pad_width, mode=mode, **kwargs)  # type: ignore
      return convert_to_dst_type(img_np, dst=img)[0]
  
file_path: MONAI/monai/transforms/croppad/functional.py
imports: from __future__ import annotations
  import warnings
  import numpy
  import torch
  from torch.nn.functional import pad
  from monai.config.type_definitions import NdarrayTensor
  from monai.data.meta_obj import get_track_meta
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import to_affine_nd
  from monai.transforms.inverse import TraceableTransform
  from monai.transforms.utils import convert_pad_mode, create_translate
  from monai.utils import PytorchPadMode, convert_to_dst_type, convert_to_numpy, convert_to_tensor, ensure_tuple
label_desc: Use image node_id 2 for calling a global function with example usage: _np_pad(img, pad_width, mode) and returns: convert_to_dst_type