code: def test_predict_per_tree(
      train_device, infer_device, n_classes, num_boost_round, tmp_path
  ):
      n_rows = 1000
      n_columns = 30
  
      with using_device_type(train_device):
          X, y = simulate_data(
              n_rows,
              n_columns,
              n_classes,
              random_state=0,
              classification=True,
          )
  
          model_path = os.path.join(tmp_path, "xgb_class.model")
  
          xgboost_params = {
              "base_score": (0.5 if n_classes == 2 else 0.0)
          }
          bst = _build_and_save_xgboost(
              model_path,
              X,
              y,
              num_rounds=num_boost_round,
              classification=True,
              n_classes=n_classes,
              xgboost_params=xgboost_params,
          )
          fm = ForestInference.load(model_path, output_class=True)
          tl_model = treelite.Model.from_xgboost(bst)
          pred_per_tree_tl = treelite.gtil.predict_per_tree(tl_model, X)
  
      with using_device_type(infer_device):
          pred_per_tree = fm.predict_per_tree(X)
          margin_pred = bst.predict(xgb.DMatrix(X), output_margin=True)
          if n_classes == 2:
              expected_shape = (n_rows, num_boost_round)
              sum_by_class = np.sum(pred_per_tree, axis=1)
          else:
              expected_shape = (n_rows, num_boost_round * n_classes)
              sum_by_class = np.column_stack(
                  tuple(
                      np.sum(
                          pred_per_tree[:, class_id::n_classes], axis=1
                      )
                      for class_id in range(n_classes)
                  )
              )
          fm.optimize(
              batch_size=len(X), predict_method="predict_per_tree"
          )
          pred_per_tree_opt = fm.predict_per_tree(X)
          assert pred_per_tree.shape == expected_shape
          np.testing.assert_almost_equal(
              sum_by_class, margin_pred, decimal=3
          )
          np.testing.assert_almost_equal(
              pred_per_tree, pred_per_tree_tl, decimal=3
          )
          np.testing.assert_almost_equal(
              pred_per_tree_opt, pred_per_tree, decimal=3
          )
  
imports: import numpy
  import pytest
  import os
  import pandas
  from math import ceil
  from cuml.experimental import ForestInference
  from cuml.testing.utils import array_equal, unit_param, quality_param, stress_param
  from cuml.internals.import_utils import has_lightgbm, has_xgboost
  from cuml.common.device_selection import using_device_type
  from sklearn.datasets import make_classification, make_regression
  from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor, RandomForestClassifier, RandomForestRegressor, ExtraTreesClassifier, ExtraTreesRegressor
  from sklearn.metrics import accuracy_score, mean_squared_error
  from sklearn.model_selection import train_test_split
  import treelite
label_desc: Use image node_id 13 for calling a global function with example usage: test_predict_per_tree(train_device, infer_device, n_classes, num_boost_round, tmp_path) without return types