code: def sliding_window(
      input: torch.Tensor,
      kernel_size: Union[int, Tuple[int, int]],
      /,
      *,
      stride: Union[int, Tuple[int, int]] = 1,
      dilation: Union[int, Tuple[int, int]] = 1,
      padding: Union[str, int, Tuple[int, int]] = 0,
  ) -> torch.Tensor:
      if input.ndim != 4:
          # convert input to 4D tensor as unfold only accepts 4D data
          input_shape = input.shape
          extend_dims = max(0, 4 - len(input_shape))
          new_shape = (1,) * extend_dims + input_shape
          input = input.reshape(new_shape).float()
  
      stride = (
          (stride,) * 2
          if isinstance(stride, int)
          else tuple(stride) * 2
      )
      dilation = (
          (dilation,) * 2
          if isinstance(dilation, int)
          else tuple(dilation) * 2
      )
  
      kernel_size = (
          (kernel_size,) * 2
          if isinstance(kernel_size, int)
          else kernel_size
      )
      if len(kernel_size) < 2:
          kernel_size = (kernel_size) * 2
  
      # check padding and convert to right format
      if isinstance(padding, str):
          # convert padding from str to seq
          if padding.upper() == "SAME":
              pad_vals = []
              for dim in input.shape:
                  pad_val = _handle_padding(
                      dim,
                      stride[0]
                      if isinstance(stride, tuple)
                      else stride,
                      kernel_size[0],
                      padding,
                  )
                  pad_vals.append(pad_val)
              padding = pad_vals[:2]
          else:
              padding = 0
      else:
          padding = (
              (padding,) * 2 if isinstance(padding, int) else padding
          )
  
      return torch.nn.functional.unfold(
          input,
          kernel_size,
          dilation=dilation,
          padding=padding,
          stride=stride,
      )
  
imports: from typing import Optional, Union, Tuple, List, Literal, Sequence, Callable
  import torch
  import math
  import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from .None import backend_version
  from ivy.functional.ivy.layers import _handle_padding, _get_num_padded_values, _validate_max_pool_params, _depth_max_pooling_helper
  from ivy.functional.ivy.experimental.layers import _padding_ceil_mode, _broadcast_pooling_helper
label_desc: Use image node_id 29 for calling a global function with example usage: sliding_window() and returns: torch