code: def compute_complexity(
      model: nn.Module,
      compute_fn: Callable,
      input_shape: Tuple[int],
      input_key: Optional[Union[str, List[str]]] = None,
      patch_attr: str = None,
      compute_unique: bool = False,
  ) -> int:
      """
      Compute the complexity of a forward pass.
  
      Args:
          compute_unique: If True, the compexity for a given module is only calculated
              once. Otherwise, it is counted every time the module is called.
  
      TODO(@mannatsingh): We have some assumptions about only modules which are leaves
          or have patch_attr defined. This should be fixed and generalized if possible.
      """
      # assertions, input, and upvalue in which we will perform the count:
      assert isinstance(model, nn.Module)
  
      if not isinstance(input_shape, abc.Sequence) and not isinstance(
          input_shape, dict
      ):
          return None
      else:
          input = get_model_dummy_input(model, input_shape, input_key)
  
      complexity_computer = ComplexityComputer(
          compute_fn, compute_unique
      )
  
      # measure FLOPs:
      modify_forward(model, complexity_computer, patch_attr=patch_attr)
      try:
          # compute complexity in eval mode
          with eval_model(model), torch.no_grad():
              model.forward(input)
      finally:
          restore_forward(model, patch_attr=patch_attr)
  
      return complexity_computer.count
  
imports: import collections.abc
  import logging
  import operator
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from classy_vision.generic.util import eval_model, get_batchsize_per_replica, get_model_dummy_input, is_leaf, is_on_gpu
  from torch.cuda import cudart
label_desc: Use image node_id 9 for calling a global function with example usage: compute_complexity(model, compute_fn, input_shape, input_key, patch_attr, compute_unique) and returns: complexity_computer, None