code: def contrastive_forward(
      model, cfg, inputs, index, time, epoch_exact, scaler
  ):
      if cfg.CONTRASTIVE.SEQUENTIAL:
          perform_backward = False
          mdl = getattr(model, "module", model)
          keys = (
              mdl.compute_key_feat(
                  inputs,
                  compute_predictor_keys=False,
                  batched_inference=True if len(inputs) < 2 else False,
              )
              if cfg.CONTRASTIVE.TYPE == "moco"
              or cfg.CONTRASTIVE.TYPE == "byol"
              else [None] * len(inputs)
          )
          for k, vid in enumerate(inputs):
              other_keys = keys[:k] + keys[k + 1 :]
              time_cur = torch.cat(
                  [
                      time[:, k : k + 1, :],
                      time[:, :k, :],
                      time[:, k + 1 :, :],
                  ],
                  1,
              )  # q, kpre, kpost
              vids = [vid]
              if (
                  cfg.CONTRASTIVE.TYPE == "swav"
                  or cfg.CONTRASTIVE.TYPE == "simclr"
              ):
                  if k < len(inputs) - 1:
                      vids = inputs[k : k + 2]
                  else:
                      break
              lgt_k, loss_k = model(
                  vids, index, time_cur, epoch_exact, keys=other_keys
              )
              scaler.scale(loss_k).backward()
              if k == 0:
                  preds, partial_loss = lgt_k, loss_k.detach()
              else:
                  preds = torch.cat([preds, lgt_k], dim=0)
                  partial_loss += loss_k.detach()
          partial_loss /= (
              len(inputs) * 2.0
          )  # to have same loss as symm model
          if cfg.CONTRASTIVE.TYPE == "moco":
              mdl._dequeue_and_enqueue(keys)
      else:
          perform_backward = True
          preds, partial_loss = model(
              inputs, index, time, epoch_exact, keys=None
          )
      return model, preds, partial_loss, perform_backward
  
imports: import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import slowfast.models.losses
  import slowfast.utils.distributed
  import slowfast.utils.logging
  from slowfast.models.video_model_builder import X3D, MViT, ResNet, SlowFast
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 3 for calling a global function with example usage: contrastive_forward(model, cfg, inputs, index, time, epoch_exact, scaler) and returns: model,  preds,  partial_loss,  perform_backward