code: def multi_modal_img_text_collate_fn(
      batch: List[Mapping[str, Union[Tensor, Mapping[str, Tensor]]]],
      opts: argparse.Namespace,
  ) -> Mapping[str, Union[Tensor, Mapping[str, Tensor]]]:
      """Combines a list of dictionaries into a single dictionary by concatenating matching fields."""
      images = []
      text_tokens = []
      padding_mask = []
      labels = []
  
      truncate_seq_len = getattr(
          opts, "dataset.multi_modal_img_text.trunc_seq_len"
      )
  
      zero_shot = batch[0].pop("zero_shot", 0)
  
      max_seq_len_in_batch = (
          1  # at least one token is required in the sequence
      )
      for i, batch_i in enumerate(batch):
          inputs_i = batch_i.pop("samples")
          img_tensor = inputs_i.pop("image", None)
          if img_tensor is None:
              continue
          images.append(img_tensor)
          labels.append(batch_i.pop("targets"))
  
          text_data = inputs_i.pop("text")
          pad_mask = inputs_i.pop("padding_mask", None)
          max_seq_len_in_batch = max(
              max_seq_len_in_batch, inputs_i.pop("max_seq_len", 0)
          )
          if not zero_shot or (zero_shot and i == 0):
              # For zero-shot, all text captions are the same
              # so, we only aggregate for one batch element
              text_tokens.append(text_data)
              if pad_mask is not None:
                  padding_mask.append(pad_mask)
  
      images = torch.stack(images, dim=0)
      text_tokens = torch.stack(text_tokens, dim=0)
  
      # truncate tokens based on the max. seq length
      if not truncate_seq_len:
          max_seq_len_in_batch = text_tokens.shape[-1]
      text_tokens = text_tokens[..., :max_seq_len_in_batch]
  
      if len(padding_mask) != 0:
          padding_mask = torch.stack(padding_mask, dim=0)
          padding_mask = padding_mask[..., :max_seq_len_in_batch]
      else:
          padding_mask = None
  
      labels = torch.tensor(labels, dtype=torch.long)
  
      channels_last = getattr(opts, "common.channels_last")
      if channels_last:
          images = images.to(memory_format=torch.channels_last)
  
      return {
          "samples": {
              "image": images,
              "text": text_tokens,
              "padding_mask": padding_mask,
          },
          "targets": labels,
      }
  
imports: import argparse
  import os
  from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
  import torch
  from PIL import Image
  from torch import Tensor
  from data.collate_fns import COLLATE_FN_REGISTRY
  from data.datasets.dataset_base import BaseImageDataset
  from data.datasets.multi_modal_img_text.zero_shot import BaseZeroShotDataset, build_zero_shot_dataset
  from data.datasets.utils.text import caption_preprocessing
  from data.text_tokenizer import build_tokenizer
  from data.transforms import image_pil
  from data.transforms.common import Compose
  from utils import logger
  from utils.ddp_utils import is_master, is_start_rank_node
label_desc: Use image node_id 1 for calling a global function with example usage: multi_modal_img_text_collate_fn(batch, opts) and returns: dict