Features
Compile and install mmcv-full in an Ascend NPU container (including NPU operator support)
Prerequisites
- Ascend CANN and torch_npu are already installed in the container
- The working directory is already mounted (e.g., /home/zqq)
Usage
Step 0: Install prerequisite third-party library dependencies
Install the prerequisite dependencies according to the target PyTorch version:
source /opt/conda/bin/activate <conda-env-name>
# 根据版本选择对应的 requirements 文件
pip install -r /path/to/DrivingSDK/model_examples/BEVFormer/requirements.txt
# 或 requirements_pytorch2.6.0.txt / requirements_pytorch2.7.1.txt 等
Step 1: Confirm the conda environment (confirm with the user)
Ask the user for the name of the conda environment in use
Step 2: Clone the mmcv repository
Choose according to the network conditions:
Direct server connection is working:
git clone -b 1.x https://github.com/open-mmlab/mmcv.git
Server network timeout: configure a proxy or clone locally and transfer via scp
# 方案1:配置代理
export http_proxy=http://proxy:port
export https_proxy=http://proxy:port
git clone -b 1.x https://github.com/open-mmlab/mmcv.git
# 方案2:本地克隆后传输(仍使用GitHub链接)
# 本地执行
git clone -b 1.x https://github.com/open-mmlab/mmcv.git
scp -r mmcv user@server:/target/path/
Important: Always use the official GitHub link, do not use mirror sites.
Step 3: Apply the patch
Copy the patch from DrivingSDK and apply it:
cd mmcv
cp /path/to/DrivingSDK/model_examples/BEVFormer/mmcv_config.patch .
git apply --reject mmcv_config.patch
Step 4: Install dependencies
source /opt/conda/bin/activate <conda-env-name>
pip install -r requirements/runtime.txt
pip install ninja
Step 5: Compile and install
MMCV_WITH_OPS=1 MAX_JOBS=8 FORCE_NPU=1 python setup.py build_ext
MMCV_WITH_OPS=1 FORCE_NPU=1 python setup.py develop
Step 6: Verify the installation
python -c "import mmcv; print(mmcv.__version__)"
NPU verification: confirm there is no CUDA dependency
python -c "import site; print([p for p in site.getsitepackages() if 'cuda' in p.lower()])"
# 应输出空列表
Key environment variables
| Variable | Description |
|---|---|
| MMCV_WITH_OPS=1 | Compile NPU operators |
| FORCE_NPU=1 | Force the use of the NPU backend |
| MAX_JOBS=8 | Number of parallel compilation jobs |
Common issues
- numpy version conflict: try
pip install numpy==1.23.5 - Compilation timeout: increase MAX_JOBS
- patch failure: handle manually or skip non-critical patches
Decision guidance
Ask the user:
- What is the conda environment name?
- Can the server network access GitHub?
- What is the specific path of the patch file?