class_docstr: Transformation that merges linear layers that take the same input into one big linear layer.
class_docstr_tok: ["Transformation","that","merges","linear","layers","that","take","the","same","input","into","one","big","linear","layer","."]
code: def transform(self, graph_module: "GraphModule") -> "GraphModule":
      candidates = collections.defaultdict(list)
      for node in graph_module.graph.nodes:
          if node.op == "call_module":
              mod = graph_module.get_submodule(node.target)
              if isinstance(mod, torch.nn.Linear):
                  input_node = node.args[0]
                  candidates[input_node].append((node, mod))
  
      # Only keep the candidates with more than one linear and the ones with the same number of
      # output features.
      candidates = {k: v for k, v in candidates.items() if len(v) > 1}
  
      for input_node, t in candidates.items():
          linear_nodes, linears = list(zip(*t))
          self._merge_linears(
              graph_module, input_node, linear_nodes, linears
          )
  
      return graph_module
  
imports: import collections
  import copy
  import functools
  import itertools
  import operator
  import warnings
  from abc import ABC, abstractmethod
  from typing import TYPE_CHECKING, List
  import torch
  from transformers.file_utils import add_end_docstrings
  from transformers.utils.fx import _gen_constructor_wrapper
label_desc: Use image node_id 6 for calling the MergeLinears obj's underlying member method code with example usage: obj.transform(graph_module) and returns: graph_module