code: def select_single_mlvl(mlvl_tensors, batch_id, detach=True):
      """Extract a multi-scale single image tensor from a multi-scale batch
      tensor based on batch index.
  
      Note: The default value of detach is True, because the proposal gradient
      needs to be detached during the training of the two-stage model. E.g
      Cascade Mask R-CNN.
  
      Args:
          mlvl_tensors (list[Tensor]): Batch tensor for all scale levels,
             each is a 4D-tensor.
          batch_id (int): Batch index.
          detach (bool): Whether detach gradient. Default True.
  
      Returns:
          list[Tensor]: Multi-scale single image tensor.
      """
      assert isinstance(mlvl_tensors, (list, tuple))
      num_levels = len(mlvl_tensors)
  
      if detach:
          mlvl_tensor_list = [
              mlvl_tensors[i][batch_id].detach()
              for i in range(num_levels)
          ]
      else:
          mlvl_tensor_list = [
              mlvl_tensors[i][batch_id] for i in range(num_levels)
          ]
      return mlvl_tensor_list
  
imports: from functools import partial
  from typing import List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from mmengine.utils import digit_version
  from six.moves import map, zip
  from torch import Tensor
  from torch.autograd import Function
  from torch.nn import functional
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import BaseBoxes, get_box_type, stack_boxes
  from mmdet.structures.mask import BitmapMasks, PolygonMasks
  from mmdet.utils import OptInstanceList
label_desc: Use image node_id 8 for calling a global function with example usage: select_single_mlvl(mlvl_tensors, batch_id, detach) and returns: mlvl_tensor_list