code: def avg_pool2d(
      x: torch.Tensor,
      kernel: Union[int, Tuple[int], Tuple[int, int]],
      strides: Union[int, Tuple[int], Tuple[int, int]],
      padding: Union[str, int, List[Tuple[int, int]]],
      /,
      *,
      data_format: str = "NHWC",
      count_include_pad: bool = False,
      ceil_mode: bool = False,
      divisor_override: Optional[int] = None,
      out: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      if isinstance(strides, int):
          strides = (strides, strides)
      elif len(strides) == 1:
          strides = (strides[0], strides[0])
  
      if isinstance(kernel, int):
          kernel = (kernel, kernel)
      elif len(strides) == 1:
          kernel = (kernel[0], kernel[0])
  
      if data_format == "NHWC":
          x = x.permute(0, 3, 1, 2)
  
      if (
          isinstance(padding, int)
          or not isinstance(padding, str)
          and all(pad[0] == pad[1] for pad in padding)
      ):
          if not isinstance(padding, int):
              padding = [padding[0][0], padding[1][0]]
          res = torch.nn.functional.avg_pool2d(
              x,
              kernel,
              strides,
              padding,
              count_include_pad=count_include_pad,
              ceil_mode=ceil_mode,
              divisor_override=divisor_override,
          )
      else:
          x_shape = list(x.shape[2:])
          padding, pad_specific = _get_specific_pad(
              x_shape, kernel, strides, padding, 2
          )
          x = torch.nn.functional.pad(
              x,
              padding,
              value=0.0,
          )
          res = torch.nn.functional.avg_pool2d(
              x,
              kernel,
              strides,
              0,
              ceil_mode,
              divisor_override=divisor_override,
          )
  
          if (
              not count_include_pad
              and any(pad_specific)
              and not divisor_override
          ):
              num_padded_values = [
                  ivy.map(
                      _get_num_padded_values,
                      constant={
                          "p": pad_specific[i],
                          "n": x_shape[i],
                          "k": kernel[i],
                          "s": strides[i],
                      },
                      unique={
                          "i": torch.arange(res.shape[i + 2]),
                      },
                  )
                  for i in range(2)
              ]
              if ceil_mode:
                  for i in range(2):
                      num_padded_values = (
                          _adjust_num_padded_values_to_ceil(
                              pad_specific,
                              num_padded_values,
                              x_shape,
                              kernel,
                              strides,
                              2,
                          )
                      )
              num_padded_values1 = torch.tensor(
                  num_padded_values[0], dtype=res.dtype
              )[:, None]
              num_padded_values2 = torch.tensor(
                  num_padded_values[1], dtype=res.dtype
              )[None, :]
              num_padded_values = (
                  num_padded_values1 * kernel[1]
                  + num_padded_values2 * kernel[0]
                  - num_padded_values1 * num_padded_values2
              )
              res = (kernel[0] * kernel[1] * res) / (
                  kernel[0] * kernel[1] - num_padded_values
              )
  
      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 9 for calling a global function with example usage: avg_pool2d() and returns: res, res