code: def search_plan_to_layer(
      sym,
      layer_name=None,
      threshold=500,
      ntrial=6,
      type_dict=None,
      **kwargs,
  ):
      """Quickly heurestic search over possible plans to find good memory plan.
  
      Parameters
      ----------
      sym : symbolic
         Symbolic configurations
  
      ntrial: integer
         Additional grid search steps
      """
      history = []
      min_threshold = None
      min_cost = None
      nbegin = 10
  
      for k in range(nbegin):
          info = {}
          sym = make_mirror_plan_to_layer(
              sym,
              layer_name=layer_name,
              threshold=threshold,
              plan_info=info,
              **kwargs,
          )
          cost = get_cost(sym, type_dict, **kwargs)
          save_size = info["save_size"] >> 20
          local_size = info["max_size"] >> 20
          guess = 300 * (k + 1)
          if min_cost is None or min_cost > cost:
              min_cost = cost
          if min_threshold is None or local_size < min_threshold:
              min_threshold = local_size
          print(
              "Search threshold=%d MB, cost=%d MB" % (threshold, cost)
          )
          history.append((cost, threshold, sym))
          threshold = guess
  
      max_threshold = threshold * math.sqrt(2)
      step = int((max_threshold - min_threshold) / ntrial)
      print(min_threshold, max_threshold, step)
      threshold = min_threshold + step
      if step > 0:
          for k in range(ntrial):
              sym = make_mirror_plan_to_layer(
                  sym,
                  layer_name=layer_name,
                  threshold=threshold,
                  plan_info=info,
                  **kwargs,
              )
              cost = get_cost(sym, type_dict, **kwargs)
              print(
                  "Search threshold=%d MB, cost=%d MB"
                  % (threshold, cost)
              )
              history.append((cost, threshold, sym))
              threshold += step
  
      history.sort(key=lambda x: x[0])
      cost, threshold, sym = history[0]
      print(
          "Find best plan with threshold=%d, cost=%d MB"
          % (threshold, cost)
      )
      return sym
  
file_path: insightface/recognition/arcface_mxnet/symbol/memonger_v2.py
imports: import mxnet
  import math
label_desc: Use image node_id 7 for calling a global function with example usage: search_plan_to_layer(sym, layer_name, threshold, ntrial, type_dict) and returns: sym