code: def _find_ckpt_regions(nodes: List[Node]):
      """
      Find the 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:
              act_ckpt_label = node.meta["activation_checkpoint"]
  
              # 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 not "activation_checkpoint" in node.meta
          ):
              # 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
      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 5 for calling a global function with example usage: _find_ckpt_regions(nodes) and returns: ckpt_regions