code: def average_pool(
      inputs,
      pool_size,
      strides=None,
      padding="valid",
      data_format=None,
  ):
      inputs = convert_to_tensor(inputs)
      num_spatial_dims = inputs.ndim - 2
      pool_size = standardize_tuple(
          pool_size, num_spatial_dims, "pool_size"
      )
      if strides is None:
          strides = pool_size
      else:
          strides = standardize_tuple(
              strides, num_spatial_dims, "strides"
          )
  
      data_format = standardize_data_format(data_format)
      if data_format == "channels_last":
          inputs = _transpose_spatial_inputs(inputs)
      padding_value = 0
      if padding == "same":
          spatial_shape = inputs.shape[2:]
          num_spatial_dims = len(spatial_shape)
          padding_value = []
          uneven_padding = []
  
          for i in range(num_spatial_dims):
              padding_size = _compute_padding_length(
                  spatial_shape[i], pool_size[i], strides[i]
              )
              # Torch only supports even padding on each dim, to replicate the
              # behavior of "same" padding of `tf.keras` as much as possible,
              # we need to pad evenly using the shorter padding.
              padding_value.append(padding_size[0])
              if padding_size[0] != padding_size[1]:
                  # Handle unequal padding.
                  # `torch.nn.pad` sets padding value in the reverse order.
                  uneven_padding = [0, 1] + uneven_padding
          # Only call tnn.pad when needed.
          if len(uneven_padding) > 0:
              inputs = tnn.pad(inputs, uneven_padding)
  
      if num_spatial_dims == 1:
          outputs = tnn.avg_pool1d(
              inputs,
              kernel_size=pool_size,
              stride=strides,
              padding=padding_value,
              count_include_pad=False,
          )
      elif num_spatial_dims == 2:
          outputs = tnn.avg_pool2d(
              inputs,
              kernel_size=pool_size,
              stride=strides,
              padding=padding_value,
              count_include_pad=False,
          )
      elif num_spatial_dims == 3:
          outputs = tnn.avg_pool3d(
              inputs,
              kernel_size=pool_size,
              stride=strides,
              padding=padding_value,
              count_include_pad=False,
          )
      else:
          raise ValueError(
              "Inputs to pooling op must have ndim=3, 4 or 5, "
              "corresponding to 1D, 2D and 3D inputs. "
              f"Received input shape: {inputs.shape}."
          )
      if data_format == "channels_last":
          outputs = _transpose_spatial_outputs(outputs)
      return outputs
  
imports: import torch
  import torch.nn.functional
  import tree
  from keras.backend import standardize_data_format
  from keras.backend import standardize_dtype
  from keras.backend.common.backend_utils import compute_conv_transpose_padding_args_for_torch
  from keras.backend.config import epsilon
  from keras.backend.torch.core import cast
  from keras.backend.torch.core import convert_to_tensor
  from keras.backend.torch.core import get_device
  from keras.backend.torch.numpy import expand_dims
  from keras.backend.torch.numpy import maximum
  from keras.backend.torch.numpy import where
  from keras.utils.argument_validation import standardize_tuple
label_desc: Use image node_id 23 for calling a global function with example usage: average_pool(inputs, pool_size, strides, padding, data_format) and returns: outputs