我需要在没有GPU的Windows虚拟机上对cuml.dask.ensemble.RandomForestClassifier进行推理,而该虚拟机上无法安装rapids/cuml。
我考虑使用treelite,因此我需要将模型导入treelite并生成一个共享库(对于Windows是.dll文件)。之后,我会使用treelite_runtime.Predictor导入共享库,并在目标机器上执行推理。
问题是我不知道如何将RandomForestClassifier模型导入treelite以创建一个treelite模型。
我尝试使用’convert_to_treelite_model’,但得到的对象并不是一个treelite模型,我不知道如何使用它。
请查看附件代码(在Linux下执行,所以我尝试使用gcc工具链并生成一个’.so’文件…)
当我尝试调用’export_lib’函数时,我得到异常”‘cuml.fil.fil.TreeliteModel’ object has no attribute ‘export_lib'”…
备注:我尝试在装有2个NVIDIA RTX2080ti GPU的Ubuntu机器上运行代码,使用以下库版本:
cudatoolkit 10.1.243cudnn 7.6.0cudf 0.15.0cuml 0.15.0dask 2.30.0 dask-core 2.30.0 dask-cuda 0.15.0 dask-cudf 0.15.0 rapids 0.15.1treelite 0.92treelite-runtime 0.92
回答:
目前Treelite没有可以直接使用的序列化方法。我们使用内部序列化方法来pickle cuML的RF模型。
我建议在Treelite的GitHub仓库(https://github.com/dmlc/treelite)中创建一个功能请求,并请求添加序列化和反序列化Treelite模型的功能。
此外,convert_to_treelite_model
函数的输出是一个Treelite模型。它显示为:
In [2]: treelite_modelOut[2]: <cuml.fil.fil.TreeliteModel at 0x7f11ceeca840>
因为我们通过cython暴露了C++ Treelite代码,以便直接访问Treelite的C++句柄。