code: def modify_forward(
      model: nn.Module,
      complexity_computer: ComplexityComputer,
      prefix: str = "",
      patch_attr: str = None,
  ) -> nn.Module:
      """
      Modify forward pass to measure a module's parameters, like FLOPs.
      """
      # Recursively update all the modules in the model. A module is patched if it
      # contains the patch_attr (like the flops() function for FLOPs computation) or it is
      # a leaf. We stop recursing if we patch a module since that module is supposed
      # to return the results for all its children as well.
      # Since this recursion can lead to the same module being patched through different
      # paths, we make sure we only patch un-patched modules.
      if hasattr(model, "orig_type"):
          return model
      if is_leaf(model) or (
          patch_attr is not None and hasattr(model, patch_attr)
      ):
          model.__class__ = _patched_computation_module(
              model, complexity_computer, prefix
          )
      else:
          for name, child in model.named_children():
              modify_forward(
                  child,
                  complexity_computer,
                  prefix=f"{prefix}.{name}",
                  patch_attr=patch_attr,
              )
      return model
  
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 7 for calling a global function with example usage: modify_forward(model, complexity_computer, prefix, patch_attr) and returns: model, model