الرقائق المحلية
MooreThread GPU
Using PyTorch
First, we recommend creating an instance using one of our pre-built base images that includes the PyTorch framework. Then, for NVIDIA-based PyTorch code, just a few simple modifications are needed to run it on MooreThread GPUs. Please see the example below:
# 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)
# 改造为摩尔线程GPU上可运行的代码
# 第一步:import torch后,立即import torch_musa(musa为摩尔的'cuda')
# 第二步:cuda()函数换为musa()
import torch
import torch_musa
x = torch.randn(10000, 10000).musa()
y = torch.randn(10000, 10000).musa()
for _ in range(1000):
z = x.mm(y)
print(z)
More Complex Examples
The following is the code for training a NVIDIA PyTorch ResNet network using the MNIST dataset
# 下载代码
wget https://webcal-public.ks3-cn-beijing.ksyuncs.com/debug/dp_res18.py
# 执行代码训练,自动会下载MNIST数据集
python dp_res18.py
Below is the code modified from the above to support MooreThread GPUs:
# 下载代码
wget https://webcal-public.ks3-cn-beijing.ksyuncs.com/npu_chips/moore_threads/dp_res18_mt.py
# 执行代码训练,自动会下载MNIST数据集
python dp_res18_mt.py
Differences between the two code snippets:
# diff dp_res18.py dp_res18_mt.py
8a9
> import torch_musa
29c30,31
< device = 'cuda' if torch.cuda.is_available() else 'cpu'
---
> device = 'musa' if torch.musa.is_available() else 'cpu'
> print("Detect device:", device)
# 从diff两个文件的结果可以看出,除多了import torch_musa和替换了cuda→musa,其他均相同
MooreThread GPU Utilization Monitoring
View GPU utilization, GPU memory usage, and more
Use the mthreads-gmi command
# mthreads-gmi
Fri Apr 18 15:41:55 2025
---------------------------------------------------------------
mthreads-gmi:1.14.0 Driver Version:2.7.0
---------------------------------------------------------------
ID Name |PCIe |%GPU Mem
Device Type |Pcie Lane Width |Temp MPC Capable
| ECC Mode
+-------------------------------------------------------------+
0 MTT S4000 |00000000:12:00.0 |0% 4MiB(49152MiB)
Physical |16x(16x) |41C YES
| N/A
---------------------------------------------------------------
---------------------------------------------------------------
Processes:
ID PID Process name GPU Memory
Usage
+-------------------------------------------------------------+
No running processes found
---------------------------------------------------------------
More algorithms and models will soon be available on the CodeWithGPU community. You can also visit MooreThread’s official GitHub model repository to access even more models!
