code: def benchmark(args, dataset_folder, model_folder, dataset):
      warnings.filterwarnings("ignore")
      data = prepare_dataset(dataset_folder, dataset, args.nrows)
      results = {}
      args.dataset = dataset
      operators = args.operator
      if operators == "all":
          operators = "rf,lgbm,xgb"
      for op in operators.split(","):
          print("Running '%s' ..." % op)
          results[op] = {}
          model_name = (
              op
              + "-"
              + str(args.ntrees)
              + "-"
              + str(args.max_depth)
              + "-"
              + str(args.cpus)
          )
          model_full_name = os.path.join(
              model_folder, model_name + ".pkl"
          )
          trainer = train.TrainEnsembleAlgorithm.create(
              op, data.learning_task
          )
          if args.batch_benchmark:
              test_size = args.batch_size
          else:
              test_size = data.X_test.shape[0]
  
          X_test = get_data(data.X_test, size=test_size)
          y_test = get_data(data.y_test, size=test_size)
  
          with trainer:
              if not os.path.exists(model_full_name):
                  train_time = trainer.fit(data, args)
                  pred = trainer.test(X_test)
                  results[op] = {
                      "train_time": str(train_time),
                      "train_accuracy": str(
                          get_metrics(y_test, pred, data.learning_task)
                      ),
                  }
                  model = trainer.model
                  if not os.path.exists(model_folder):
                      os.makedirs(model_folder)
                  pickle.dump(
                      model, open(model_full_name, "wb"), protocol=4
                  )
              else:
                  model = pickle.load(open(model_full_name, "rb"))
  
              times = []
              mean = 0
              mem = 0
  
              try:
                  for i in range(args.niters):
                      set_alarm(3600)
                      times.append(trainer.predict(model, X_test, args))
                      set_alarm(0)
                  mean = (
                      stats.trim_mean(times, 1 / len(times))
                      if args.niters > 1
                      else times[0]
                  )
                  gc.collect()
                  mem = max(
                      memory_usage(
                          (trainer.predict, (model, X_test, args))
                      )
                  )
              except Exception as e:
                  print(e)
                  pass
  
              results[op].update({"prediction_time": mean})
              results[op].update({"peak_mem": mem})
              outer_ops = args.operator
              args.operator = op
  
              if args.backend == "all":
                  args.backend = (
                      "onnx-ml,hb-pytorch,hb-torchscript,hb-onnx,hb-tvm"
                  )
              if "hb-tvm" in args.backend:
                  assert (
                      tvm_installed
                  ), "To run benchmark with TVM you need to have TVM installed. Either install TVM or remove it from the backends."
              if "hb-onnx" in args.backend:
                  assert (
                      onnx_runtime_installed
                  ), "To run benchmark with ONNX you need to have ONNX runtime installed. Either install ONNX runtime or remove ONNX from the backends."
              if "onnx-ml" in args.backend:
                  assert (
                      onnx_runtime_installed and onnx_ml_tools_installed
                  ), "To run benchmark with ONNX-ML you need to have ONNX runtime and ONNXMLTOOLS installed. Either install ONNX runtime and ONNXMLTOOLS or remove ONNX-ML from the backends."
              for backend in args.backend.split(","):
                  print("Running '%s' ..." % backend)
                  scorer = score.ScoreBackend.create(backend)
                  with scorer:
                      conversion_time = scorer.convert(
                          model,
                          data,
                          X_test,
                          args,
                          os.path.join(model_folder, model_name),
                      )
  
                      times = []
                      prediction_time = 0
  
                      try:
                          for i in range(args.niters):
                              set_alarm(3600)
                              times.append(scorer.predict(X_test))
                              set_alarm(0)
                          prediction_time = (
                              times[0]
                              if args.niters == 1
                              else stats.trim_mean(
                                  times, 1 / len(times)
                              )
                          )
                          gc.collect()
                          mem = max(
                              memory_usage((scorer.predict, (X_test,)))
                          )
                      except Exception as e:
                          print(e)
                          pass
  
                      results[op][backend] = {
                          "conversion_time": str(conversion_time),
                          "prediction_time": str(prediction_time),
                          "peak_mem": str(mem),
                          "is_same_output": "None"
                          if len(trainer.predictions) == 0
                          or scorer is None
                          or scorer.predictions is None
                          else np.allclose(
                              trainer.predictions,
                              scorer.predictions,
                              atol=1e-6,
                          ),
                      }
  
                      print(results[op][backend])
  
                      if args.validate:
                          np.testing.assert_allclose(
                              scorer.predictions,
                              trainer.predictions,
                              rtol=1e-5,
                              atol=1e-6,
                          )
  
              args.operator = outer_ops
      return results
  
imports: import os
  import sys
  import argparse
  import json
  import ast
  import gc
  import psutil
  import signal
  import pickle
  import numpy
  import warnings
  from pathlib import Path
  from scipy import stats
  from memory_profiler import memory_usage
  import benchmarks.trees.train
  import benchmarks.trees.score
  from benchmarks.trees.metrics import get_metrics
  from benchmarks.datasets import prepare_dataset, LearningTask
  from hummingbird.ml._utils import xgboost_installed, lightgbm_installed, sklearn_installed, onnx_ml_tools_installed, onnx_runtime_installed, tvm_installed
label_desc: Use image node_id 8 for calling a global function with example usage: benchmark(args, dataset_folder, model_folder, dataset) and returns: results