code: def _find_nested_ckpt_regions(
      node_list: List[Node], ckpt_level: int = 0
  ):
      """
      Find the nested checkpoint regions given a list of consecutive nodes. The outputs
      will be list of tuples, each tuple is in the form of (start_index, end_index).
      """
      ckpt_regions = []
      start = -1
      end = -1
      current_region = None
  
      for idx, node in enumerate(node_list):
          if len(node.meta["info"].activation_checkpoint) > ckpt_level:
              act_ckpt_label = node.meta["info"].activation_checkpoint[
                  ckpt_level
              ]
  
              # this activation checkpoint label is not set yet
              # meaning this is the first node of the activation ckpt region
              if current_region is None:
                  current_region = act_ckpt_label
                  start = idx
  
              # if activation checkpoint has changed
              # we restart the tracking
              # e.g. node ckpt states = [ckpt1, ckpt2, ckpt2, ckpt2]
              if act_ckpt_label != current_region:
                  assert start != -1
                  ckpt_regions.append((start, idx - 1))
                  current_region = act_ckpt_label
                  start = idx
                  end = -1
  
          elif current_region is not None and _end_of_ckpt(
              node, ckpt_level
          ):
              # used to check the case below
              # node ckpt states = [ckpt, ckpt, non-ckpt]
              end = idx - 1
              assert start != -1 and end != -1
              ckpt_regions.append((start, end))
              start = end = -1
              current_region = None
  
          else:
              pass
  
      if current_region is not None:
          end = len(node_list) - 1
          ckpt_regions.append((start, end))
      return ckpt_regions
  
file_path: colossalai/colossalai/_analyzer/fx/codegen.py
imports: from typing import Any, Dict, List, Tuple
  import torch
  from torch.fx.graph import PythonCode, _custom_builtins, _format_target, _is_from_torch, _Namespace, _origin_type_map, _register_custom_builtin, inplace_methods, magic_methods
  from torch.fx.node import Argument, Node, _get_qualified_name, _type_repr, map_arg
  import colossalai
  from colossalai.fx._compatibility import compatibility
label_desc: Use image node_id 6 for calling a global function with example usage: _find_nested_ckpt_regions(node_list, ckpt_level) and returns: ckpt_regions