class_docstr: Distributed evaluation hook.
  
  This hook will regularly perform evaluation in a given interval when
  performing in distributed environment.
  
  Args:
      dataloader (DataLoader): A PyTorch dataloader, whose dataset has
          implemented ``evaluate`` function.
      start (int | None, optional): Evaluation starting epoch. It enables
          evaluation before the training starts if ``start`` <= the resuming
          epoch. If None, whether to evaluate is merely decided by
          ``interval``. Default: None.
      interval (int): Evaluation interval. Default: 1.
      by_epoch (bool): Determine perform evaluation by epoch or by iteration.
          If set to True, it will perform by epoch. Otherwise, by iteration.
          default: True.
      save_best (str, optional): If a metric is specified, it would measure
          the best checkpoint during evaluation. The information about best
          checkpoint would be saved in ``runner.meta['hook_msgs']`` to keep
          best score value and best checkpoint path, which will be also
          loaded when resume checkpoint. Options are the evaluation metrics
          on the test dataset. e.g., ``bbox_mAP``, ``segm_mAP`` for bbox
          detection and instance segmentation. ``AR@100`` for proposal
          recall. If ``save_best`` is ``auto``, the first key of the returned
          ``OrderedDict`` result will be used. Default: None.
      rule (str | None, optional): Comparison rule for best score. If set to
          None, it will infer a reasonable rule. Keys such as 'acc', 'top'
          .etc will be inferred by 'greater' rule. Keys contain 'loss' will
          be inferred by 'less' rule. Options are 'greater', 'less', None.
          Default: None.
      test_fn (callable, optional): test a model with samples from a
          dataloader in a multi-gpu manner, and return the test results. If
          ``None``, the default test function ``mmcv.engine.multi_gpu_test``
          will be used. (default: ``None``)
      tmpdir (str | None): Temporary directory to save the results of all
          processes. Default: None.
      gpu_collect (bool): Whether to use gpu or cpu to collect results.
          Default: False.
      broadcast_bn_buffer (bool): Whether to broadcast the
          buffer(running_mean and running_var) of rank 0 to other rank
          before evaluation. Default: True.
      out_dir (str, optional): The root directory to save checkpoints. If not
          specified, `runner.work_dir` will be used by default. If specified,
          the `out_dir` will be the concatenation of `out_dir` and the last
          level directory of `runner.work_dir`.
      file_client_args (dict): Arguments to instantiate a FileClient.
          See :class:`mmcv.fileio.FileClient` for details. Default: None.
      **eval_kwargs: Evaluation arguments fed into the evaluate function of
          the dataset.
