code: def sort_log_data(data):
      """Sort each data[data_type][metric] by epoch or keep only first instance."""
      for t in data:
          if "epoch" in data[t]:
              assert (
                  "epoch_ind" not in data[t]
                  and "epoch_max" not in data[t]
              )
              data[t]["epoch_ind"] = [
                  int(e.split("/")[0]) for e in data[t]["epoch"]
              ]
              data[t]["epoch_max"] = [
                  int(e.split("/")[1]) for e in data[t]["epoch"]
              ]
              epoch = data[t]["epoch_ind"]
              if "iter" in data[t]:
                  assert (
                      "iter_ind" not in data[t]
                      and "iter_max" not in data[t]
                  )
                  data[t]["iter_ind"] = [
                      int(i.split("/")[0]) for i in data[t]["iter"]
                  ]
                  data[t]["iter_max"] = [
                      int(i.split("/")[1]) for i in data[t]["iter"]
                  ]
                  itr = zip(
                      epoch, data[t]["iter_ind"], data[t]["iter_max"]
                  )
                  epoch = [
                      e + (i_ind - 1) / i_max for e, i_ind, i_max in itr
                  ]
              for m in data[t]:
                  data[t][m] = [
                      v for _, v in sorted(zip(epoch, data[t][m]))
                  ]
          else:
              data[t] = {m: d[0] for m, d in data[t].items()}
      return data
  
file_path: pycls/pycls/core/logging.py
imports: import builtins
  import decimal
  import logging
  import os
  import sys
  import pycls.core.distributed
  import simplejson
  from pycls.core.config import cfg
  from pycls.core.io import pathmgr
label_desc: Use image node_id 8 for calling a global function with example usage: sort_log_data(data) and returns: data