code: def test_mmdetection(config_file: str):
      torch.cuda.empty_cache()
  
      folder_prefix = os.environ["MMDET_DIR"]
  
      # Specify the path to model config and checkpoint file
      config = Config.fromfile(
          folder_prefix + "/configs/" + config_file + ".py"
      )
  
      # RoIAlign will cause many errors. there are 4 ways to avoid it
      # 1. add 'mmcv_ops.RoIAlign' to leaf_module when tracing, and set 'config_dict['use_torchvision'] = True' recursively
      # 2. add 'mmcv_ops.RoIAlign' to leaf_module when tracing, and set 'config_dict['aligned'] = False' recursively
      # 3. set 'config_dict['use_torchvision'] = True', and set 'config_dict['aligned'] = False' recursively, and
      #            from torchvision.ops import roi_align as tv_roi_align
      #            add 'tv_roi_align: (((torchvision.ops, 'roi_align'),), False, None),' to autowrap_leaf_function
      # 4. set 'config_dict['aligned'] = False' recursively, and add 'from mmcv.ops.roi_align import roi_align as mmcv_roi_align' and
      #            add 'mmcv_roi_align: ((), False, None),' to autowrap_leaf_function
      RoIAlign_solution = 3
  
      def roi_align_setter(config_dict: dict):
          if "type" in config_dict:
              if config_dict["type"] == "RoIAlign":
                  if RoIAlign_solution in (1, 3):
                      config_dict["use_torchvision"] = True
                  if RoIAlign_solution in (2, 3, 4):
                      config_dict["aligned"] = False
                  pass
              else:
                  for v in config_dict.values():
                      if isinstance(v, dict):
                          roi_align_setter(v)
  
      roi_align_setter(config._cfg_dict["model"])
  
      leaf_module_append = ()
      if RoIAlign_solution in (1, 2, 3):
          from mmcv import ops as mmcv_ops
  
          leaf_module_append = (mmcv_ops.RoIAlign,)
  
      model = init_detector(config, device=device)
  
      with torch.no_grad():
          packed_inputs = demo_mm_inputs()
  
          dummy_inputs = model.data_preprocessor(packed_inputs, False)
  
          # init run
          # some models need to be run 2 times before doing trace
          model.forward(**dummy_inputs)
          model.forward(**dummy_inputs)
  
          seed = torch.seed()
          torch.manual_seed(seed)
          out_orig_1 = model.forward(**dummy_inputs)
          torch.manual_seed(seed)
          out_orig_2 = model.forward(**dummy_inputs)
          assert check_equal(
              out_orig_1, out_orig_2
          ), "check_equal failure for original model"
          del out_orig_1, out_orig_2
  
          if config_file == "pvt/retinanet_pvt-l_fpn_1x_coco":
              # to support numpy.intc
              import torch.fx as torch_fx
              from numpy import intc, int64
  
              orig_base_types = torch_fx.proxy.base_types
              torch_fx.proxy.base_types = (
                  *torch_fx.proxy.base_types,
                  intc,
                  int64,
              )
  
          traced_model = concrete_trace(
              model,
              dummy_inputs,
              use_operator_patch=True,
              forward_function_name="forward",
              autowrap_leaf_function={
                  **ConcreteTracer.default_autowrap_leaf_function,
                  all: ((), False, None),
                  min: ((), False, None),
                  max: ((), False, None),
              },
              autowrap_leaf_class={
                  **ConcreteTracer.default_autowrap_leaf_class,
                  int: ((), False),
                  reversed: ((), False),
                  torch.Size: ((), False),
              },
              leaf_module=(
                  *leaf_module_append,
                  mmcv_cnn.bricks.wrappers.Conv2d,
                  mmcv_cnn.bricks.wrappers.Conv3d,
                  mmcv_cnn.bricks.wrappers.ConvTranspose2d,
                  mmcv_cnn.bricks.wrappers.ConvTranspose3d,
                  mmcv_cnn.bricks.wrappers.Linear,
                  mmcv_cnn.bricks.wrappers.MaxPool2d,
                  mmcv_cnn.bricks.wrappers.MaxPool3d,
              ),
              fake_middle_class=(
                  mmdet_models.task_modules.prior_generators.AnchorGenerator,
              ),
          )
  
          if config_file == "pvt/retinanet_pvt-l_fpn_1x_coco":
              torch_fx.proxy.base_types = orig_base_types
  
          seed = torch.seed()
          torch.manual_seed(seed)
          out_orig = model.forward(**dummy_inputs)
          torch.manual_seed(seed)
          out_orig_traced = traced_model(**dummy_inputs)
          assert check_equal(
              out_orig, out_orig_traced
          ), "check_equal failure in original inputs"
          del out_orig, out_orig_traced
  
file_path: nni/test/algo/compression/pruning/test_concrete_trace_mmdetection.py
imports: import pytest
  import os
  import torch
  import mmcv.cnn
  import mmdet.models
  from mmdet.apis import init_detector
  from mmdet.testing import demo_mm_inputs, get_detector_cfg
  from mmengine import Config
  from nni.common.concrete_trace_utils import concrete_trace, ConcreteTracer
label_desc: Use image node_id 2 for calling a global function with example usage: test_mmdetection(config_file) without return types