class_docstr: The Runner for ensembler. It ensembles predictions and saves them to the disk with a support of using multi-GPU.
  
  Args:
      data_src_cfg_name: filename of the data source.
      work_dir: working directory to save the intermediate and final results. Default is `./work_dir`.
      num_fold: number of fold. Default is 5.
      ensemble_method_name: method to ensemble predictions from different model. Default is AlgoEnsembleBestByFold.
                            Supported methods: ["AlgoEnsembleBestN", "AlgoEnsembleBestByFold"].
      mgpu: if using multi-gpu. Default is True.
      kwargs: additional image writing, ensembling parameters and prediction parameters for the ensemble inference.
            - for image saving, please check the supported parameters in SaveImage transform.
            - for prediction parameters, please check the supported parameters in the ``AlgoEnsemble`` callables.
            - for ensemble parameters, please check the documentation of the selected AlgoEnsemble callable.
  
  Example:
  
      .. code-block:: python
  
          ensemble_runner = EnsembleRunner(data_src_cfg_name,
                                           work_dir,
                                           ensemble_method_name,
                                           mgpu=device_setting['n_devices']>1,
                                           **kwargs,
                                           **pred_params)
          ensemble_runner.run(device_setting)
class_docstr_tok: ["The","Runner","for","ensembler",".","It","ensembles","predictions","and","saves","them","to","the","disk","with","a","support","of","using","multi-GPU",".","Args",":","data_src_cfg_name",":","filename","of","the","data","source",".","work_dir",":","working","directory","to","save","the","intermediate","and","final","results",".","Default","is","`",".\/work_dir","`",".","num_fold",":","number","of","fold",".","Default","is","5.","ensemble_method_name",":","method","to","ensemble","predictions","from","different","model",".","Default","is","AlgoEnsembleBestByFold",".","Supported","methods",":","[","``","AlgoEnsembleBestN","''",",","``","AlgoEnsembleBestByFold","''","]",".","mgpu",":","if","using","multi-gpu",".","Default","is","True",".","kwargs",":","additional","image","writing",",","ensembling","parameters","and","prediction","parameters","for","the","ensemble","inference",".","-","for","image","saving",",","please","check","the","supported","parameters","in","SaveImage","transform",".","-","for","prediction","parameters",",","please","check","the","supported","parameters","in","the","``","AlgoEnsemble","``","callables",".","-","for","ensemble","parameters",",","please","check","the","documentation","of","the","selected","AlgoEnsemble","callable",".","Example",":","..","code-block",":",":","python","ensemble_runner","=","EnsembleRunner","(","data_src_cfg_name",",","work_dir",",","ensemble_method_name",",","mgpu=device_setting","[","'n_devices","'","]",">","1",",","*","*","kwargs",",","*","*","pred_params",")","ensemble_runner.run","(","device_setting",")"]
code: def _create_cmd(self) -> None:
      if (
          int(self.device_setting["NUM_NODES"]) <= 1
          and int(self.device_setting["n_devices"]) <= 1
      ):
          # if single GPU
          logger.info("Ensembling using single GPU!")
          self.ensemble()
          return
  
      # define base cmd for subprocess
      base_cmd = f"monai.apps.auto3dseg EnsembleRunner ensemble \
                  --data_src_cfg_name {self.data_src_cfg_name} \
                  --work_dir {self.work_dir} \
                  --num_fold {self.num_fold} \
                  --ensemble_method_name {self.ensemble_method_name} \
                  --mgpu True"
  
      if self.kwargs and isinstance(self.kwargs, Mapping):
          for k, v in self.kwargs.items():
              base_cmd += f" --{k}={v}"
      # define env for subprocess
      ps_environ = os.environ.copy()
      ps_environ["CUDA_VISIBLE_DEVICES"] = str(
          self.device_setting["CUDA_VISIBLE_DEVICES"]
      )
      if int(self.device_setting["NUM_NODES"]) > 1:
          if self.device_setting["MN_START_METHOD"] != "bcprun":
              raise NotImplementedError(
                  f"{self.device_setting['MN_START_METHOD']} is not supported yet. "
                  "Try modify EnsembleRunner._create_cmd for your cluster."
              )
          logger.info(
              f"Ensembling on {self.device_setting['NUM_NODES']} nodes!"
          )
          cmd = _prepare_cmd_bcprun(
              "-m " + base_cmd,
              cmd_prefix=f"{self.device_setting['CMD_PREFIX']}",
          )
          _run_cmd_bcprun(
              cmd,
              n=self.device_setting["NUM_NODES"],
              p=self.device_setting["n_devices"],
          )
  
      else:
          logger.info(
              f"Ensembling using {self.device_setting['n_devices']} GPU!"
          )
          cmd = _prepare_cmd_torchrun("-m " + base_cmd)
          _run_cmd_torchrun(
              cmd,
              nnodes=1,
              nproc_per_node=self.device_setting["n_devices"],
              env=ps_environ,
              check=True,
          )
      return
  
imports: from __future__ import annotations
  import os
  from abc import ABC, abstractmethod
  from collections.abc import Mapping, Sequence
  from copy import deepcopy
  from typing import Any, cast
  from warnings import warn
  import numpy
  import torch
  import torch.distributed
  from monai.apps.auto3dseg.bundle_gen import BundleAlgo
  from monai.apps.auto3dseg.utils import get_name_from_algo_id, import_bundle_algo_history
  from monai.apps.utils import get_logger
  from monai.auto3dseg import concat_val_to_np
  from monai.auto3dseg.utils import _prepare_cmd_bcprun, _prepare_cmd_torchrun, _run_cmd_bcprun, _run_cmd_torchrun, datafold_read
  from monai.bundle import ConfigParser
  from monai.data import partition_dataset
  from monai.transforms import MeanEnsemble, SaveImage, VoteEnsemble
  from monai.utils import RankFilter
  from monai.utils.enums import AlgoKeys
  from monai.utils.misc import check_kwargs_exist_in_class_init, prob2class
  from monai.utils.module import look_up_option, optional_import
label_desc: Use image node_id 8 for calling the EnsembleRunner obj's underlying member method code with example usage: obj._create_cmd() without return types