fastllm icon indicating copy to clipboard operation
fastllm copied to clipboard

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Open ArtificialZeng opened this issue 1 year ago • 2 comments

Traceback (most recent call last): File "/home/zengzijian/ai_code/fastllm/build/tools/baichuan2flm.py", line 18, in torch2flm.tofile(exportPath, model, tokenizer, dtype = dtype) File "/home/zengzijian/ai_code/fastllm/build/tools/fastllm_pytools/torch2flm.py", line 156, in tofile cur = dict[key].numpy().astype(ori_np_data_type) TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

ArtificialZeng avatar Aug 09 '23 15:08 ArtificialZeng

这个有点奇怪,有改过脚本吗?baichuan的脚本里11行已经model.to("cpu"),为什么这里还是在cuda:0上

ztxz16 avatar Aug 14 '23 02:08 ztxz16

正常的baichuan转换如楼上所说是做过model.to("cpu")的,其他模型,如果model.to("cpu")不成功,可以在这里加一下,改为:

dict[key].cpu().numpy().astype(ori_np_data_type)

TylunasLi avatar Sep 14 '23 00:09 TylunasLi