基础环境安装
本教程参考快速安装昇腾环境,稍作补遗。
安装驱动
安装驱动之前
安装驱动之前需要安装内核和解压工具:
yum install kernel-devel kernel-headers -y
yum groupinstall "Development Tools"
yum install tar dkms -y安装
按照快速安装昇腾环境中的方法安装驱动,但是有以下几个注意点:
安装 CANN
CANN 在物理机上不是必须的,想装也可以,好消息是可以用yum 直装了!!
测试
import torch
import torch_npu
try:
print(f"Torch NPU available: {torch.npu.is_available()}")
if torch.npu.is_available():
print(f"NPU device count: {torch.npu.device_count()}")
print(f"Current NPU device: {torch.npu.current_device()}")
print(f"NPU device name: {torch.npu.get_device_name(0)}") # if device_count > 0
else:
print("Torch NPU not available.")
except Exception as e:
print(f"An error occurred: {e}")
import traceback
traceback.print_exc()Python 环境
建议把阿里源和额外的华为云源 pytorch 源配上:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set global.extra-index-url "https://download.pytorch.org/whl/cpu/ https://mirrors.huaweicloud.com/ascend/repos/pypi"docker
docker 的 data_root 默认在 /var/lib/docker,但是根目录挂在只有 100G,我们需要更换 data_root。
停止 docker 服务:
sudo systemctl stop docker编辑 /etc/docker/daemon.json:
{
"data-root": "/home/docker"
}迁移现有数据:
sudo rsync -aP /var/lib/docker/ /home/docker验证现有配置:
docker info | grep "Docker Root Dir"科学上网
http_proxy
参考远程服务器使用本地代理的方 clear 法把本地的 clash 代理挂到远程。
这个的前置步骤是需要配置服务器的 sshd:
# 编辑SSH配置
vim /etc/ssh/sshd_config
# 确保有以下配置
GatewayPorts yes
AllowTcpForwarding yes
# 重启SSH服务
sudo systemctl restart sshd需要注意的是,有的时候重复挂代理,会造成冲突,使用 netstat -tlnp | grep 7897 检查是否已经挂了代理,挂了的话杀了重新挂。
git 走 http_proxy
使用下面配置让 git 走 http_proxy 代理:
git config --global http.proxy http://127.0.0.1:7897
git config --global https.proxy http://127.0.0.1:7897但是正常情况下,ssh 是走不了 http_proxy 代理的。对于 GitHub 这种强制使用 ssh 的,我们要绕一下。
安装 ncat:
sudo apt install ncat
brew install nmap在 ~/.ssh/config 里面加上:
Host github.com
Hostname github.com
User git
ProxyCommand ncat --proxy-type http --proxy 127.0.0.1:7897 %h %p克隆时强制指定 443 端口:
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes -p 443' git clone git@ssh.github.com:yongqiangma/PaddleCustomDevice_NPU.git