Enabling Profiling in a Training Project

Perform the following operations in MindStudio.

  1. Choose File > Open... on the menu bar, select the migrated training project, and click OK to import the project. See Figure 1.
    Figure 1 Training project import
  2. Modify the training script.
    • Edit the train.py file to set the device for training and add the Profiling enabling code.
      • Set the device and add the following code: See Figure 2.
        NPU_DEVICE='npu:1'
        torch.npu.set_device(NPU_DEVICE)
        Figure 2 Device setting
      • Add the Profiling enabling code and configure the flush path of profile data. See Figure 3.
        with torch.npu.profile(profiler_result_path="/tmp/pytorch/profiling"):
        Figure 3 Profiling enabling
    • To accelerate training and profile data collection, edit the global_settings.py file in the conf directory to set EPOCH to 1.
      Figure 4 EPOCH setting
  3. Run the training script. For details, see "Training After Porting" in the Migration Tool Quick Start Sample-PyTorch GPU2Ascend.