class_docstr: Compute contrastive loss between image and text pairs.
  
  Args:
      opts: command-line arguments
class_docstr_tok: ["Compute","contrastive","loss","between","image","and","text","pairs",".","Args",":","opts",":","command-line","arguments"]
docstr: Computes contrastive loss between image and text representations, optionally with neural aug
  
  Args:
      input_sample: Input to the model.
      prediction: A mapping of the form (string: Tensor). image and text are mandatory keys.
  
  Shape:
      input_sample: This loss function does not care about this argument.
      prediction["image"]: Shape is [N, d]
      prediction["text"]: Shape is [N, d]
  
      where N is the local batch size and d is the feature dimension.
  
  Returns:
      The output dictionary contains four keys (total_loss, image_loss, text_loss, logit_scale) and scalar
      loss value for each of these keys. total_loss is sum of image_loss and text_loss.
docstr_tok: ["Computes","contrastive","loss","between","image","and","text","representations",",","optionally","with","neural","aug","Args",":","input_sample",":","Input","to","the","model",".","prediction",":","A","mapping","of","the","form","(","string",":","Tensor",")",".","image","and","text","are","mandatory","keys",".","Shape",":","input_sample",":","This","loss","function","does","not","care","about","this","argument",".","prediction","[","``","image","''","]",":","Shape","is","[","N",",","d","]","prediction","[","``","text","''","]",":","Shape","is","[","N",",","d","]","where","N","is","the","local","batch","size","and","d","is","the","feature","dimension",".","Returns",":","The","output","dictionary","contains","four","keys","(","total_loss",",","image_loss",",","text_loss",",","logit_scale",")","and","scalar","loss","value","for","each","of","these","keys",".","total_loss","is","sum","of","image_loss","and","text_loss","."]
code: def forward(
      self,
      input_sample: Any,
      prediction: Dict[str, Tensor],
      *args,
      **kwargs,
  ) -> Dict:
      """
      Computes contrastive loss between image and text representations, optionally with neural aug
  
      Args:
          input_sample: Input to the model.
          prediction: A mapping of the form (string: Tensor). image and text are mandatory keys.
  
      Shape:
          input_sample: This loss function does not care about this argument.
          prediction["image"]: Shape is [N, d]
          prediction["text"]: Shape is [N, d]
  
          where N is the local batch size and d is the feature dimension.
  
      Returns:
          The output dictionary contains four keys (total_loss, image_loss, text_loss, logit_scale) and scalar
          loss value for each of these keys. total_loss is sum of image_loss and text_loss.
      """
  
      if not self.training:
          # we typically compute zero-shot logits for monitoring the val perf.
          # Therefore, we return 0 for loss during validation.
  
          # Note: In future, we may compute validation loss (depending on use case)
          return {
              "total_loss": torch.tensor(
                  0.0, dtype=torch.float, device=self.device
              )
          }
  
      clip_loss_dict = self._forward_clip(prediction=prediction)
      return clip_loss_dict
  
file_path: ml-cvnets/loss_fn/multi_modal_img_text/contrastive_loss_clip.py
imports: import argparse
  from typing import Any, Dict, Tuple
  import torch
  from torch import Tensor
  from torch.nn import functional
  from loss_fn import LOSS_REGISTRY
  from loss_fn.multi_modal_img_text.base_multi_modal_img_text_criteria import BaseMultiModalImageTextCriteria
  from utils import logger
  from utils.tensor_utils import gather_all_features
label_desc: Use image node_id 3 for calling the ContrastiveLossClip obj's underlying member method code with example usage: obj.forward(input_sample, prediction) and returns: clip_loss_dict, dict