code: def build_group_dependency(graph_module: torch.fx.GraphModule):
      """
      This model analyze the group dependencis between the conv
      layers in a model.
  
      Parameters
      ----------
      graph_module : torch.fx.GraphModule
          The target graph and module.
  
      Returns
      -------
      dependency : Dict
          The group dependency for the target graph.
      """
      graph = graph_module.graph
      dependency = dict()
      groups = dict()
  
      for node in graph.nodes:
          node: torch.fx.Node
          d_set = set()
  
          # Build the channel dependency for the conv layers in the model.
          # This function return the group number of each conv layers. Note
          # that, here, the group count of conv layers may be larger than
          # their originl groups. This is because that the input channel
          # will also be grouped for the group conv layers. To make this
          # clear, assume we have two group conv layers: conv1(group=2),
          # conv2(group=4). conv2 takes the output features of conv1 as input.
          # Then we have to the filters of conv1 can still be divided into
          # 4 groups after filter pruning, because the input channels of
          # conv2 should be divided into 4 groups.
  
          if node.op == "call_module":
              num_groups = 0
              submodule = graph_module.get_submodule(node.target)
              if isinstance(
                  submodule, (torch.nn.Conv2d, torch.nn.ConvTranspose2d)
              ):
                  # depthwise conv will not introduce extra group dependency
                  num_groups = (
                      submodule.groups
                      if submodule.groups != submodule.out_channels
                      else 1
                  )
              elif isinstance(submodule, torch.nn.GroupNorm):
                  num_groups = submodule.num_groups
              else:
                  continue
  
              groups[node] = groups.get(node, []) + [num_groups]
  
              if num_groups > 1:
                  # for the conv layer whose group is larger than 1, it will require the number
                  # of output channels of their parent conv layer to be divisible by group.
                  d_set = find_adjacent_layers(
                      node,
                      graph_module,
                      [
                          torch.nn.Conv2d,
                          torch.nn.ConvTranspose2d,
                          torch.nn.Linear,
                      ],
                      "parent",
                  )
                  for parent in d_set:
                      groups[parent] = groups.get(parent, []) + [
                          num_groups
                      ]
  
      for node in groups:
          group_max = lcm_list(groups[node])
          group_min = (
              gcd_list(groups[node])
              if min(groups[node]) == gcd_list(groups[node])
              else 1
          )
  
          if group_max == 1 and group_min == 1:
              continue
  
          dependency[node] = (group_max, group_min)
      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 9 for calling a global function with example usage: build_group_dependency(graph_module) and returns: dependency