code: def count_flops_params(
      name: str,
      module: nn.Module,
      shapes: dict[str, tuple[MutableShape, MutableShape]],
      config: FlopsParamsCounterConfig,
  ) -> FlopsResult:
      """
      Count FLOPs of a module.
  
      Firstly check whether the type of module is in FLOPs formula registry.
      If not, traverse its children and sum up the FLOPs of each child.
  
      Parameters
      ----------
      name
          Name of the module.
      module
          The module to count FLOPs.
      shapes
          Input and output shapes of all the modules.
          Should at least contain ``name``.
  
      Returns
      -------
      flops
          The FLOPs of the module.
      """
      formula = find_flops_formula(module)
  
      if formula is not None:
          if name not in shapes:
              raise KeyError(
                  f"Cannot find shape of {name} in shapes. This could be caused by a shape inference that is too coarse-grained, "
                  f"or the module did not appear in the forward at all. Existing modules are:\n  {list(shapes.keys())}"
              )
  
          # We provide arguments to the formula when they need them.
          formula_kwargs = {}
          if argument_in_spec(formula, "name"):
              formula_kwargs["name"] = name
          if argument_in_spec(formula, "shapes"):
              formula_kwargs["shapes"] = shapes
          if argument_in_spec(formula, "config"):
              formula_kwargs["config"] = config
          for field in fields(config):
              if argument_in_spec(formula, field.name):
                  formula_kwargs[field.name] = getattr(
                      config, field.name
                  )
  
          rv = formula(module, *shapes[name], **formula_kwargs)
          _logger.debug("FLOPs of %s counts to: %s", name, rv)
          return rv
  
      else:
          children_flops = [
              count_flops_params(
                  concat_name(name, n), child, shapes, config
              )
              for n, child in module.named_children()
          ]
          if children_flops:
              rv = sum(children_flops)
              _logger.debug("FLOPs of %s sums up to be: %r", name, rv)
              return cast(FlopsResult, rv)
          else:
              # Leaf module. No children.
              if type(module) not in _unlisted_types:
                  _logger.warning(
                      "Parameters and FLOPs of %s is not counted because it has no children (name: %s).",
                      type(module).__name__,
                      name,
                  )
                  _unlisted_types.add(type(module))
              return FlopsResult(0.0, 0.0)
  
imports: from __future__ import annotations
  import logging
  from dataclasses import dataclass, fields
  from functools import partial, reduce
  from typing import Any, NamedTuple, Callable, cast
  from torch import nn
  import nni.nas.nn.pytorch
  from nni.mutable import Sample, Mutable, MutableExpression
  from nni.nas.nn.pytorch import ModelSpace
  from nni.nas.profiler import Profiler, ExpressionProfiler
  from .utils import MutableShape, ShapeTensor, submodule_input_output_shapes, standardize_arguments, argument_in_spec, concat_name
  from .utils._attrs import tuple_n_t, _getattr
label_desc: Use image node_id 1 for calling a global function with example usage: count_flops_params(name, module, shapes, config) and returns: rv, cast, FlopsResult