Offline Parsing of Data Profiled by Ascend PyTorch Profiler

When the profile data sampled using the Ascend PyTorch Profiler APIs is large, using the on_trace_ready API directly in the current environment for automatic parsing may cause excessive resource consumption and result in lags. In this case, you can cancel the on_trace_ready API, use the environment variable ASCEND_WORK_PATH to set the flush directory (for example, export ASCEND_WORK_PATH=xx/xx), and use the following method to parse collected profile data in offline mode:

  1. Create the {file_name}.py file (with user-defined {file_name}), and edit the following code:
    1
    2
    3
    4
    from torch_npu.profiler.profiler import analyse
    
    if __name__ == "__main__":
     analyse(profiler_path="./result_data", max_process_number=max_process_number)
    
    Table 1 Parameters

    Parameter

    Description

    Required/Optional

    profiler_path

    PyTorch profile data path. The path can contain only letters, digits, and underscores (_). Soft links are not supported. This specified path stores the PyTorch profile data directory {worker_name}_{timestamp}_ascend_pt.

    Required

    max_process_number

    Maximum number of offline analysis processes. The value ranges from 1 to the number of CPU cores. The default value is half of the number of CPU cores. If the value of this parameter exceeds the number of available CPU cores in the environment, the system will automatically utilize all available CPU cores. If this parameter is set to an invalid value, half of the default number of CPU cores is used.

    Optional

    The offline parsing API supports parallel parsing of multiple profile data directories. In cases where the profile data volume is large and there are many data directories, parsing may fail due to insufficient memory in the environment. In these cases, you can customize the maximum number of processes (max_process_number) to control the resource usages.

  2. Save the file and run the following command to parse the profile data:
    python3 {file_name}.py
  3. View the sampled PyTorch training/online inference profile data result files and profile data analysis.For details about profile data result files, see Data Storing Directories.