code: def find_adjacent_layers(
      node: torch.fx.Node,
      module: torch.fx.GraphModule,
      target_types: List[torch.nn.Module],
      direction: str = "parent",
  ) -> List[torch.fx.Node]:
      """
      Find the nearest layers of `target_types` in module for the target node given search direction.
  
      Parameters
      ---------
      node : torch.fx.Node
          The target node.
      module : torch.fx.GraphModule
          The model to be analyzed.
      target_types : list
          The target types of the father layers.
      direction : str
          The search direction, 'parent' or 'child'.
  
      Returns
      -------
      parent_layers: list
          The nearest father conv/linear layers for the target worknode.
      """
  
      layers = []
      if direction == "parent":
          nodes = node.all_input_nodes
      elif direction == "child":
          nodes = node.users
      else:
          raise ValueError(
              "search direction should be 'parent' or 'child'"
          )
  
      for node in nodes:
          if node.op == "call_module":
              target_module = module.get_submodule(node.target)
              if isinstance(target_module, tuple(target_types)):
                  layers.append(node)
                  continue
          elif channel_dependency_breakpoint(node):
              continue
          layers.extend(
              find_adjacent_layers(
                  node, module, target_types, direction
              )
          )
      return layers
  
file_path: nni/nni/compression/speedup/dependency.py
imports: import logging
  import operator
  from copy import deepcopy
  from typing import Any, Dict, List, Set
  from uuid import uuid4
  import numpy
  import torch
  import torch.fx
  from torch.fx.passes.shape_prop import TensorMetadata
  from nni.compression.base.config import trans_legacy_config_list, select_modules_by_config
label_desc: Use image node_id 4 for calling a global function with example usage: find_adjacent_layers(node, module, target_types, direction) and returns: layers