code: def has_failed(save_dir):
      if not os.path.exists(save_dir):
          return False
  
      # find max job id
      job_ids = []
      for fn in os.listdir(save_dir):
          if fn.startswith("train.stderr."):
              job_ids.append(int(fn.split(".")[-1]))
      if len(job_ids) == 0:
          return False
      max_job_id = max(job_ids)
  
      def _has_failed(stderr_fn):
          with open(stderr_fn) as h:
              for line in h:
                  if len(line.strip()) > 0:
                      # assume that any output in stderr indicates an error
                      return True
          return False
  
      return _has_failed(
          os.path.join(save_dir, f"train.stderr.{max_job_id}")
      )
  
file_path: mmf/tools/sweeps/lib/slurm.py
imports: import datetime
  import itertools
  import os
  import random
  import shlex
  import shutil
  import subprocess
  from collections import OrderedDict
  from glob import glob
  from mmf.utils.general import get_mmf_root
label_desc: Use image node_id 5 for calling a global function with example usage: has_failed(save_dir) and returns: _has_failed, False, False, False, True