class_docstr_tok: ["Distributed","evaluation","hook",".","This","hook","will","regularly","perform","evaluation","in","a","given","interval","when","performing","in","distributed","environment",".","Args",":","dataloader","(","DataLoader",")",":","A","PyTorch","dataloader",",","whose","dataset","has","implemented","``","evaluate","``","function",".","start","(","int","|","None",",","optional",")",":","Evaluation","starting","epoch",".","It","enables","evaluation","before","the","training","starts","if","``","start","``","<","=","the","resuming","epoch",".","If","None",",","whether","to","evaluate","is","merely","decided","by","``","interval","``",".","Default",":","None",".","interval","(","int",")",":","Evaluation","interval",".","Default",":","1.","by_epoch","(","bool",")",":","Determine","perform","evaluation","by","epoch","or","by","iteration",".","If","set","to","True",",","it","will","perform","by","epoch",".","Otherwise",",","by","iteration",".","default",":","True",".","save_best","(","str",",","optional",")",":","If","a","metric","is","specified",",","it","would","measure","the","best","checkpoint","during","evaluation",".","The","information","about","best","checkpoint","would","be","saved","in","``","runner.meta","[","'hook_msgs","'","]","``","to","keep","best","score","value","and","best","checkpoint","path",",","which","will","be","also","loaded","when","resume","checkpoint",".","Options","are","the","evaluation","metrics","on","the","test","dataset",".","e.g.",",","``","bbox_mAP","``",",","``","segm_mAP","``","for","bbox","detection","and","instance","segmentation",".","``","AR","@","100","``","for","proposal","recall",".","If","``","save_best","``","is","``","auto","``",",","the","first","key","of","the","returned","``","OrderedDict","``","result","will","be","used",".","Default",":","None",".","rule","(","str","|","None",",","optional",")",":","Comparison","rule","for","best","score",".","If","set","to","None",",","it","will","infer","a","reasonable","rule",".","Keys","such","as","'acc","'",",","'top'",".etc","will","be","inferred","by","'greater","'","rule",".","Keys","contain","'loss","'","will","be","inferred","by","'less","'","rule",".","Options","are","'greater","'",",","'less","'",",","None",".","Default",":","None",".","test_fn","(","callable",",","optional",")",":","test","a","model","with","samples","from","a","dataloader","in","a","multi-gpu","manner",",","and","return","the","test","results",".","If","``","None","``",",","the","default","test","function","``","mmcv.engine.multi_gpu_test","``","will","be","used",".","(","default",":","``","None","``",")","tmpdir","(","str","|","None",")",":","Temporary","directory","to","save","the","results","of","all","processes",".","Default",":","None",".","gpu_collect","(","bool",")",":","Whether","to","use","gpu","or","cpu","to","collect","results",".","Default",":","False",".","broadcast_bn_buffer","(","bool",")",":","Whether","to","broadcast","the","buffer","(","running_mean","and","running_var",")","of","rank","0","to","other","rank","before","evaluation",".","Default",":","True",".","out_dir","(","str",",","optional",")",":","The","root","directory","to","save","checkpoints",".","If","not","specified",",","`","runner.work_dir","`","will","be","used","by","default",".","If","specified",",","the","`","out_dir","`","will","be","the","concatenation","of","`","out_dir","`","and","the","last","level","directory","of","`","runner.work_dir","`",".","file_client_args","(","dict",")",":","Arguments","to","instantiate","a","FileClient",".","See",":","class",":","`","mmcv.fileio.FileClient","`","for","details",".","Default",":","None",".","*","*","eval_kwargs",":","Evaluation","arguments","fed","into","the","evaluate","function","of","the","dataset","."]
docstr: perform evaluation and save ckpt.
docstr_tok: ["perform","evaluation","and","save","ckpt","."]
code: def _do_evaluate(self, runner):
      """perform evaluation and save ckpt."""
      # Synchronization of BatchNorm's buffer (running_mean
      # and running_var) is not supported in the DDP of pytorch,
      # which may cause the inconsistent performance of models in
      # different ranks, so we broadcast BatchNorm's buffers
      # of rank 0 to other ranks to avoid this.
      if self.broadcast_bn_buffer:
          model = runner.model
          for name, module in model.named_modules():
              if (
                  isinstance(module, _BatchNorm)
                  and module.track_running_stats
              ):
                  dist.broadcast(module.running_var, 0)
                  dist.broadcast(module.running_mean, 0)
  
      tmpdir = self.tmpdir
      if tmpdir is None:
          tmpdir = osp.join(runner.work_dir, ".eval_hook")
  
      results = self.test_fn(
          runner.model,
          self.dataloader,
          tmpdir=tmpdir,
          gpu_collect=self.gpu_collect,
      )
      if runner.rank == 0:
          print("\n")
          runner.log_buffer.output["eval_iter_num"] = len(
              self.dataloader
          )
          key_score = self.evaluate(runner, results)
          # the key_score may be `None` so it needs to skip the action to
          # save the best checkpoint
          if self.save_best and key_score:
              self._save_ckpt(runner, key_score)
  
imports: import os.path
  import warnings
  from math import inf
  import torch.distributed
  from torch.nn.modules.batchnorm import _BatchNorm
  from torch.utils.data import DataLoader
  from annotator.uniformer.mmcv.fileio import FileClient
  from annotator.uniformer.mmcv.utils import is_seq_of
  from .hook import Hook
  from .logger import LoggerHook
label_desc: Use image node_id 2 for calling the DistEvalHook obj's underlying member method code with example usage: obj._do_evaluate(runner) without return types