Skip to content

Instantly share code, notes, and snippets.

@RAMitchell
Created May 19, 2020 03:01
Show Gist options
  • Select an option

  • Save RAMitchell/e484cbec9a4edb5b5c04d61070a4490f to your computer and use it in GitHub Desktop.

Select an option

Save RAMitchell/e484cbec9a4edb5b5c04d61070a4490f to your computer and use it in GitHub Desktop.
import cupy as cp
import GPUtil
import xgboost as xgb
import time
print("Xgboost version: {}".format(xgb.__version__))
n_train = 10000
n_test = 1000
iterations = 20
m = 100
X = cp.random.randn(n_train, m)
X_test = [cp.random.randn(n_test, m) for i in range(iterations)]
y = cp.random.randn(n_train)
dtrain = xgb.DeviceQuantileDMatrix(X, y)
# Train a regression model
bst = xgb.train({
'tree_method': 'gpu_hist'}, dtrain, 100)
# Standard prediction
start = time.time()
for i in range(iterations):
pred = bst.predict(xgb.DMatrix(X_test[i]))
print("Standard prediction took: {}".format(time.time() - start))
start = time.time()
# In place prediction
for i in range(iterations):
pred = bst.inplace_predict(X_test[i])
print("Inplace prediction took: {}".format(time.time() - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment