code: def get_early_stopping_callback(metric, patience):
      return EarlyStopping(
          monitor=f"val_{metric}",  # does this need avg?
          mode="min" if "loss" in metric else "max",
          patience=patience,
          verbose=True,
      )
  
file_path: transformers/examples/research_projects/rag-end2end-retriever/callbacks_rag.py
imports: import logging
  from pathlib import Path
  import numpy
  import pytorch_lightning
  import torch
  from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint
  from pytorch_lightning.utilities import rank_zero_only
  from utils_rag import save_json
label_desc: Use image node_id 3 for calling a global function with example usage: get_early_stopping_callback(metric, patience) and returns: EarlyStopping