我在Google Colab上使用CUML 0.10.0库中的随机森林回归模型进行模型预测时遇到了问题。模型训练成功结束后,我使用(.predict)方法对一个大小为(41697600, 11)的超大数组进行推理。然而,我收到了以下错误:
TypeError: GPU predict model only accepts float32 dtype as input, convert the data to float32 or use the CPU predict with `predict_model='CPU'`.
即使将输入的numpy数组的dtype转换为float32,并在predict方法中指定predict_model=’CPU’参数,错误仍然存在。
供您参考,以下是使用的代码:
array=(X_test.values).astype('float32')predictions = cuml_model.predict(array, predict_model='CPU',output_class=False, algo='BATCH_TREE_REORG')
模型摘要:
<bound method RandomForestRegressor.print_summary of RandomForestRegressor(n_estimators=10, max_depth=16, handle=<cuml.common.handle.Handle object at 0x7fbfa342e888>, max_features='auto', n_bins=8, n_streams=8, split_algo=1, split_criterion=2, bootstrap=True, bootstrap_features=False, verbose=False, min_rows_per_node=2, rows_sample=1.0, max_leaves=-1, accuracy_metric='mse', quantile_per_tree=False, seed=-1)>
回答:
这个错误信息非常令人困惑。我认为失败的原因是训练使用的是float64而不是float32。如果你改用float32进行训练,应该就可以解决这个问题。当前的GPU预测优化实现仅支持float32模型。你应该可以回退到较慢的CPU预测,但这个异常阻止了这种操作。
我已将此问题报告为一个错误,我们将尝试在即将发布的版本中修复它。您可以继续关注该问题,或者添加任何额外的问题等:https://github.com/rapidsai/cuml/issues/1406