code: def _rnn_flops(
      flops: int,
      macs: int,
      module: torch.nn.RNNBase,
      w_ih: torch.Tensor,
      w_hh: torch.Tensor,
  ) -> Tuple[int, int]:
      # copied from https://github.com/sovrasov/flops-counter.pytorch/blob/master/ptflops/pytorch_ops.py
  
      # matrix matrix mult ih state and internal state
      macs += reduce(operator.mul, w_ih.shape)
      flops += 2 * reduce(operator.mul, w_ih.shape)
      # matrix matrix mult hh state and internal state
      macs += reduce(operator.mul, w_hh.shape)
      flops += 2 * reduce(operator.mul, w_hh.shape)
      if isinstance(module, (torch.nn.RNN, torch.nn.RNNCell)):
          # add both operations
          flops += module.hidden_size
      elif isinstance(module, (torch.nn.GRU, torch.nn.GRUCell)):
          # hadamard of r
          flops += module.hidden_size
          # adding operations from both states
          flops += module.hidden_size * 3
          # last two hadamard product and add
          flops += module.hidden_size * 3
      elif isinstance(module, (torch.nn.LSTM, torch.nn.LSTMCell)):
          # adding operations from both states
          flops += module.hidden_size * 4
          # two hadamard product and add for C state
          flops += module.hidden_size * 3
          # final hadamard
          flops += module.hidden_size * 3
      return flops, macs
  
file_path: ColossalAI/colossalai/fx/profiler/experimental/profiler_module/rnn.py
imports: import operator
  from functools import reduce
  from typing import Optional, Tuple
  import torch
  from ..registry import meta_profiler_module
label_desc: Use image node_id 1 for calling a global function with example usage: _rnn_flops(flops, macs, module, w_ih, w_hh) and returns: flops,  macs