code: def gather_results_from_each_node(
      num_replicas, save_dir, timeout
  ) -> List[Dict[str, List]]:
      # WAIT FOR lots of .json files
      start_wait = time.time()
      logger.info("waiting for all nodes to finish")
      json_data = None
      while (time.time() - start_wait) < timeout:
          json_files = list(save_dir.glob("rank_*.json"))
          if len(json_files) < num_replicas:
              continue
          try:
              # make sure all json files are fully saved
              json_data = lmap(load_json, json_files)
              return json_data
          except JSONDecodeError:
              continue
      else:
          raise TimeoutError(
              "Rank 0 gave up on waiting for other processes"
          )
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/examples/legacy/seq2seq/run_distributed_eval.py
imports: import argparse
  import shutil
  import time
  from json import JSONDecodeError
  from logging import getLogger
  from pathlib import Path
  from typing import Dict, List
  import torch
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
  from utils import Seq2SeqDataset, calculate_bleu, calculate_rouge, chunks, lmap, load_json, parse_numeric_n_bool_cl_kwargs, save_json, use_task_specific_params, write_txt_file
label_desc: Use image node_id 4 for calling a global function with example usage: gather_results_from_each_node(num_replicas, save_dir, timeout) and returns: json_data