code: def _flow_sequence_consistency_loss_fn(
      flow_preds: List[Tensor],
      gamma: float = 0.8,
      resize_factor: float = 0.25,
      rescale_factor: float = 0.25,
      rescale_mode: str = "bilinear",
      weights: Optional[Tensor] = None,
  ):
      """Loss function defined over sequence of flow predictions"""
  
      # Simplified version of ref: https://arxiv.org/pdf/2006.11242.pdf
      # In the original paper, an additional refinement network is used to refine a flow prediction.
      # Each step performed by the recurrent module in Raft or CREStereo is a refinement step using a delta_flow update.
      # which should be consistent with the previous step. In this implementation, we simplify the overall loss
      # term and ignore left-right consistency loss or photometric loss which can be treated separately.
  
      torch._assert(
          rescale_factor <= 1.0,
          "sequence_consistency_loss: `rescale_factor` must be less than or equal to 1, but got {}".format(
              rescale_factor
          ),
      )
  
      flow_preds = torch.stack(
          flow_preds
      )  # shape = (num_flow_updates, batch_size, 2, H, W)
      N, B, C, H, W = flow_preds.shape
  
      # rescale flow predictions to account for bilinear upsampling artifacts
      if rescale_factor:
          flow_preds = (
              F.interpolate(
                  flow_preds.view(N * B, C, H, W),
                  scale_factor=resize_factor,
                  mode=rescale_mode,
                  align_corners=True,
              )
          ) * rescale_factor
          flow_preds = torch.stack(
              torch.chunk(flow_preds, N, dim=0), dim=0
          )
  
      # force the next prediction to be similar to the previous prediction
      abs_diff = (flow_preds[1:] - flow_preds[:-1]).square()
      abs_diff = abs_diff.mean(axis=(1, 2, 3, 4))
  
      num_predictions = (
          flow_preds.shape[0] - 1
      )  # because we are comparing differences
      if weights is None or len(weights) != num_predictions:
          weights = gamma ** torch.arange(
              num_predictions - 1,
              -1,
              -1,
              device=flow_preds.device,
              dtype=flow_preds.dtype,
          )
  
      flow_loss = (abs_diff * weights).sum()
      return flow_loss, weights
  
imports: from typing import List, Optional
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  from torchvision.prototype.models.depth.stereo.raft_stereo import grid_sample, make_coords_grid
label_desc: Use image node_id 5 for calling a global function with example usage: _flow_sequence_consistency_loss_fn(flow_preds, gamma, resize_factor, rescale_factor, rescale_mode, weights) and returns: flow_loss,  weights