code: def _select_fit_memory_chunk_region(
      self, possible_chunk_regions, chunk_infos, mem_peak
  ):
      # stop chunk if max memory satisfy memory limit
      if max(mem_peak) < self.max_memory:
          return None
  
      # remove illegal regions
      illegal_regions = []
      for i in possible_chunk_regions:
          if not self._is_legal_region(i, chunk_infos):
              illegal_regions.append(i)
      for i in illegal_regions:
          if i in possible_chunk_regions:
              possible_chunk_regions.remove(i)
  
      if len(possible_chunk_regions) == 0:
          return None
  
      # get mem for chunk region
      regions_dict = []
      for region in possible_chunk_regions:
          cur_region = region.copy()
          cur_node_list, cur_region = self.reorder_graph.tmp_reorder(
              self.node_mgr.get_node_list(), cur_region
          )
          cur_chunk_infos = chunk_infos + [cur_region]
          cur_mem = self.estimate_memory.estimate_chunk_inference_mem(
              cur_node_list, cur_chunk_infos
          )[0]
          cur_chunk_region_peak = cur_mem[
              cur_region["region"][0] : cur_region["region"][1] + 1
          ]
          cur_chunk_region_max_peak = max(cur_chunk_region_peak)
          if cur_chunk_region_max_peak < self.max_memory:
              regions_dict.append(
                  {
                      "chunk_info": region,
                      "chunk_max_mem": cur_chunk_region_max_peak,
                      "chunk_len": self._get_compute_node_num(
                          region["region"][0], region["region"][1]
                      ),
                      "reorder_chunk_info": cur_region,
                      "reorder_node_list": cur_node_list,
                  }
              )
      # no region found
      if len(regions_dict) == 0:
          raise RuntimeError(
              "Search failed. Try a larger memory threshold."
          )
  
      # select the min chunk len
      chunk_len = [i["chunk_len"] for i in regions_dict]
      best_region_idx = chunk_len.index(min(chunk_len))
      best_region = regions_dict[best_region_idx]
  
      # get max chunk size
      best_region = self._get_fit_chunk_size(best_region, chunk_infos)
      return best_region
  
file_path: ColossalAI/colossalai/autochunk/select_chunk.py
imports: from .estimate_memory import EstimateMemory
  from .reorder_graph import ReorderGraph
  from .trace_indice import TraceIndice
  from .utils import NodeMgr, is_non_compute_node
label_desc: Use image node_id 3 for calling the SelectChunk obj's underlying member method code with example usage: obj._select_fit_memory_chunk_region(possible_chunk_regions, chunk_infos, mem_peak) and returns: best_region, None, None