code: def _pyg_collate(samples: List[Dict[str, Any]]) -> Dict[str, Any]:
      """Helper to collate PyTorch Geometric ``Data`` objects into PyTorch Geometric ``Batch`` objects whilst preserving
      our dictionary format."""
      inputs = Batch.from_data_list(
          [sample[DataKeys.INPUT] for sample in samples]
      )
      if DataKeys.TARGET in samples[0]:
          targets = default_collate(
              [sample[DataKeys.TARGET] for sample in samples]
          )
          return {DataKeys.INPUT: inputs, DataKeys.TARGET: targets}
      return {DataKeys.INPUT: inputs}
  
imports: from typing import Any, Dict, List
  from torch.utils.data.dataloader import default_collate
  from flash.core.data.io.input import DataKeys
  from flash.core.utilities.imports import _TOPIC_GRAPH_AVAILABLE
label_desc: Use image node_id 1 for calling a global function with example usage: _pyg_collate(samples) and returns: dict, dict