code: def get_best_candidates(
      candidate_batch_sizes,
      micro_batches,
      min_gpus,
      max_gpus,
      prefer_larger,
  ):
      max_valid_gpus = 0
      valid_gpus = None
      final_batch_size = int(min(micro_batches))
  
      for batch_size in candidate_batch_sizes:
          current_valid_gpus = get_valid_gpus(
              batch_size, micro_batches, min_gpus, max_gpus
          )
  
          if len(current_valid_gpus) > max_valid_gpus or (
              len(current_valid_gpus) == max_valid_gpus
              and (
                  (prefer_larger and batch_size > final_batch_size)
                  or (
                      not prefer_larger
                      and batch_size < final_batch_size
                  )
              )
          ):
              max_valid_gpus = len(current_valid_gpus)
              valid_gpus = current_valid_gpus
              final_batch_size = batch_size
  
      return final_batch_size, valid_gpus
  
file_path: DeepSpeed/deepspeed/elasticity/elasticity.py
imports: import os
  import json
  import numpy
  import math
  from packaging import version
  from .config import ElasticityConfig, ElasticityConfigError, ElasticityError, ElasticityIncompatibleWorldSize
  from .constants import ELASTICITY, ENABLED, ENABLED_DEFAULT, LATEST_ELASTICITY_VERSION, MINIMUM_DEEPSPEED_VERSION, DEEPSPEED_ELASTICITY_CONFIG
  from ..git_version_info import version
  from ..utils import logger
label_desc: Use image node_id 3 for calling a global function with example usage: get_best_candidates(candidate_batch_sizes, micro_batches, min_gpus, max_gpus, prefer_larger) and returns: final_batch_size,  valid_gpus