code: def _find_nested_ckpt_regions(nodes, check_idx=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(nodes):
          if "activation_checkpoint" in node.meta:
              if isinstance(node.meta["activation_checkpoint"], int):
                  act_ckpt_label = node.meta["activation_checkpoint"]
              else:
                  act_ckpt_label = node.meta["activation_checkpoint"][
                      check_idx
                  ]
  
              # 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, check_idx
          ):
              # 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(nodes) - 1
          ckpt_regions.append((start, end))
      return ckpt_regions
  
file_path: colossalai/colossalai/fx/codegen/activation_checkpoint_codegen.py
imports: from typing import Any, Dict, Iterable, List, Tuple
  import torch
  import colossalai
label_desc: Use image node_id 11 for calling a global function with example usage: _find_nested_ckpt_regions(nodes, check_idx) and returns: ckpt_regions