code: def max_pool2d(
      x: torch.Tensor,
      kernel: Union[int, Tuple[int, ...]],
      strides: Union[int, Tuple[int, ...]],
      padding: Union[str, int, Tuple[int], List[Tuple[int, int]]],
      /,
      *,
      data_format: str = "NHWC",
      dilation: Union[int, Tuple[int, ...]] = 1,
      ceil_mode: bool = False,
      out: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      dims = 2
      kernel, strides, padding, dilation = _validate_max_pool_params(
          kernel,
          strides,
          padding,
          dilation,
          ceil_mode,
          dims,
          data_format,
      )
  
      if data_format == "NHWC":
          x = x.permute(0, 3, 1, 2)
          kernel = (
              [kernel[i] for i in [0, 3, 1, 2]]
              if len(kernel) == (dims + 2)
              else kernel
          )
          strides = (
              [strides[i] for i in [0, 3, 1, 2]]
              if len(strides) == (dims + 2)
              else strides
          )
  
      # determine depth pooling
      x, kernel, strides, depth_pooling = _determine_depth_max_pooling(
          x, kernel, strides, dims, data_format="channel_first"
      )
  
      if isinstance(padding, str):
          x_shape = list(x.shape[2:])
          new_kernel = [
              kernel[i] + (kernel[i] - 1) * (dilation[i] - 1)
              for i in range(2)
          ]
          pad_h = _handle_padding(
              x_shape[0], strides[0], new_kernel[0], padding
          )
          pad_w = _handle_padding(
              x_shape[1], strides[1], new_kernel[1], padding
          )
          pad_list = [
              pad_w // 2,
              pad_w - pad_w // 2,
              pad_h // 2,
              pad_h - pad_h // 2,
          ]
      else:
          if (
              any(item != 0 for sublist in padding for item in sublist)
              and depth_pooling
          ):
              raise NotImplementedError(
                  "Nonzero explicit padding is not supported for depthwise max pooling"
              )
          pad_list = [
              item for sublist in padding[::-1] for item in sublist
          ]
  
      if all(
          pad_list[i] == pad_list[i + 1] for i in range(0, 2 * dims, 2)
      ) and all(
          pad <= kernel_size / 2
          for pad, kernel_size in zip(pad_list[::-2], kernel)
      ):
          res = torch.nn.functional.max_pool2d(
              x, kernel, strides, pad_list[::-2], dilation, ceil_mode
          )
      else:
          x = torch.nn.functional.pad(
              x,
              pad_list,
              value=float("-inf"),
          )
          res = torch.nn.functional.max_pool2d(
              x, kernel, strides, 0, dilation, ceil_mode
          )
  
      if depth_pooling:
          res = torch.permute(res, (0, 2, 1, 3))
      if data_format == "NHWC":
          return res.permute(0, 2, 3, 1)
      return res
  
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 3 for calling a global function with example usage: max_pool2d() and returns: res, res