Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
# NVIDIA PyTorch 代码 import torch x = torch.randn(10000, 10000).cuda() y = torch.randn(10000, 10000).cuda() for _ in range(1000): z = x.mm(y) print(z) # 改造为华为910B上可运行的代码 # 第一步:import torch后,立即import torch_npu # 第二步:cuda()函数换为npu() import torch import torch_npu x = torch.randn(10000, 10000).npu() y = torch.randn(10000, 10000).npu() for _ in range(1000): z = x.mm(y) print(z)
# 下载代码 wget https://autodl-public.ks3-cn-beijing.ksyuncs.com/debug/dp_res18_ascend.py # 执行代码训练,自动会下载MNIST数据集 python dp_res18.py
# 下载代码 wget https://autodl-public.ks3-cn-beijing.ksyuncs.com/npu_chips/huawei/dp_res18_ascend.py # 执行代码训练,自动会下载MNIST数据集 python dp_res18_ascend.py
# diff dp_res18.py dp_res18_ascend.py 8a9 > import torch_npu 29c30,31 < device = 'cuda' if torch.cuda.is_available() else 'cpu' --- > device = 'npu' if torch.npu.is_available() else 'cpu' > print("Detect device:", device) # 从diff两个文件的结果可以看出,除多了import torch_npu和替换了cuda→npu,其他均相同
npu-smi info
# npu-smi info +------------------------------------------------------------------------------------------------+ | npu-smi 23.0.3 Version: 23.0.3 | +---------------------------+---------------+----------------------------------------------------+ | NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)| | Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) | +===========================+===============+====================================================+ | 6 910B2 | OK | 98.7 46 0 / 0 | | 0 | 0000:82:00.0 | 0 0 / 0 3330 / 65536 | +===========================+===============+====================================================+ +---------------------------+---------------+----------------------------------------------------+ | NPU Chip | Process id | Process name | Process memory(MB) | +===========================+===============+====================================================+ | No running processes found in NPU 6 | +===========================+===============+====================================================+
npu-smi info watch
# npu-smi info watch NpuID(Idx) ChipId(Idx) Pwr(W) Temp(C) AI Core(%) AI Cpu(%) Ctrl Cpu(%) Memory(%) Memory BW(%) 6 0 98.0 44 0 0 0 5 0 6 0 97.9 44 0 0 0 5 0