code: def benchmark_times(plays, iterations=3):
      times = defaultdict(lambda: defaultdict(list))
  
      def store_time(model, name):
          def inner(iteration, elapsed, loss):
              print(name, model.factors, iteration, elapsed)
              times[name][model.factors].append(elapsed)
  
          return inner
  
      output = defaultdict(list)
      for factors in range(32, 257, 32):
          for steps in [2, 3, 4]:
              model = AlternatingLeastSquares(
                  factors=factors,
                  use_native=True,
                  use_cg=True,
                  use_gpu=False,
                  regularization=0,
                  iterations=iterations,
              )
              model.fit_callback = store_time(model, f"cg{steps}")
              model.cg_steps = steps
              model.fit(plays)
  
          model = AlternatingLeastSquares(
              factors=factors,
              use_native=True,
              use_cg=False,
              regularization=0,
              iterations=iterations,
              use_gpu=False,
          )
          model.fit_callback = store_time(model, "cholesky")
          model.fit(plays)
  
          if HAS_CUDA:
              model = AlternatingLeastSquares(
                  factors=factors,
                  use_native=True,
                  use_gpu=True,
                  regularization=0,
                  iterations=iterations,
              )
              model.fit_callback = store_time(model, "gpu")
              model.fit(plays)
  
          # take the min time for the output
          output["factors"].append(factors)
          for name, stats in times.items():
              output[name].append(min(stats[factors]))
  
      return output
  
file_path: implicit/benchmarks/benchmark_als.py
imports: import argparse
  import json
  import logging
  from collections import defaultdict
  import matplotlib.pyplot
  import scipy.io
  import seaborn
  from implicit.als import AlternatingLeastSquares
  from implicit.gpu import HAS_CUDA
  from implicit.nearest_neighbours import bm25_weight
label_desc: Use image node_id 2 for calling a global function with example usage: benchmark_times(plays, iterations) and returns: output, inner