Ascend / pytorch

Ascend PyTorch adapter (torch_npu). Mirror of https://gitee.com/ascend/pytorch
https://ascend.github.io/docs/
Other
259 stars 15 forks source link

AttributeError: module 'torch_npu' has no attribute '_isinstance' #9

Open liyifango opened 1 year ago

liyifango commented 1 year ago

在使用PyTorch网络模型迁移和训练快速体验代码的时候,根据迁移修改代码后运行,提示如下错误

/usr/local/Ascend/ascend-toolkit/latest/tools/ms_fmk_transplt/torch_npu_bridge/transfer_to_npu.py:129: ImportWarning:
    *************************************************************************************************************
    The torch.Tensor.cuda and torch.nn.Module.cuda are replaced with torch.Tensor.npu and torch.nn.Module.npu now..
    The torch.cuda.DoubleTensor is replaced with torch.npu.FloatTensor cause the double type is not supported now..
    The backend in torch.distributed.init_process_group set to hccl now..
    The torch.cuda.* and torch.cuda.amp.* are replaced with torch.npu.* and torch.npu.amp.* now..
    The device parameters have been replaced with npu in the function below:
    torch.logspace, torch.randint, torch.hann_window, torch.rand, torch.full_like, torch.ones_like, torch.rand_like, torch.randperm, torch.arange, torch.frombuffer, torch.normal, torch._empty_per_channel_affine_quantized, torch.empty_strided, torch.empty_like, torch.scalar_tensor, torch.tril_indices, torch.bartlett_window, torch.ones, torch.sparse_coo_tensor, torch.randn, torch.kaiser_window, torch.tensor, torch.triu_indices, torch.as_tensor, torch.zeros, torch.randint_like, torch.full, torch.eye, torch._sparse_csr_tensor_unsafe, torch.empty, torch._sparse_coo_tensor_unsafe, torch.blackman_window, torch.zeros_like, torch.range, torch.sparse_csr_tensor, torch.randn_like, torch.from_file, torch._cudnn_init_dropout_state, torch._empty_affine_quantized, torch.linspace, torch.hamming_window, torch.empty_quantized, torch._pin_memory, torch.Tensor.new_empty, torch.Tensor.new_empty_strided, torch.Tensor.new_full, torch.Tensor.new_ones, torch.Tensor.new_tensor, torch.Tensor.new_zeros, torch.Tensor.to, torch.nn.Module.to, torch.nn.Module.to_empty
    *************************************************************************************************************

  warnings.warn(msg, ImportWarning)
Traceback (most recent call last):
  File "/root/workspaces/pytorch-trans-demo/train.py", line 8, in <module>
    from torch.utils.data import Dataset, DataLoader
  File "<frozen importlib._bootstrap>", line 1064, in _handle_fromlist
  File "/usr/local/Ascend/ascend-toolkit/latest/tools/ms_fmk_transplt/torch_npu_bridge/transfer_to_npu.py", line 134, in wrapped_isinstance
    return torch_npu._isinstance(obj, class_or_tuple)
AttributeError: module 'torch_npu' has no attribute '_isinstance'
Exception ignored in atexit callback: <function dump_compile_times at 0xfffb0bd967a0>
Traceback (most recent call last):
  File "/root/workspaces/mamba/envs/example/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 247, in dump_compile_times
    log.info(compile_times(repr="str", aggregate=True))
  File "/root/workspaces/mamba/envs/example/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 234, in compile_times
    out += tabulate(rows, headers=("Function", "Runtimes (s)"))
  File "/root/workspaces/mamba/envs/example/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 86, in tabulate
    import tabulate
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 945, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1439, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1406, in _get_spec
  File "/usr/local/Ascend/ascend-toolkit/latest/tools/ms_fmk_transplt/torch_npu_bridge/transfer_to_npu.py", line 134, in wrapped_isinstance
    return torch_npu._isinstance(obj, class_or_tuple)
AttributeError: module 'torch_npu' has no attribute '_isinstance'

环境版本:

aarch64-linux# cat ascend_toolkit_install.info
package_name=Ascend-cann-toolkit
version=7.0.RC1.alpha003
innerversion=V100R001C11B300
compatible_version=[V100R001C80,V100R001C84],[V100R001C77,V100R001C79],[V100R001C29],[V100R001C11,V100R001C50]
arch=aarch64
os=linux
path=/usr/local/Ascend/ascend-toolkit/7.0.RC1.alpha003/aarch64-linux

aarch64-linux# python --version
Python 3.10.12

aarch64-linux# pip list | grep torch*
torch              2.1.0
torch-npu          2.1.0rc1
torchvision        0.15.2a0+dd47d21

aarch64-linux# npu-smi info
+--------------------------------------------------------------------------------------------------------+
| npu-smi 23.0.rc2                                 Version: 23.0.rc2                                     |
+-------------------------------+-----------------+------------------------------------------------------+
| NPU     Name                  | Health          | Power(W)     Temp(C)           Hugepages-Usage(page) |
| Chip    Device                | Bus-Id          | AICore(%)    Memory-Usage(MB)                        |
+===============================+=================+======================================================+
| 1       310P3                 | OK              | NA           40                0     / 0             |
| 0       0                     | 0000:01:00.0    | 0            1700 / 21527                            |
+===============================+=================+======================================================+
| 2       310P3                 | OK              | NA           39                0     / 0             |
| 0       1                     | 0000:02:00.0    | 0            1699 / 21527                            |
sunchuhan-930 commented 1 year ago

根据目前的报错可能是torch版本和三方库版本不匹配