昇腾社区首页
中文
注册

在训练工程内开启Profiling采集功能

以下操作请在MindStudio环境上操作。

  1. 单击菜单栏File > Open...,选中迁移后的训练工程,如图1所示,单击“OK”导入工程。
    图1 导入训练工程
  2. 修改训练脚本。
    • 编辑train.py文件,设置执行训练的卡并添加Profiling使能代码。
      • 设置device,添加如下代码。如图2所示。
        NPU_DEVICE='npu:1'
        torch.npu.set_device(NPU_DEVICE)
        图2 设置device
      • 添加Profiling使能代码,配置Profiling数据的落盘路径。如图3所示。
        with torch.npu.profile(profiler_result_path="/tmp/pytorch/profiling"):
        图3 使能Profiling
    • 为加快完成训练并采集Profiling数据,编辑conf目录下的global_settings.py文件,将EPOCH参数设置为1。
      图4 修改EPOCH参数
  3. 执行训练脚本,具体操作可参见分析迁移快速入门样例(PyTorch GPU2Ascend)的“迁移后训练”章节。