Closed sdqdsjf1999 closed 8 months ago
我们在0.1.3版本中加入了对CPU二进制模型的支持,可以尝试使用以下方法来载入使用GPU完成训练的模型,并使用CPU进行预测:
gnnwr = models.GNNWR(train_dataset, val_dataset, test_dataset, [256, 64, 16])
gnnwr.gpumodel_to_cpu('../gnnwr-models/GNNWR_20231027-000000.pkl', '../gnnwr-models/GNNWR_CPU.pkl')
gnnwr.load_model('../gnnwr_models/GNNWR_CPU.pkl', map_location='cpu', use_dict=True)
gnnwr.result('../gnnwr_models/GNNWR_CPU.pkl', map_location='cpu', use dict=True)
我事先使用GPU跑出来模型的结果保存为模型文件 再在只有CPU的设备上使用load_model加载路径上的模型文件并预测模型结果 在执行predict()方法之后,报错有变量在cuda而不是cpu上 以下是我的代码
报错信息如下: /home/induschain/anaconda3/lib/python3.9/site-packages/gnnwr/utils.py:26: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use
res = GTNNWR_ind.predict(pred_dataset)
File "/home/induschain/anaconda3/lib/python3.9/site-packages/gnnwr/models.py", line 398, in predict
output = self._out(self._model(data).mul(coef.to(torch.float32)))
File "/home/induschain/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, *kwargs)
File "/home/induschain/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(args, **kwargs)
File "/home/induschain/anaconda3/lib/python3.9/site-packages/torch/nn/parallel/data_parallel.py", line 171, in forward
raise RuntimeError("module must have its parameters and buffers "
RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu
ser.iloc[pos]
intercept = self.__fit.params[0] Traceback (most recent call last): File "/home/induschain/zju/sjf/GNNWR/predict_test.py", line 23, in