Skip to content

Instantly share code, notes, and snippets.

@abhi1868sharma
Last active August 22, 2020 14:45
Show Gist options
  • Select an option

  • Save abhi1868sharma/1dfd35a6bdc252050a3866954be72cc0 to your computer and use it in GitHub Desktop.

Select an option

Save abhi1868sharma/1dfd35a6bdc252050a3866954be72cc0 to your computer and use it in GitHub Desktop.
import treelite
import treelite_runtime # runtime module
import numpy as np
import time
dim = 100
toolchain = 'gcc'
lgb_path = "/Users/num/gitrepos/blogs/medium/gpu_based_inference/models/lgb_model.txt"
lgb_treelite = treelite.Model.load(lgb_path, model_format='lightgbm')
# save the treelite model to disk + read the treelite model from disk
# predictor is used for prediction at runtime
path_lgb_treelite = '/Users/num/gitrepos/blogs/medium/gpu_based_inference/models/lgb_model.dylib'
model.export_lib(toolchain=toolchain, libpath=path_lgb_treelite, verbose=True,params={'parallel_comp': 6} )
predictor_lgb = treelite_runtime.Predictor(path_lgb_treelite, verbose=True)
# treelite model performance
start = time.perf_counter()
for _ in range(10000):
predictor_lgb.predict(treelite_runtime.Batch.from_npy2d(np.random.rand(1,100)))
print(1000 * (time.perf_counter() - start)) # time in ms
# lightgbm model performance
import lightgbm as lgb
clf = lgb.Booster(model_file=lgb_path)
start = time.perf_counter()
for _ in range(10000):
clf.predict(np.random.rand(1,100))
print(1000 * (time.perf_counter() - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment