Enabling Profiling in a Training Project
Perform the following operations in MindStudio.
- Choose on the menu bar, select the migrated training project, and click OK to import the project. See Figure 1.
- 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:
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"):
- Set the device and add the following code:
- 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
- Edit the train.py file to set the device for training and add the Profiling enabling code.
- Run the training script. For details, see Training After Migration.
Parent topic: Profiling (PyTorch Training)

