在Ascend AI处理器上使用MindSpore Profiler进行性能调试。
流程
准备训练脚本,并在训练脚本中调用性能调试接口,接着运行训练脚本。
启动MindInsight,并通过启动参数指定summary-base-dir目录(summary-base-dir是Profiler所创建目录的父目录),例如训练时Profiler创建的文件夹绝对路径为/home/user/code/data,则summary-base-dir设为/home/user/code。启动成功后,根据IP和端口访问可视化界面在训练列表找到对应训练,点击性能分析,即可在页面中查看训练性能数据
首先准备脚本:
set_context之后,初始化网络、以及初始化HCCL之前,需要初始化MindSpore Profiler对象。
调用Profiler.analyse()停止性能数据收集并生成性能分析结果。
Profiler可以通过start_profile参数控制是否基于step(epoch)开启、关闭收集性能数据。对于图模式的数据下沉模式,只有在每个epoch结束后才有机会告知CANN开启和停止,因此对于数据下沉模式,需要基于epoch开启和关闭。
正常正常情况下,代码如下:
import numpy as np
from mindspore import nn, context
from mindspore import Model
import mindspore.dataset as ds
from mindspore.profiler import Profiler
class Net(nn.Cell):
def __init__(self