code: def _pad_and_downsample(x: Tensor) -> Tensor:
      """
      Downsamples using average pooling, padding if necessary.
  
      To match the Tensorflow MS-SSIM implementation, we need to pad
      images before pooling if their height/width does not evenly
      divide 2. Tensorflow uses "SYMMETRIC" padding, which is
      equivalent to PyTorch's replication padding in our special
      case where at most 1 element of padding is added to each
      dimension.
  
      Args:
          x: a batch of images to pad and downsample, of shape [batch_size,
              num_channels, height, width].
  
      Returns:
          The padded and downsampled tensor, of shape [batch_size,
          num_channels, ceil(height / 2), ceil(width / 2)] where the
          output height/widht is relative to the input shape.
      """
  
      padded = F.pad(
          x, (0, x.shape[3] % 2, 0, x.shape[2] % 2), mode="replicate"
      )
      return F.avg_pool2d(padded, kernel_size=2)
  
file_path: NeuralCompression/neuralcompression/functional/_multiscale_structural_similarity.py
imports: from typing import Callable, Optional, Sequence
  import torch
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 5 for calling a global function with example usage: _pad_and_downsample(x) and returns: F