常见故障
import 出错
错误一:Cannot find the extension library(_C.so)
解决方法:
- 确定 horizon_plugin_pytorch 版本和 cuda 版本是对应的。
- 在 python3 中,找到 horizon_plugin_pytorch 的执行路径,检测该目录下是否有 .so 文件。可能同时存在多个 horizon_plugin_pytorch 的版本,需要卸载只保留一个需要的版本。
错误二:RuntimeError: Cannot load custom ops. Please rebuild the horizon_plugin_pytorch
解决方法:确认本地 CUDA 环境是否正常,如路径、版本等。
Module 不支持 deepcopy
某些框架(例如:PyTorch Lightning)对 torch 原生 module 做了二次封装,但不支持 deepcopy。
解决方法:为模型实现 __deepcopy__ 方法。
RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment
该报错通常发生在 deepcopy torch.nn.Module 的时候。通常是 forward 过程中将某些中间结果存在了模型中,模型中存在 non-leaf tensor 导致 deepcopy 报错。
解决方法:检查模型中,以及 forward 之后,是否有某些属性是 non-leaf tensor。在保存这些 tensor 前,确保进行了 detach 操作。
export 时报错:IndexError: list index out of range
该报错通常是因为模型输出中存在 QTensor。
解决方法:检查模型输出,确保所有输出都经过了 dequant。
