# 算子编译过程中报错A module that was compiled using NumPy 1.x cannot be run in Numpy 2.0.0 .

**1. 系统环境**

硬件环境\(Ascend/GPU/CPU\): Ascend/GPU/CPU

软件环境: MindSpore 版本: 2.0.0

执行模式（静态图/动态图）： 不限

Python 版本: 3.9

操作系统平台: linux

**2. 报错信息**

2.1 问题描述

算子编译过程中部分模块与numpy2.0版本不兼容。

```
(mindie) root@ubuntu:/usr/local/Ascend/MindIE-LLM/examples/models# source /usr/local/Ascend/MindIE-LLM/set_env.sh
A module that was compiled using NumPy 1.x cannot be run in Numpy 2.0.0 as it may crash. To support both with and 2.x versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuildinstead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules willoneed time to support NumPy 2.

Traceback (most recent call last): File "<string>", line 1, in <module>
    File "/root/anaconda3/envs/mindie/l ib/python3. 10/site-packages/torch/_ init_.py", line 1382, in <modules>
        from .functional import * # noqa: F403
    File "/root/anaconda3/envs/m indie/l ib/python3.10/s ite-pac kages/torch/functional.py", line 7, in <module>
        import torch.nn.functional as F
    File "/root/anaconda3/envs/mindie/Lib/python3.10/stte-packages/torch/nn/_ init_.pyahen", line 1, in <module>
        from .modules import * # noqa: F403
    File "/root/anaconda3/envs/mindie/l ib/python3.10/site-packages/t orch/nn/modules/_init__.py" , line 35, in <module>
        from .transformer import Trans formerEncoder, TransformerDecoder, \
    File "/root/anaconda3/envs/mindie/lib/python3,10/site-packages/torch/nn/modules/transformer .py" , line 20, in <module>
        device: torch.device = torch.deviceltorch. C. get default device( )), # torch.device('cpu')
/root/anaconda3/envs/mindie/tib/python3. 10/site-packages/torch/nn/modules/transformer .py:20: Userwarn ing: Failed to initialize NumPy: _ARRAY_APIenotfound, (Trigge red internally at /pytorch/torch/csrc/utils/tensor numpy.cpp:84.)
    device: torch.device = torch.device( torch. C. get default device( )), # torch.device('cpu')
```

**3. 根因分析**

本机环境安装numpy 版本 2.X，但是安装的torch是在numpy 1.X版本下编译的，因此会报错。报错代码行

```
File "/root/anaconda3/envs/mindie/lib/python3,10/site-packages/torch/nn/modules/transformer .py" , line 20, in <module> device: torch.device = torch.deviceltorch. C. get default device( )), # torch.device('cpu')
```

具体报错信息里面也写的很明确

```
A module that was compiled using NumPy 1.x cannot be run in Numpy 2.0.0 as it may crash. To support both with and 2.x versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuildinstead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules willoneed time to support NumPy 2.
```

**4. 解决方案**

1.卸载numpy 2.X版本，安装numpy 1.X版本，例如1.21.2

pip uninstall numpy -y

pip install numpy==1.21.2

2.更新pytorch到最新版本

torch最新版本2.3.1应该已经加入了numpy 2.x的支持

不过其他组件有可能会报错，稳妥的解决版本还是方案1。

