torch._six在torch2.x版本已经被移除
经排查是在导入from torch._six import container_abcs时出错
因此将出错代码更改为:
import torch
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
from torch._six import container_abcs
else:
import collections.abc as container_abcs
即可正常运行
参考链接:cannot import name ‘container_abcs‘ from ‘torch._six‘错误的解决方法(一般升级pytorch1.9后出现)-CSDN博客