class_docstr: Row-wise correlation pyramid.
  
  Create a row-wise correlation pyramid with ``num_levels`` level from the outputs of the feature encoder,
  this correlation pyramid will later be used as index to create correlation features using CorrBlock1d.
class_docstr_tok: ["Row-wise","correlation","pyramid",".","Create","a","row-wise","correlation","pyramid","with","``","num_levels","``","level","from","the","outputs","of","the","feature","encoder",",","this","correlation","pyramid","will","later","be","used","as","index","to","create","correlation","features","using","CorrBlock1d","."]
docstr: Build the correlation pyramid from two feature maps.
  
  The correlation volume is first computed as the dot product of each pair (pixel_in_fmap1, pixel_in_fmap2) on the same row.
  The last 2 dimensions of the correlation volume are then pooled num_levels times at different resolutions
  to build the correlation pyramid.
code: def forward(self, fmap1: Tensor, fmap2: Tensor) -> List[Tensor]:
      """Build the correlation pyramid from two feature maps.
  
      The correlation volume is first computed as the dot product of each pair (pixel_in_fmap1, pixel_in_fmap2) on the same row.
      The last 2 dimensions of the correlation volume are then pooled num_levels times at different resolutions
      to build the correlation pyramid.
      """
  
      torch._assert(
          fmap1.shape == fmap2.shape,
          f"Input feature maps should have the same shape, instead got {fmap1.shape} (fmap1.shape) != {fmap2.shape} (fmap2.shape)",
      )
  
      batch_size, num_channels, h, w = fmap1.shape
      fmap1 = fmap1.view(batch_size, num_channels, h, w)
      fmap2 = fmap2.view(batch_size, num_channels, h, w)
  
      corr = torch.einsum("aijk,aijh->ajkh", fmap1, fmap2)
      corr = corr.view(batch_size, h, w, 1, w)
      corr_volume = corr / torch.sqrt(
          torch.tensor(num_channels, device=corr.device)
      )
  
      corr_volume = corr_volume.reshape(batch_size * h * w, 1, 1, w)
      corr_pyramid = [corr_volume]
      for _ in range(self.num_levels - 1):
          corr_volume = F.avg_pool2d(
              corr_volume, kernel_size=(1, 2), stride=(1, 2)
          )
          corr_pyramid.append(corr_volume)
  
      return corr_pyramid
  
imports: from functools import partial
  from typing import Callable, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  import torchvision.models.optical_flow.raft
  from torch import Tensor
  from torchvision.models._api import register_model, Weights, WeightsEnum
  from torchvision.models._utils import handle_legacy_interface
  from torchvision.models.optical_flow._utils import grid_sample, make_coords_grid, upsample_flow
  from torchvision.models.optical_flow.raft import FlowHead, MotionEncoder, ResidualBlock
  from torchvision.ops import Conv2dNormActivation
  from torchvision.prototype.transforms._presets import StereoMatching
  from torchvision.utils import _log_api_usage_once
label_desc: Use image node_id 2 for calling the CorrPyramid1d obj's underlying member method code with example usage: obj.forward(fmap1, fmap2) and returns: corr_pyramid