code: def sliding_window(
      input: Union[tf.Tensor, tf.Variable],
      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]] = "VALID",
  ) -> Union[tf.Tensor, tf.Variable]:
      if len(input.shape) != 4:
          input = _to_4d(input)
  
      input = tf.transpose(input, (0, 2, 3, 1))
  
      kernel_size = (
          [1]
          + (
              [kernel_size] * 2
              if isinstance(kernel_size, int)
              else list(kernel_size)
          )
          + [1]
      )
      if len(kernel_size) < 4:
          kernel_size.append(1)
  
      stride = (
          [1]
          + ([stride] * 2 if isinstance(stride, int) else list(stride))
          + [1]
      )
      if len(stride) < 4:
          stride.append(1)
  
      dilation = (
          [1]
          + (
              [dilation] * 2
              if isinstance(dilation, int)
              else list(dilation)
          )
          + [1]
      )
      if len(dilation) < 4:
          dilation.append(1)
  
      padding = [padding] * 2 if isinstance(padding, int) else padding
  
      if isinstance(padding, str) and padding.upper() in [
          "VALID",
          "SAME",
      ]:
          padding = padding
  
      elif padding[0] == padding[1] == 0:
          padding = "VALID"
      elif padding[0] == padding[1] != 0:
          padding = "SAME"
      else:
          raise ivy.utils.exceptions.IvyError(
              f"Cannot convert padding sequence {padding} to TensorFlow padding mode"
          )
  
      return tf.image.extract_patches(
          images=input,
          sizes=kernel_size,
          strides=stride,
          rates=dilation,
          padding=padding,
      )
  
imports: import math
  from typing import Union, Optional, Tuple, List, Literal, Sequence, Callable
  import tensorflow
  from ivy.func_wrapper import inputs_to_ivy_arrays, output_to_native_arrays, with_unsupported_dtypes, with_supported_dtypes, with_supported_device_and_dtypes
  from ..None import backend_version
  import ivy
  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, _get_size
label_desc: Use image node_id 49 for calling a global function with example usage: sliding_window() and returns: tf