code: def apply_to_sample(f, sample):
      ## add check for datasets that return none samples for missing items
      if sample == None or len(sample) == 0:
          return {}
  
      def _apply(x):
          if torch.is_tensor(x):
              return f(x)
          elif isinstance(x, dict):
              return {key: _apply(value) for key, value in x.items()}
          elif isinstance(x, list):
              return [_apply(x) for x in x]
          else:
              return x
  
      return _apply(sample)
  
imports: import gzip
  import logging
  import os
  import random
  import tarfile
  import zipfile
  import cv2
  import decord
  import webdataset
  import numpy
  import torch
  from torch.utils.data.dataset import IterableDataset, ChainDataset
  from decord import VideoReader
  from lavis.common.registry import registry
  from lavis.datasets.datasets.base_dataset import ConcatDataset
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling a global function with example usage: apply_to_sample(f, sample) and returns: _apply, dict, f, unknown, unknown, x