code: def profile_model(
      model,
      profile_name,
      input_ids,
      masks,
      num_batches,
      is_decoder,
      max_token,
      pad_token_id,
  ):
      # Warmup
      gen_config = None
      if is_decoder:
          gen_config = GenerationConfig(
              max_new_tokens=max_token,
              min_new_tokens=max_token,
              use_cache=True,
              pad_token_id=pad_token_id,
          )
          _ = model.generate(
              input_ids,
              attention_mask=masks,
              generation_config=gen_config,
          )
          torch.cuda.synchronize()
  
      else:
          _ = model(input_ids, masks)
          torch.cuda.synchronize()
  
      name = f"{profile_name}_bs={input_ids.shape[0]}_slen={input_ids.shape[1]}_gen={max_token}"
      with profile(
          activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
          record_shapes=True,
          profile_memory=True,
          with_stack=True,
          on_trace_ready=tensorboard_trace_handler("./tb_logs/" + name),
      ):
          for _ in tqdm(range(num_batches)):
              if is_decoder:
                  with record_function("generate"):
                      _ = model.generate(
                          input_ids,
                          attention_mask=masks,
                          generation_config=gen_config,
                      )
              else:
                  _ = model(input_ids, masks)
  
file_path: optimum/tests/benchmark/profile_bettertransformer_t5.py
imports: import argparse
  import torch
  from torch.profiler import ProfilerActivity, profile, record_function, tensorboard_trace_handler
  from tqdm import tqdm
  from transformers import AutoModel, AutoModelForCausalLM, AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig
  from optimum.bettertransformer import BetterTransformer
  from optimum.exporters import TasksManager
label_desc: Use image node_id 3 for calling a global function with example usage: profile_model(model, profile_name, input_ids, masks, num_batches, is_decoder, max_token, pad_token_id) without return types