code: def build_reshape_dependency(graph_module: torch.fx.GraphModule):
      """
      Some model may have the view/reshape functions, such functions may have fixed parameters
      and cannot be replaced at all. Therefore, these functions may have some constraints on
      their input shapes. In this class, we find the direct input conv/linear layers of these
      reshape functions. If you get the shape conflict when run the forward inference on the
      speeduped model, please try remove these layers from the pruner config list and try again.
      """
  
      graph = graph_module.graph
      dependency = dict()
  
      for node in graph.nodes:
          parent_layers = []
          # find the node that contains the reshape-like function
          if node.op == "call_function" and node.target in [
              torch.narrow,
              torch.reshape,
          ]:
              logger.info(
                  f"Detect reshape-like functions: {node.target}, args = {node.args}, kwargs = {node.kwargs}"
              )
              parent_layers = find_adjacent_layers(
                  node,
                  graph_module,
                  [
                      torch.nn.Conv2d,
                      torch.nn.ConvTranspose2d,
                      torch.nn.Linear,
                  ],
                  "parent",
              )
              dependency[node] = parent_layers
          elif node.op == "call_method" and node.target in [
              "narrow",
              "reshape",
              "view",
          ]:
              logger.info(
                  f"Detect reshape-like methods: {node.target}, args = {node.args}, kwargs = {node.kwargs}"
              )
              parent_layers = find_adjacent_layers(
                  node,
                  graph_module,
                  [
                      torch.nn.Conv2d,
                      torch.nn.ConvTranspose2d,
                      torch.nn.Linear,
                  ],
                  "parent",
              )
              dependency[node] = parent_layers
      return dependency
  
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 10 for calling a global function with example usage: build_reshape_dependency(graph_module) and returns: dependency