code: def get_flops(
      model, dataset, device, logger, transform, verbose=False
  ):
      r"""Given a model and dataset to the model, compute the per-operator flops
      of the given model.
      Args:
          model: the model to compute flop counts.
          dataset: dataset that are passed to `model` to count flops.
          device: cuda.device. It is the device that the model run on.
          verbose: whether to print information of modules.
  
      Returns:
          total_ops: the number of flops for each operation.
      """
      if model.type == ModelType.DECISIONTREE:
          return 1
      if model.__class__.__name__ == "Pop":
          return 1
  
      import copy
  
      model = copy.deepcopy(model)
  
      def count_normalization(m, x, y):
          x = x[0]
          flops = torch.DoubleTensor([2 * x.numel()])
          m.total_ops += flops
  
      def count_embedding(m, x, y):
          x = x[0]
          nelements = x.numel()
          hiddensize = y.shape[-1]
          m.total_ops += nelements * hiddensize
  
      class TracingAdapter(torch.nn.Module):
          def __init__(self, rec_model):
              super().__init__()
              self.model = rec_model
  
          def forward(self, interaction):
              return self.model.predict(interaction)
  
      custom_ops = {
          torch.nn.Embedding: count_embedding,
          torch.nn.LayerNorm: count_normalization,
      }
      wrapper = TracingAdapter(model)
      inter = dataset[torch.tensor([1])].to(device)
      inter = transform(dataset, inter)
      inputs = (inter,)
      from thop.profile import register_hooks
      from thop.vision.basic_hooks import count_parameters
  
      handler_collection = {}
      fn_handles = []
      params_handles = []
      types_collection = set()
      if custom_ops is None:
          custom_ops = {}
  
      def add_hooks(m: nn.Module):
          m.register_buffer(
              "total_ops", torch.zeros(1, dtype=torch.float64)
          )
          m.register_buffer(
              "total_params", torch.zeros(1, dtype=torch.float64)
          )
  
          m_type = type(m)
  
          fn = None
          if m_type in custom_ops:
              fn = custom_ops[m_type]
              if m_type not in types_collection and verbose:
                  logger.info(
                      "Customize rule %s() %s."
                      % (fn.__qualname__, m_type)
                  )
          elif m_type in register_hooks:
              fn = register_hooks[m_type]
              if m_type not in types_collection and verbose:
                  logger.info(
                      "Register %s() for %s."
                      % (fn.__qualname__, m_type)
                  )
          else:
              if m_type not in types_collection and verbose:
                  logger.warning(
                      "[WARN] Cannot find rule for %s. Treat it as zero Macs and zero Params."
                      % m_type
                  )
  
          if fn is not None:
              handle_fn = m.register_forward_hook(fn)
              handle_paras = m.register_forward_hook(count_parameters)
              handler_collection[m] = (
                  handle_fn,
                  handle_paras,
              )
              fn_handles.append(handle_fn)
              params_handles.append(handle_paras)
          types_collection.add(m_type)
  
      prev_training_status = wrapper.training
  
      wrapper.eval()
      wrapper.apply(add_hooks)
  
      with torch.no_grad():
          wrapper(*inputs)
  
      def dfs_count(module: nn.Module, prefix="\t"):
          total_ops, total_params = module.total_ops.item(), 0
          ret_dict = {}
          for n, m in module.named_children():
              next_dict = {}
              if m in handler_collection and not isinstance(
                  m, (nn.Sequential, nn.ModuleList)
              ):
                  m_ops, m_params = (
                      m.total_ops.item(),
                      m.total_params.item(),
                  )
              else:
                  m_ops, m_params, next_dict = dfs_count(
                      m, prefix=prefix + "\t"
                  )
              ret_dict[n] = (m_ops, m_params, next_dict)
              total_ops += m_ops
              total_params += m_params
  
          return total_ops, total_params, ret_dict
  
      total_ops, total_params, ret_dict = dfs_count(wrapper)
  
      # reset wrapper to original status
      wrapper.train(prev_training_status)
      for m, (op_handler, params_handler) in handler_collection.items():
          m._buffers.pop("total_ops")
          m._buffers.pop("total_params")
      for i in range(len(fn_handles)):
          fn_handles[i].remove()
          params_handles[i].remove()
  
      return total_ops
  
imports: import datetime
  import importlib
  import os
  import random
  import pandas
  import numpy
  import torch
  import torch.nn
  from torch.utils.tensorboard import SummaryWriter
  from texttable import Texttable
  from recbole.utils.enum_type import ModelType
label_desc: Use image node_id 11 for calling a global function with example usage: get_flops(model, dataset, device, logger, transform, verbose) and returns: total_ops, int, int, total_ops,  total_params,  ret_dict, self